Zastosowanie wszystkich poprawek UI i logiki kalkulatora
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
interface CompareItem {
|
||||
slug: string;
|
||||
name: string;
|
||||
brand: string;
|
||||
price: number | null;
|
||||
image: string;
|
||||
specs: Record<string, string>;
|
||||
}
|
||||
|
||||
interface CompareState {
|
||||
items: CompareItem[];
|
||||
addItem: (item: CompareItem) => void;
|
||||
removeItem: (slug: string) => void;
|
||||
clearAll: () => void;
|
||||
isAdded: (slug: string) => boolean;
|
||||
}
|
||||
|
||||
export const useCompareStore = create<CompareState>()((set, get) => ({
|
||||
items: [],
|
||||
|
||||
addItem: (item) => {
|
||||
const { items } = get();
|
||||
if (items.length >= 3 || items.find((i) => i.slug === item.slug)) return;
|
||||
set({ items: [...items, item] });
|
||||
},
|
||||
|
||||
removeItem: (slug) =>
|
||||
set((state) => ({ items: state.items.filter((i) => i.slug !== slug) })),
|
||||
|
||||
clearAll: () => set({ items: [] }),
|
||||
|
||||
isAdded: (slug) => get().items.some((i) => i.slug === slug),
|
||||
}));
|
||||
Reference in New Issue
Block a user