26 lines
817 B
TypeScript
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 };
|
|
}
|