diff --git a/src/routes/settings/+layout.server.ts b/src/routes/settings/+layout.server.ts deleted file mode 100644 index 140b1a7e149..00000000000 --- a/src/routes/settings/+layout.server.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { collections } from "$lib/server/database"; -import type { LayoutServerLoad } from "./$types"; -import type { Report } from "$lib/types/Report"; - -export const load = (async ({ locals, parent }) => { - const { assistants } = await parent(); - - let reportsByUser: string[] = []; - const createdBy = locals.user?._id ?? locals.sessionId; - if (createdBy) { - const reports = await collections.reports - .find>({ createdBy }, { projection: { _id: 0, assistantId: 1 } }) - .toArray(); - reportsByUser = reports.map((r) => r.assistantId.toString()); - } - - return { - assistants: assistants.map((el) => ({ - ...el, - reported: reportsByUser.includes(el._id), - })), - }; -}) satisfies LayoutServerLoad; diff --git a/src/routes/settings/assistants/[assistantId]/+page.server.ts b/src/routes/settings/assistants/[assistantId]/+page.server.ts index 0734d964c39..ffe5991c766 100644 --- a/src/routes/settings/assistants/[assistantId]/+page.server.ts +++ b/src/routes/settings/assistants/[assistantId]/+page.server.ts @@ -7,6 +7,7 @@ import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public"; import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private"; import { z } from "zod"; import type { Assistant } from "$lib/types/Assistant"; + async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) { const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) }); @@ -21,6 +22,22 @@ async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) { return assistant; } +export async function load({ params, locals }) { + const assistantId = params.assistantId; + let isReported = false; + + const createdBy = locals.user?._id ?? locals.sessionId; + if (createdBy) { + const report = await collections.reports.findOne({ + createdBy, + assistantId: new ObjectId(assistantId), + }); + isReported = !!report; + } + + return { isReported }; +} + export const actions: Actions = { delete: async ({ params, locals }) => { let assistant; diff --git a/src/routes/settings/assistants/[assistantId]/+page.svelte b/src/routes/settings/assistants/[assistantId]/+page.svelte index 29a01da5fb0..2612fac2851 100644 --- a/src/routes/settings/assistants/[assistantId]/+page.svelte +++ b/src/routes/settings/assistants/[assistantId]/+page.svelte @@ -107,7 +107,7 @@ Duplicate - {#if !assistant?.reported} + {#if !data.isReported}