add TypeScript interfaces for cart and cart items

Introduces BaseCartItem, MovieCartItem, SnackCartItem, and the CartItem
discriminated union in bigConstants.ts. Replaces all any-typed cart
references across CartView, CheckoutView, SnacksView, and BookingModal
with the new typed interfaces. Also types users/currentUser with the
existing User interface and removes the unused JSONType import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jannis Heydemann
2026-05-06 08:25:16 +02:00
parent e6fee6e4e1
commit 06606131ef
5 changed files with 97 additions and 58 deletions

View File

@@ -27,12 +27,12 @@ export const timePatterns = [
export const weekdayShort = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];
// Shared State
export const cart: unknown[] = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("eagleCart") || '[]') : '[]');
export const cart: CartItem[] = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("eagleCart") || '[]') : '[]');
export let occupiedSeatsData = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("eagleOccupied") || '{}') : '{}');
export const users: unknown[] = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("eagleUsers") || '[]') : '[]');
export let currentUser: unknown = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("currentUser") || 'null') : 'null');
export const users: User[] = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("eagleUsers") || '[]') : '[]');
export let currentUser: User | null = JSON.parse(typeof window !== 'undefined' ? (localStorage.getItem("currentUser") || 'null') : 'null');
export function updateCart(newCart: unknown[]) {
export function updateCart(newCart: CartItem[]) {
cart.splice(0, cart.length, ...newCart);
if (typeof window !== 'undefined') {
localStorage.setItem("eagleCart", JSON.stringify(cart));
@@ -57,7 +57,7 @@ export function persistUsers() {
if (typeof window !== 'undefined') localStorage.setItem("eagleUsers", JSON.stringify(users));
}
export function persistCurrentUser(user: unknown) {
export function persistCurrentUser(user: User | null) {
currentUser = user;
if (typeof window !== 'undefined') {
if (currentUser) localStorage.setItem("currentUser", JSON.stringify(currentUser));
@@ -65,6 +65,30 @@ export function persistCurrentUser(user: unknown) {
}
}
export interface BaseCartItem {
id: number;
category: "movie" | "snack";
title: string;
/** Hall name for movies; size label (e.g. "0,33L") for snacks */
hall: string;
/** Showtime for movies; flavour/variant for snacks */
time: string;
price: number;
img?: string;
}
export interface MovieCartItem extends BaseCartItem {
category: "movie";
seatId: string;
}
export interface SnackCartItem extends BaseCartItem {
category: "snack";
type: "SNACK";
}
export type CartItem = MovieCartItem | SnackCartItem;
export interface User {
firstName: string;
lastName: string;