Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Assistants settings] Update reported data backend #871

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/routes/settings/+layout.server.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/routes/settings/assistants/[assistantId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) });

Expand All @@ -21,6 +22,30 @@ async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
return assistant;
}

export async function load({ parent, params, locals }) {
const data = await parent();
Copy link
Member

@coyotte508 coyotte508 Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this triggers the root's +layout.server.ts's load.

So each time we switch assistant, this will trigger a load of all assistants

IMO we can keep the redirect in page.ts - that way the load isn't triggered - since the frontend will be able to execute it.


TLDR:

  • Keep page.ts as is
  • remove the redirect / parent() call here
  • The rest of the PR is great!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in 1d5994f


const assistantId = params.assistantId;

const assistant = data.settings.assistants.find((id) => id === assistantId);
if (!assistant) {
throw redirect(302, `${base}/assistant/${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;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/assistants/[assistantId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<CarbonCopy class="mr-1.5 inline text-xs" />Duplicate</button
>
</form>
{#if !assistant?.reported}
{#if !data.isReported}
<button
type="button"
on:click={() => {
Expand Down
14 changes: 0 additions & 14 deletions src/routes/settings/assistants/[assistantId]/+page.ts

This file was deleted.

Loading