Zastosowanie wszystkich poprawek UI i logiki kalkulatora
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { Product } from '@/content/products';
|
||||
|
||||
interface RecentlyViewedState {
|
||||
items: Product[];
|
||||
addItem: (item: Product) => void;
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
export const useRecentlyViewedStore = create<RecentlyViewedState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
items: [],
|
||||
|
||||
addItem: (newItem) => {
|
||||
set((state) => {
|
||||
// Usuń, jeśli już jest na liście (aby przenieść na początek)
|
||||
const filtered = state.items.filter((i) => i.slug !== newItem.slug);
|
||||
// Dodaj na początek, zachowaj tylko ostatnie 4
|
||||
return { items: [newItem, ...filtered].slice(0, 4) };
|
||||
});
|
||||
},
|
||||
|
||||
clear: () => set({ items: [] }),
|
||||
}),
|
||||
{ name: 'thermcool-recently-viewed' }
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user