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 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 { getSeed, getTrips, getTripItems, toggleTripItem } from "./api";
|
||||||
import ItemsPage from "./pages/ItemsPage";
|
import ItemsPage from "./pages/ItemsPage";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [view, setView] = useState<"trips" | "items">("trips");
|
|
||||||
|
|
||||||
const [trips, setTrips] = useState<any[]>([]);
|
const [trips, setTrips] = useState<any[]>([]);
|
||||||
const [items, setItems] = useState<Record<string, any[]>>({});
|
const [items, setItems] = useState<Record<string, any[]>>({});
|
||||||
|
|
||||||
|
|
@ -20,10 +18,8 @@ export default function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (view === "trips") {
|
|
||||||
loadTrips();
|
loadTrips();
|
||||||
}
|
}, []);
|
||||||
}, [view]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
|
|
@ -31,8 +27,18 @@ export default function App() {
|
||||||
<h1 className="text-2xl font-bold mb-4">Packlist</h1>
|
<h1 className="text-2xl font-bold mb-4">Packlist</h1>
|
||||||
|
|
||||||
<div className="flex gap-2 mb-4">
|
<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
|
<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 () => {
|
onClick={async () => {
|
||||||
await getSeed();
|
await getSeed();
|
||||||
await loadTrips();
|
await loadTrips();
|
||||||
|
|
@ -40,16 +46,11 @@ export default function App() {
|
||||||
>
|
>
|
||||||
Seed-Daten erzeugen
|
Seed-Daten erzeugen
|
||||||
</button>
|
</button>
|
||||||
<Link to="/items">
|
|
||||||
<button className="bg-green-500 text-white px-4 py-2 rounded">
|
|
||||||
Alle Items
|
|
||||||
</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/trips"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
{trips.map((trip) => (
|
{trips.map((trip) => (
|
||||||
|
|
@ -91,6 +92,8 @@ export default function App() {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route path="/items" element={<ItemsPage />} />
|
<Route path="/items" element={<ItemsPage />} />
|
||||||
|
{/* Optional: Redirect / to /trips */}
|
||||||
|
<Route path="/" element={<Navigate to="/trips" />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue