feat(02-01): prompt editor UI with types, hooks, page, route, sidebar

- Add PromptInfo, PromptListResponse, PromptDetail types
- Add usePromptList, usePrompt, useSavePrompt, useResetPrompt hooks
- Create PromptEditor page with two-column layout, live variables
- Add /prompt-editor route in App.tsx
- Add Prompt Editor nav item with Pencil icon in Sidebar
- TypeScript compiles without errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michele
2026-03-08 20:57:01 +01:00
parent 05972fa8f1
commit ca3dd59072
5 changed files with 372 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ import type {
GenerateResponse,
JobStatus,
PostResult,
PromptDetail,
PromptListResponse,
Settings,
SettingsStatus,
} from '../types'
@@ -184,3 +186,51 @@ export function useDownloadEditedCsv() {
},
})
}
// ---------------------------------------------------------------------------
// Prompt Editor
// ---------------------------------------------------------------------------
/** Lista tutti i prompt disponibili con flag modificato/default. */
export function usePromptList() {
return useQuery<PromptListResponse>({
queryKey: ['prompts'],
queryFn: () => apiGet<PromptListResponse>('/prompts'),
staleTime: 30_000,
})
}
/** Carica contenuto + variabili di un singolo prompt. */
export function usePrompt(name: string | null) {
return useQuery<PromptDetail>({
queryKey: ['prompts', name],
queryFn: () => apiGet<PromptDetail>(`/prompts/${name}`),
enabled: !!name,
staleTime: 0, // Sempre fresco dopo edit
})
}
/** Salva il contenuto modificato di un prompt. */
export function useSavePrompt() {
const queryClient = useQueryClient()
return useMutation<PromptDetail, Error, { name: string; content: string }>({
mutationFn: ({ name, content }) =>
apiPut<PromptDetail>(`/prompts/${name}`, { content }),
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ['prompts'] })
queryClient.setQueryData(['prompts', data.name], data)
},
})
}
/** Reset un prompt al default originale. */
export function useResetPrompt() {
const queryClient = useQueryClient()
return useMutation<PromptDetail, Error, string>({
mutationFn: (name) => apiPost<PromptDetail>(`/prompts/${name}/reset`),
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ['prompts'] })
queryClient.setQueryData(['prompts', data.name], data)
},
})
}