diff --git a/frontend/bun.lockb b/frontend/bun.lockb index d826154..1a0f593 100755 Binary files a/frontend/bun.lockb and b/frontend/bun.lockb differ diff --git a/frontend/package.json b/frontend/package.json index 4bd10b1..fee689c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -36,7 +36,7 @@ "dependencies": { "@types/he": "^1.2.3", "apexcharts": "^3.44.0", - "bits-ui": "^0.18.2", + "bits-ui": "^0.19.6", "clsx": "^2.0.0", "cmdk-sv": "^0.0.13", "drizzle-orm": "^0.29.0", diff --git a/frontend/src/lib/components/ui/checkbox/checkbox.svelte b/frontend/src/lib/components/ui/checkbox/checkbox.svelte index 9ee3e9f..d203953 100644 --- a/frontend/src/lib/components/ui/checkbox/checkbox.svelte +++ b/frontend/src/lib/components/ui/checkbox/checkbox.svelte @@ -1,30 +1,31 @@ + on:click +> + let:isIndeterminate + > {#if isChecked} {:else if isIndeterminate} diff --git a/frontend/src/lib/components/ui/checkbox/index.ts b/frontend/src/lib/components/ui/checkbox/index.ts index 94d8674..6d92d94 100644 --- a/frontend/src/lib/components/ui/checkbox/index.ts +++ b/frontend/src/lib/components/ui/checkbox/index.ts @@ -1,6 +1,6 @@ -import Root from './checkbox.svelte' +import Root from "./checkbox.svelte"; export { Root, // Root as Checkbox, -} +}; diff --git a/frontend/src/lib/db/schema.ts b/frontend/src/lib/db/schema.ts index bd1e113..11b97ec 100644 --- a/frontend/src/lib/db/schema.ts +++ b/frontend/src/lib/db/schema.ts @@ -5,6 +5,7 @@ import { timestamp, integer, uuid, + boolean, } from 'drizzle-orm/pg-core' import { relations, type InferSelectModel } from 'drizzle-orm' @@ -17,6 +18,7 @@ export const shortener = pgTable('shortener', { .defaultNow() .notNull(), userId: integer('user_id').notNull(), + active: boolean('active').notNull().default(true), projectId: integer('project_id'), }) diff --git a/frontend/src/routes/(app)/links/+page.svelte b/frontend/src/routes/(app)/links/+page.svelte index 2753903..2b7733b 100644 --- a/frontend/src/routes/(app)/links/+page.svelte +++ b/frontend/src/routes/(app)/links/+page.svelte @@ -12,6 +12,7 @@ import { Input } from '$lib/components/ui/input' import { Label } from '$lib/components/ui/label' import { Badge } from '$lib/components/ui/badge' + import { Checkbox } from '$lib/components/ui/checkbox' import { BarChart, ExternalLink, @@ -35,6 +36,7 @@ let editShortenerCode = '' let editShortenerLink = '' let editShortenerCategory: any = undefined + let editShortenerActive = false let isEditLoading = false let open: boolean = false @@ -42,15 +44,27 @@ $: selectedProject = data.selected_project.label - const openEditDialog = (code: string, link: string) => { + const openEditDialog = ( + code: string, + link: string, + projectId: number | null, + projectName: string | undefined, + active: boolean, + ) => { editDialogOpen = true editShortenerCode = code editShortenerLink = link - editShortenerCategory = undefined + editShortenerActive = active + if (projectId) { + editShortenerCategory = { value: projectId, label: projectName } + } else { + editShortenerCategory = undefined + } } const editShortener = async (code: string, link: string) => { isEditLoading = true + console.log(editShortenerCategory) await fetch(`/api/shortener/${code}`, { method: 'put', body: JSON.stringify({ @@ -58,6 +72,7 @@ projectId: editShortenerCategory ? editShortenerCategory.value : undefined, + active: editShortenerActive, }), }) await invalidateAll() @@ -169,10 +184,25 @@ - {shortener.project - ? shortener.project.name - : 'Uncategorized'} +
+ + {#if shortener.active} + + Active + {:else} + + Inactive + {/if} + + {shortener.project + ? shortener.project.name + : 'Uncategorized'} +
{shortener.link} @@ -201,7 +231,13 @@ - openEditDialog(shortener.code, shortener.link)}> + openEditDialog( + shortener.code, + shortener.link, + shortener.projectId, + shortener.project?.name, + shortener.active, + )}> Edit +
+
+
+ + +
+