diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4782d71..c6b7787 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,28 +1,23 @@ import React, { useState, useEffect } from "react"; -import { BrowserRouter as Router, Routes, Route, Link, Navigate } from "react-router-dom"; +import { BrowserRouter as Router, Routes, Route, Link, Navigate, useParams } from "react-router-dom"; import { getSeed, getTrips, getTripItems, toggleTripItem } from "./api"; import ItemsPage from "./pages/ItemsPage"; +import TripChecklist from "./pages/TripChecklist"; export default function App() { const [trips, setTrips] = useState([]); - const [items, setItems] = useState>({}); async function loadTrips() { const data = await getTrips(); setTrips(data); } - async function loadItems(tripId: string) { - const data = await getTripItems(tripId); - setItems((prev) => ({ ...prev, [tripId]: data })); - } - useEffect(() => { loadTrips(); }, []); return ( - +

Packlist

@@ -52,47 +47,25 @@ export default function App() { +
    {trips.map((trip) => ( -
    -
    -
    -

    {trip.name}

    -

    - {trip.start_date} – {trip.end_date} -

    -
    - -
    - {items[trip.id] && ( -
      - {items[trip.id].map((item) => ( -
    • - { - await toggleTripItem(item.id); - await loadItems(trip.id); - }} - /> - {item.name_calculated} -
    • - ))} -
    - )} -
    +
  • + + {trip.name} ({trip.start_date} – {trip.end_date}) + +
  • ))} - +
} /> + } + /> } /> - {/* Optional: Redirect / to /trips */} } />
diff --git a/frontend/src/pages/TripChecklist.tsx b/frontend/src/pages/TripChecklist.tsx new file mode 100644 index 0000000..d4c135c --- /dev/null +++ b/frontend/src/pages/TripChecklist.tsx @@ -0,0 +1,42 @@ +// filepath: frontend/src/pages/TripChecklist.tsx +import React, { useState, useEffect } from "react"; +import { useParams } from "react-router-dom"; +import { getTripItems, toggleTripItem } from "../api"; + +export default function TripChecklist({ trips }: { trips: any[] }) { + const { id } = useParams(); + const [items, setItems] = useState([]); + + useEffect(() => { + if (id) { + getTripItems(id).then(setItems); + } + }, [id]); + + const trip = trips.find((t) => t.id === id); + + if (!trip) return
Trip not found
; + + return ( +
+

{trip.name}

+

{trip.start_date} – {trip.end_date}

+
    + {items.map((item) => ( +
  • + { + await toggleTripItem(item.id); + const updated = await getTripItems(id!); + setItems(updated); + }} + /> + {item.name_calculated} +
  • + ))} +
+
+ ); +} \ No newline at end of file