From dec9c0b04e42acfbfaefd9bb09066fc676aed0b6 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:59:31 +0000 Subject: [PATCH] Persist new tags on refresh Implement functionality to ensure that newly added tags are persisted across page refreshes, preventing loss of data. [skip gpt_engineer] --- src/components/Sidebar.jsx | 22 +++++++++++++-------- src/integrations/supabase/hooks/useTags.js | 23 ++++++++++++++++++++++ src/pages/Index.jsx | 22 +++++---------------- 3 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 src/integrations/supabase/hooks/useTags.js diff --git a/src/components/Sidebar.jsx b/src/components/Sidebar.jsx index eab0b3d..1f34806 100644 --- a/src/components/Sidebar.jsx +++ b/src/components/Sidebar.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { CircleUserRound, ChevronLeft, ChevronRight, Check, X, Plus } from 'lucide-react'; import { useSupabaseAuth } from '../integrations/supabase'; import { useNavigate } from 'react-router-dom'; -import { useNotes } from '../integrations/supabase'; +import { useNotes, useTags, useAddTag } from '../integrations/supabase'; import { DropdownMenu, DropdownMenuContent, @@ -21,14 +21,16 @@ import { Button } from "@/components/ui/button"; import { format } from 'date-fns'; import AddTagModal from './AddTagModal'; -const Sidebar = ({ activeFilters, toggleFilter, clearFilters, categories, addNewCategory }) => { +const Sidebar = ({ activeFilters, toggleFilter, clearFilters, addNewCategory }) => { const [isCollapsed, setIsCollapsed] = useState(false); const { session, logout } = useSupabaseAuth(); const navigate = useNavigate(); const [isLogoutDialogOpen, setIsLogoutDialogOpen] = useState(false); const [isProfileDialogOpen, setIsProfileDialogOpen] = useState(false); const [isAddTagModalOpen, setIsAddTagModalOpen] = useState(false); - const { data: notes, isLoading } = useNotes(); + const { data: notes, isLoading: notesLoading } = useNotes(); + const { data: tags, isLoading: tagsLoading } = useTags(); + const addTag = useAddTag(); useEffect(() => { const handleResize = () => { @@ -56,17 +58,21 @@ const Sidebar = ({ activeFilters, toggleFilter, clearFilters, categories, addNew }; const getCategoryCount = (categoryName) => { - if (isLoading || !notes) return 0; + if (notesLoading || !notes) return 0; return notes.filter(note => note.tag === categoryName).length; }; const handleAddNewTag = (newTag) => { - addNewCategory(newTag); + addTag.mutate({ name: newTag.name, color: newTag.color }); setIsAddTagModalOpen(false); }; + if (tagsLoading) { + return