Files
video-create/web/client/src/hooks/usePrompts.ts
2026-05-07 02:34:04 +08:00

26 lines
817 B
TypeScript

import { useState, useCallback } from 'react';
import { api } from '@/lib/api';
export function usePrompts() {
const [content, setContent] = useState<string>('');
const [path, setPath] = useState<string>('');
const [loading, setLoading] = useState(false);
const load = useCallback(async (accountId: string, type: string) => {
setLoading(true);
try {
const result = await api.getPrompt(accountId, type);
setContent(result.content);
setPath(result.path);
} catch { setContent(''); setPath(''); }
setLoading(false);
}, []);
const save = useCallback(async (accountId: string, type: string, newContent: string) => {
await api.savePrompt(accountId, type, newContent);
setContent(newContent);
}, []);
return { content, path, loading, load, save, setContent };
}