Replace entire repo content with kottgard-production-v1.1.zip (for shahikitchen-prod repo)

This commit is contained in:
root
2026-06-29 15:04:08 +00:00
parent 6cd5aaa048
commit 57cc67d2d3
850 changed files with 26149 additions and 15588 deletions
-115
View File
@@ -1,115 +0,0 @@
'use client';
import React, { createContext, useContext, useReducer, useEffect, ReactNode } from 'react';
import { toast } from 'sonner';
import { cartReducer, getCartTotals } from '@/domain/cart/cart-domain';
import type { CartItem, NewCartItem } from '@/domain/cart/entities';
import { container } from '@/infrastructure/di/container';
import { playAddSound } from '@/infrastructure/audio/web-audio-sound-adapter';
export type { CartItem };
interface CartContextType {
items: CartItem[];
isOpen: boolean;
totalItems: number;
totalPrice: number;
addToCart: (item: NewCartItem) => void;
removeFromCart: (id: string) => void;
updateQuantity: (id: string, quantity: number) => void;
clearCart: () => void;
toggleCart: () => void;
openCart: () => void;
closeCart: () => void;
}
const CartContext = createContext<CartContextType | undefined>(undefined);
export function CartProvider({ children }: { children: ReactNode }) {
const [state, dispatch] = useReducer(cartReducer, {
items: [],
isOpen: false,
});
useEffect(() => {
const savedItems = container.cartRepository.load();
if (savedItems.length > 0) {
dispatch({ type: 'RESTORE_ITEMS', payload: savedItems });
}
}, []);
useEffect(() => {
container.cartRepository.save(state.items);
}, [state.items]);
const { totalItems, totalPrice } = getCartTotals(state.items);
const addToCart = (item: NewCartItem) => {
dispatch({ type: 'ADD_ITEM', payload: item });
playAddSound();
const priceLabel =
item.pricingMode === 'weight'
? `${item.pricePerHalfKg ?? item.price} kr / ½ kg`
: `${item.price} kr`;
toast.success(`Added ${item.name} to cart`, {
description: priceLabel,
action: {
label: 'View Cart',
onClick: () => dispatch({ type: 'OPEN_CART' }),
},
});
};
const removeFromCart = (id: string) => {
dispatch({ type: 'REMOVE_ITEM', payload: id });
};
const updateQuantity = (id: string, quantity: number) => {
dispatch({ type: 'UPDATE_QUANTITY', payload: { id, quantity } });
};
const clearCart = () => {
dispatch({ type: 'CLEAR_CART' });
};
const toggleCart = () => {
dispatch({ type: 'TOGGLE_CART' });
};
const openCart = () => {
dispatch({ type: 'OPEN_CART' });
};
const closeCart = () => {
dispatch({ type: 'CLOSE_CART' });
};
return (
<CartContext.Provider
value={{
items: state.items,
isOpen: state.isOpen,
totalItems,
totalPrice,
addToCart,
removeFromCart,
updateQuantity,
clearCart,
toggleCart,
openCart,
closeCart,
}}
>
{children}
</CartContext.Provider>
);
}
export function useCart() {
const context = useContext(CartContext);
if (context === undefined) {
throw new Error('useCart must be used within a CartProvider');
}
return context;
}
@@ -1,53 +0,0 @@
'use client';
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { isRtlLanguage, type Language } from '@/domain/language/entities';
import {
persistLanguage,
resolveInitialLanguage,
} from '@/application/language/language-use-cases';
import { container } from '@/infrastructure/di/container';
interface LanguageContextType {
language: Language;
setLanguage: (lang: Language) => void;
isRtl: boolean;
}
const LanguageContext = createContext<LanguageContextType | undefined>(undefined);
export function LanguageProvider({ children }: { children: ReactNode }) {
const [language, setLanguageState] = useState<Language>('sv');
useEffect(() => {
setLanguageState(resolveInitialLanguage(container.languageRepository));
}, []);
useEffect(() => {
const root = document.documentElement;
root.lang = language;
root.dir = isRtlLanguage(language) ? 'rtl' : 'ltr';
root.dataset.locale = language;
}, [language]);
const setLanguage = (lang: Language) => {
setLanguageState(lang);
persistLanguage(container.languageRepository, lang);
};
return (
<LanguageContext.Provider
value={{ language, setLanguage, isRtl: isRtlLanguage(language) }}
>
{children}
</LanguageContext.Provider>
);
}
export function useLanguage() {
const context = useContext(LanguageContext);
if (context === undefined) {
throw new Error('useLanguage must be used within a LanguageProvider');
}
return context;
}
@@ -1,113 +0,0 @@
'use client';
import React, { createContext, useContext, useReducer, useEffect, ReactNode } from 'react';
import { toast } from 'sonner';
import {
wishlistReducer,
isInWishlist,
getWishlistCount,
} from '@/domain/wishlist/wishlist-domain';
import type { WishlistItem, NewWishlistItem } from '@/domain/wishlist/entities';
import { container } from '@/infrastructure/di/container';
export type { WishlistItem };
interface WishlistContextType {
items: WishlistItem[];
isOpen: boolean;
totalItems: number;
toggleWishlist: (item: NewWishlistItem) => void;
removeFromWishlist: (id: string) => void;
clearWishlist: () => void;
isWishlisted: (id: string) => boolean;
toggleDrawer: () => void;
openWishlist: () => void;
closeWishlist: () => void;
}
const WishlistContext = createContext<WishlistContextType | undefined>(undefined);
export function WishlistProvider({ children }: { children: ReactNode }) {
const [state, dispatch] = useReducer(wishlistReducer, {
items: [],
isOpen: false,
});
useEffect(() => {
const savedItems = container.wishlistRepository.load();
if (savedItems.length > 0) {
dispatch({ type: 'RESTORE_ITEMS', payload: savedItems });
}
}, []);
useEffect(() => {
container.wishlistRepository.save(state.items);
}, [state.items]);
const totalItems = getWishlistCount(state.items);
const toggleWishlist = (item: NewWishlistItem) => {
const wasInList = isInWishlist(state.items, item.id);
dispatch({ type: 'TOGGLE_ITEM', payload: item });
if (wasInList) {
toast.info(`Removed ${item.name} from wishlist`);
} else {
toast.success(`Saved ${item.name} to wishlist`, {
action: {
label: 'View',
onClick: () => dispatch({ type: 'OPEN_DRAWER' }),
},
});
}
};
const removeFromWishlist = (id: string) => {
dispatch({ type: 'REMOVE_ITEM', payload: id });
};
const clearWishlist = () => {
dispatch({ type: 'CLEAR_WISHLIST' });
};
const isWishlisted = (id: string) => isInWishlist(state.items, id);
const toggleDrawer = () => {
dispatch({ type: 'TOGGLE_DRAWER' });
};
const openWishlist = () => {
dispatch({ type: 'OPEN_DRAWER' });
};
const closeWishlist = () => {
dispatch({ type: 'CLOSE_DRAWER' });
};
return (
<WishlistContext.Provider
value={{
items: state.items,
isOpen: state.isOpen,
totalItems,
toggleWishlist,
removeFromWishlist,
clearWishlist,
isWishlisted,
toggleDrawer,
openWishlist,
closeWishlist,
}}
>
{children}
</WishlistContext.Provider>
);
}
export function useWishlist() {
const context = useContext(WishlistContext);
if (context === undefined) {
throw new Error('useWishlist must be used within a WishlistProvider');
}
return context;
}