Skip to content

Commit

Permalink
Fix tag note count display
Browse files Browse the repository at this point in the history
Update the logic to correctly display the number of notes associated with a tag in the DeleteTagModal component.
[skip gpt_engineer]
  • Loading branch information
lovable-dev[bot] committed Oct 13, 2024
1 parent 4c12a94 commit ca47259
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/components/DeleteTagModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -54,9 +48,11 @@ const DeleteTagModal = ({ isOpen, onClose }) => {
</RadioGroup>
)}
</div>
{selectedTag && noteCount !== undefined && (
{selectedTag && (
<p className="text-yellow-500">
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.`}
</p>
)}
<DialogFooter>
Expand Down
6 changes: 3 additions & 3 deletions src/integrations/supabase/hooks/useTagOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit ca47259

Please sign in to comment.