{title}
diff --git a/src/components/sidebar/Dashboards.tsx b/src/components/sidebar/Dashboards.tsx
index 485eb98..59d22ec 100644
--- a/src/components/sidebar/Dashboards.tsx
+++ b/src/components/sidebar/Dashboards.tsx
@@ -7,6 +7,7 @@ import Button from '../Button';
import useDashboards from '@/app/(with-header-sidebar)/mydashboard/_hooks/useDashboards';
import useTriggerStore from '@/store/triggerStore';
import styles from './Dashboards.module.css';
+import useCardStore from '@/store/cardStore';
const PAGE_SIZE = 12;
@@ -45,11 +46,14 @@ export default function Dashboards() {
function DashboardItem({ id, color, title, createdByMe }: Dashboard) {
const isActive = usePathname() === `/dashboard/${id}`;
+ const handleClick = () => useCardStore.getState().clearCards();
+
return (
diff --git a/src/store/cardStore.ts b/src/store/cardStore.ts
index ceddfe5..45be289 100644
--- a/src/store/cardStore.ts
+++ b/src/store/cardStore.ts
@@ -2,13 +2,37 @@ import { create } from 'zustand';
import { Card } from '@/types/dashboardView';
interface CardState {
- card: Card | null;
- setCard: (newCard: Card) => void;
+ cards: Card[];
+ addCard: (newCard: Card) => void;
+ modifyCard: (id: number, updatedCard: Partial
) => void;
+ removeCard: (id: number) => void;
+ clearCards: () => void;
}
const useCardStore = create((set) => ({
- card: null,
- setCard: (newCard: Card) => set({ card: newCard }),
+ cards: [],
+ addCard: (newCard: Card) =>
+ set((state) => {
+ const exists = state.cards.some((card) => card.id === newCard.id);
+ if (exists) return state;
+ return {
+ cards: [...state.cards, newCard],
+ };
+ }),
+ modifyCard: (id, updatedCard) =>
+ set((state) => ({
+ cards: state.cards.map((card) =>
+ card.id === id ? { ...card, ...updatedCard } : card
+ ),
+ })),
+ removeCard: (id) =>
+ set((state) => ({
+ cards: state.cards.filter((card) => card.id !== id),
+ })),
+ clearCards: () =>
+ set(() => ({
+ cards: [],
+ })),
}));
export default useCardStore;