Skip to content

Commit

Permalink
Reverted to edit c81e1656-22ea-4501-a031-de03cc22c800: "Remove prompt…
Browse files Browse the repository at this point in the history
…s.txt from repo

Deleted the prompts.txt file from the repository as per the request.
[skip gpt_engineer]"
  • Loading branch information
lovable-dev[bot] committed Oct 13, 2024
1 parent c896a94 commit 3012e37
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
53 changes: 30 additions & 23 deletions src/integrations/supabase/hooks/useNotes.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { supabase } from '../supabase';
import { useSupabaseAuth } from '../auth';

const fromSupabase = async (query) => {
const { data, error } = await query;
if (error) throw new Error(error.message);
return data;
};

export const useNote = (id) => {
const { session } = useSupabaseAuth();
return useQuery({
queryKey: ['notes', id],
queryFn: () => fromSupabase(supabase.from('notes').select('*').eq('id', id).eq('user_id', session?.user?.id).single()),
enabled: !!session?.user?.id,
});
};
/*
### notes
export const useNotes = () => {
const { session } = useSupabaseAuth();
return useQuery({
queryKey: ['notes'],
queryFn: () => fromSupabase(supabase.from('notes').select('*').eq('user_id', session?.user?.id)),
enabled: !!session?.user?.id,
});
};
| name | type | format | required |
|------------|--------------------------|--------|----------|
| id | integer | bigint | true |
| created_at | timestamp with time zone | string | true |
| title | text | string | false |
| content | text | string | false |
| color | text | string | false |
| tag | text | string | false |
Note:
- 'id' is the Primary Key.
- 'created_at' has a default value of now().
- 'color' has a default value of 'pink'.
- 'tag' has a default value of 'Work'.
*/

export const useNote = (id) => useQuery({
queryKey: ['notes', id],
queryFn: () => fromSupabase(supabase.from('notes').select('*').eq('id', id).single()),
});

export const useNotes = () => useQuery({
queryKey: ['notes'],
queryFn: () => fromSupabase(supabase.from('notes').select('*')),
});

export const useAddNote = () => {
const queryClient = useQueryClient();
const { session } = useSupabaseAuth();
return useMutation({
mutationFn: (newNote) => fromSupabase(supabase.from('notes').insert([{ ...newNote, user_id: session?.user?.id }])),
mutationFn: (newNote) => fromSupabase(supabase.from('notes').insert([newNote])),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['notes'] });
},
Expand All @@ -39,9 +48,8 @@ export const useAddNote = () => {

export const useUpdateNote = () => {
const queryClient = useQueryClient();
const { session } = useSupabaseAuth();
return useMutation({
mutationFn: ({ id, ...updateData }) => fromSupabase(supabase.from('notes').update(updateData).eq('id', id).eq('user_id', session?.user?.id)),
mutationFn: ({ id, ...updateData }) => fromSupabase(supabase.from('notes').update(updateData).eq('id', id)),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['notes'] });
},
Expand All @@ -50,9 +58,8 @@ export const useUpdateNote = () => {

export const useDeleteNote = () => {
const queryClient = useQueryClient();
const { session } = useSupabaseAuth();
return useMutation({
mutationFn: (id) => fromSupabase(supabase.from('notes').delete().eq('id', id).eq('user_id', session?.user?.id)),
mutationFn: (id) => fromSupabase(supabase.from('notes').delete().eq('id', id)),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['notes'] });
},
Expand Down
15 changes: 4 additions & 11 deletions src/integrations/supabase/hooks/useTagOperations.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { supabase } from '../supabase';
import { useSupabaseAuth } from '../auth';

export const useDeleteTag = () => {
const queryClient = useQueryClient();
const { session } = useSupabaseAuth();

return useMutation({
mutationFn: async (tagId) => {
Expand All @@ -13,7 +11,6 @@ export const useDeleteTag = () => {
.from('tags')
.select('tag')
.eq('id', tagId)
.eq('user_id', session?.user?.id)
.single();

if (tagError) throw tagError;
Expand All @@ -22,17 +19,15 @@ export const useDeleteTag = () => {
const { error: notesError } = await supabase
.from('notes')
.delete()
.eq('tag', tagData.tag)
.eq('user_id', session?.user?.id);
.eq('tag', tagData.tag);

if (notesError) throw notesError;

// Then, delete the tag itself
const { error: tagDeleteError } = await supabase
.from('tags')
.delete()
.eq('id', tagId)
.eq('user_id', session?.user?.id);
.eq('id', tagId);

if (tagDeleteError) throw tagDeleteError;
},
Expand All @@ -44,20 +39,18 @@ export const useDeleteTag = () => {
};

export const useCountNotesByTag = (tagText) => {
const { session } = useSupabaseAuth();
return useQuery({
queryKey: ['noteCount', tagText],
queryFn: async () => {
if (!tagText) return 0;
const { count, error } = await supabase
.from('notes')
.select('*', { count: 'exact', head: true })
.eq('tag', tagText)
.eq('user_id', session?.user?.id);
.eq('tag', tagText);

if (error) throw error;
return count;
},
enabled: !!tagText && !!session?.user?.id,
enabled: !!tagText,
});
};

0 comments on commit 3012e37

Please sign in to comment.