From d5583d0d6da7325ab0fce4abb9f9ae5efd7737ac Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sat, 9 Dec 2023 16:07:10 +0800 Subject: [PATCH] able to change shortener project --- .../src/routes/(app)/links/+page.server.ts | 5 ++++- frontend/src/routes/(app)/links/+page.svelte | 22 +++++++++++++++++++ .../(app)/projects/[uuid]/+page.server.ts | 4 +++- .../routes/(app)/projects/[uuid]/+page.svelte | 22 +++++++++++++++++++ .../src/routes/api/shortener/[id]/+server.ts | 6 ++++- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/(app)/links/+page.server.ts b/frontend/src/routes/(app)/links/+page.server.ts index c793421..7e65b17 100644 --- a/frontend/src/routes/(app)/links/+page.server.ts +++ b/frontend/src/routes/(app)/links/+page.server.ts @@ -7,10 +7,13 @@ export const load = (async (event) => { const shorteners = await db.query.shortener.findMany({ with: { visitor: true, + project: true, }, where: (shortener, { eq, and, isNull }) => and(eq(shortener.userId, user.id), isNull(shortener.projectId)), }) - return { shorteners } + const projects = await db.query.project.findMany() + + return { shorteners, projects } }) satisfies PageServerLoad diff --git a/frontend/src/routes/(app)/links/+page.svelte b/frontend/src/routes/(app)/links/+page.svelte index 3cce6cc..f4a1838 100644 --- a/frontend/src/routes/(app)/links/+page.svelte +++ b/frontend/src/routes/(app)/links/+page.svelte @@ -5,6 +5,7 @@ import * as Dialog from '$lib/components/ui/dialog' import * as Card from '$lib/components/ui/card' import * as DropdownMenu from '$lib/components/ui/dropdown-menu' + import * as Select from '$lib/components/ui/select' import { Input } from '$lib/components/ui/input' import { Label } from '$lib/components/ui/label' import { @@ -43,12 +44,14 @@ let editDialogOpen = false let editShortenerCode = '' let editShortenerLink = '' + let editShortenerCategory: any = undefined let isEditLoading = false const openEditDialog = (code: string, link: string) => { editDialogOpen = true editShortenerCode = code editShortenerLink = link + editShortenerCategory = undefined } const editShortener = async (code: string, link: string) => { @@ -57,6 +60,9 @@ method: 'put', body: JSON.stringify({ link, + projectId: editShortenerCategory + ? editShortenerCategory.value + : undefined, }), }) await invalidateAll() @@ -184,6 +190,22 @@ bind:value={editShortenerLink} class="col-span-3" /> +
+ + + + + + + {#each data.projects as project} + {project.name} + {/each} + + +