Prompt gallery (#957)

- [x] show prompt instead of app in autocomplete
- [x] use proper array/list for db (tags)
- [x] don't do <dyad-prompt> - replace inline
This commit is contained in:
Will Chen
2025-08-18 13:25:11 -07:00
committed by GitHub
parent a547735714
commit 573642ae5f
26 changed files with 1540 additions and 42 deletions

81
src/hooks/usePrompts.ts Normal file
View File

@@ -0,0 +1,81 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { IpcClient } from "@/ipc/ipc_client";
export interface PromptItem {
id: number;
title: string;
description: string | null;
content: string;
createdAt: Date;
updatedAt: Date;
}
export function usePrompts() {
const queryClient = useQueryClient();
const listQuery = useQuery({
queryKey: ["prompts"],
queryFn: async (): Promise<PromptItem[]> => {
const ipc = IpcClient.getInstance();
return ipc.listPrompts();
},
meta: { showErrorToast: true },
});
const createMutation = useMutation({
mutationFn: async (params: {
title: string;
description?: string;
content: string;
}): Promise<PromptItem> => {
const ipc = IpcClient.getInstance();
return ipc.createPrompt(params);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
meta: {
showErrorToast: true,
},
});
const updateMutation = useMutation({
mutationFn: async (params: {
id: number;
title: string;
description?: string;
content: string;
}): Promise<void> => {
const ipc = IpcClient.getInstance();
return ipc.updatePrompt(params);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
meta: {
showErrorToast: true,
},
});
const deleteMutation = useMutation({
mutationFn: async (id: number): Promise<void> => {
const ipc = IpcClient.getInstance();
return ipc.deletePrompt(id);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
meta: {
showErrorToast: true,
},
});
return {
prompts: listQuery.data ?? [],
isLoading: listQuery.isLoading,
error: listQuery.error,
refetch: listQuery.refetch,
createPrompt: createMutation.mutateAsync,
updatePrompt: updateMutation.mutateAsync,
deletePrompt: deleteMutation.mutateAsync,
};
}