feat: remove view state and add /trips route
This commit is contained in:
parent
98535aad7a
commit
e79d3a2b87
1 changed files with 17 additions and 14 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
|
||||
import { BrowserRouter as Router, Routes, Route, Link, Navigate } from "react-router-dom";
|
||||
import { getSeed, getTrips, getTripItems, toggleTripItem } from "./api";
|
||||
import ItemsPage from "./pages/ItemsPage";
|
||||
|
||||
export default function App() {
|
||||
const [view, setView] = useState<"trips" | "items">("trips");
|
||||
|
||||
const [trips, setTrips] = useState<any[]>([]);
|
||||
const [items, setItems] = useState<Record<string, any[]>>({});
|
||||
|
||||
|
|
@ -20,10 +18,8 @@ export default function App() {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (view === "trips") {
|
||||
loadTrips();
|
||||
}
|
||||
}, [view]);
|
||||
loadTrips();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Router>
|
||||
|
|
@ -31,8 +27,18 @@ export default function App() {
|
|||
<h1 className="text-2xl font-bold mb-4">Packlist</h1>
|
||||
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Link to="/trips">
|
||||
<button className="bg-blue-500 text-white px-4 py-2 rounded">
|
||||
Alle Trips
|
||||
</button>
|
||||
</Link>
|
||||
<Link to="/items">
|
||||
<button className="bg-green-500 text-white px-4 py-2 rounded">
|
||||
Alle Items
|
||||
</button>
|
||||
</Link>
|
||||
<button
|
||||
className="bg-blue-500 text-white px-4 py-2 rounded"
|
||||
className="bg-gray-300 text-gray-800 px-4 py-2 rounded"
|
||||
onClick={async () => {
|
||||
await getSeed();
|
||||
await loadTrips();
|
||||
|
|
@ -40,16 +46,11 @@ export default function App() {
|
|||
>
|
||||
Seed-Daten erzeugen
|
||||
</button>
|
||||
<Link to="/items">
|
||||
<button className="bg-green-500 text-white px-4 py-2 rounded">
|
||||
Alle Items
|
||||
</button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<Routes>
|
||||
<Route
|
||||
path="/"
|
||||
path="/trips"
|
||||
element={
|
||||
<>
|
||||
{trips.map((trip) => (
|
||||
|
|
@ -91,6 +92,8 @@ export default function App() {
|
|||
}
|
||||
/>
|
||||
<Route path="/items" element={<ItemsPage />} />
|
||||
{/* Optional: Redirect / to /trips */}
|
||||
<Route path="/" element={<Navigate to="/trips" />} />
|
||||
</Routes>
|
||||
</div>
|
||||
</Router>
|
||||
|
|
|
|||
Loading…
Reference in a new issue