diff --git a/src/components/DeleteTagModal.jsx b/src/components/DeleteTagModal.jsx index 8c4d3c0..1da025f 100644 --- a/src/components/DeleteTagModal.jsx +++ b/src/components/DeleteTagModal.jsx @@ -11,13 +11,7 @@ const DeleteTagModal = ({ isOpen, onClose }) => { const [selectedTag, setSelectedTag] = useState(null); const { data: tags, isLoading: tagsLoading } = useTags(); const { mutate: deleteTag } = useDeleteTag(); - const { data: noteCount, refetch: refetchNoteCount } = useCountNotesByTag(selectedTag); - - useEffect(() => { - if (selectedTag) { - refetchNoteCount(); - } - }, [selectedTag, refetchNoteCount]); + const { data: noteCount, isLoading: countLoading } = useCountNotesByTag(selectedTag); const handleDelete = async () => { if (!selectedTag) { @@ -54,9 +48,11 @@ const DeleteTagModal = ({ isOpen, onClose }) => { )} - {selectedTag && noteCount !== undefined && ( + {selectedTag && (

- Deleting this tag will delete {noteCount} notes using this tag. + {countLoading + ? 'Calculating affected notes...' + : `Deleting this tag will delete ${noteCount} note${noteCount !== 1 ? 's' : ''} using this tag.`}

)} diff --git a/src/integrations/supabase/hooks/useTagOperations.js b/src/integrations/supabase/hooks/useTagOperations.js index a174485..b21d98d 100644 --- a/src/integrations/supabase/hooks/useTagOperations.js +++ b/src/integrations/supabase/hooks/useTagOperations.js @@ -34,13 +34,13 @@ export const useCountNotesByTag = (tagId) => { queryKey: ['noteCount', tagId], queryFn: async () => { if (!tagId) return 0; - const { count, error } = await supabase + const { data, error } = await supabase .from('notes') - .select('*', { count: 'exact', head: true }) + .select('id', { count: 'exact' }) .eq('tag', tagId); if (error) throw error; - return count; + return data.length; }, enabled: !!tagId, });