-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement functionality to ensure that newly added tags are persisted across page refreshes, preventing loss of data. [skip gpt_engineer]
- Loading branch information
1 parent
9e5345d
commit dec9c0b
Showing
3 changed files
with
42 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { supabase } from '../supabase'; | ||
|
||
const fromSupabase = async (query) => { | ||
const { data, error } = await query; | ||
if (error) throw new Error(error.message); | ||
return data; | ||
}; | ||
|
||
export const useTags = () => useQuery({ | ||
queryKey: ['tags'], | ||
queryFn: () => fromSupabase(supabase.from('tags').select('*')), | ||
}); | ||
|
||
export const useAddTag = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationFn: (newTag) => fromSupabase(supabase.from('tags').insert([newTag])), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['tags'] }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters