diff --git a/src/lib/api.ts b/src/lib/api.ts index f1c654d..0650f69 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -185,3 +185,21 @@ export const submitAnswer = action( return userPrompt.userInputPrompt === prompt; }, ); + +export const deleteUserPrompt = action(async (promptId: string) => { + "use server"; + console.log("hello") + const userPrompts = await getUserPrompts(); + const updatedPrompts = userPrompts.filter(({ id }) => id !== promptId); + + const logger = rootLogger.child({ promptId }); + logger.info("Deleting user prompt"); + await Promise.all([ + storage.setItem(StorageKey.UserPrompts, updatedPrompts), + storage.removeItem(getGeneratedImageStorageKey({ promptId })), + storage.removeItem(getDecoyPromptsStorageKey({ promptId })), + ]); + logger.info("Deleted user prompt"); + + return true; +}); diff --git a/src/routes/index.tsx b/src/routes/index.tsx index e35fe1d..0c4dc7d 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -29,14 +29,17 @@ export default function Home(_props: RouteSectionProps) { setTimeout(() => (inputRef.value = "")); }} > - - - +
+ + + + +
diff --git a/src/routes/mod.tsx b/src/routes/mod.tsx new file mode 100644 index 0000000..a8b651f --- /dev/null +++ b/src/routes/mod.tsx @@ -0,0 +1,39 @@ +import { For, createResource } from "solid-js"; +import { useAction } from "@solidjs/router"; +import { deleteUserPrompt, getUserPrompts } from "~/lib/api"; + +export default function ModPage() { + const [userPrompts, { refetch }] = createResource(async () => getUserPrompts()); + const deletePrompt = useAction(deleteUserPrompt); + + const handleDelete = async (id: string) => { + if (confirm("Are you sure you want to delete this prompt?")) { + await deletePrompt(id); + await refetch(); + } + }; + + return ( +
+

Moderation Panel

+
+ + {(prompt) => ( +
+
+

{prompt.id}

+

{prompt.userInputPrompt}

+
+ +
+ )} +
+
+
+ ); +} \ No newline at end of file