Fix synthesis loading from database
- useQuery now returns data properly - useEffect sets synthesis state when loadedSynthesis changes - Synthesis will persist across page refreshes - No dependency on synthesis in useEffect (prevents loops) Synthesis persistence NOW WORKING!
This commit is contained in:
parent
7db7ca3de5
commit
9f7f64b9ee
1 changed files with 10 additions and 3 deletions
|
|
@ -65,21 +65,28 @@ export default function NotebookDetailPage() {
|
|||
});
|
||||
|
||||
// Load saved synthesis from database
|
||||
useQuery({
|
||||
const { data: loadedSynthesis } = useQuery({
|
||||
queryKey: ['synthesis', notebookId],
|
||||
queryFn: async () => {
|
||||
try {
|
||||
const response = await notebookAPI.getSynthesis(notebookId);
|
||||
if (response.data && response.data.status !== 'none') {
|
||||
setSynthesis(response.data);
|
||||
return response.data;
|
||||
}
|
||||
return response.data;
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Set synthesis from loaded data
|
||||
useEffect(() => {
|
||||
if (loadedSynthesis && !synthesis) {
|
||||
setSynthesis(loadedSynthesis);
|
||||
}
|
||||
}, [loadedSynthesis]);
|
||||
|
||||
const synthesisMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const response = await notebookAPI.generateSynthesis(notebookId);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue