diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 7239496..e6b2002 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -3,6 +3,9 @@ import React, { useEffect, useState } from "react"; const API = "/api"; const CHIP_LIST = ["AL", "JG", "JN", "SN", "TL"]; +const [chipOpen, setChipOpen] = useState(false); +const [chipEntry, setChipEntry] = useState(null); + async function api(path, opts = {}) { const res = await fetch(API + path, { credentials: "include", @@ -378,25 +381,18 @@ export default function App() { }; const toggleTag = async (entry) => { - const next = nextBaseTag(entry.note_tag); + const next = cycleTag(entry.note_tag); - // Wenn wir bei "s" angekommen sind -> Popup öffnen if (next === "s") { - setChipPickEntry(entry); - setChipPickOpen(true); + setChipEntry(entry); + setChipOpen(true); return; } - // Wenn wir von "s" weg gehen -> Chip local löschen - if (baseTag(entry.note_tag) === "s" && next === null) { - clearChipLS(gameId, entry.entry_id); - } - await api(`/games/${gameId}/sheet/${entry.entry_id}`, { method: "PATCH", body: JSON.stringify({ note_tag: next }), }); - await reloadSheet(); }; @@ -406,21 +402,30 @@ export default function App() { }; const chooseChip = async (chip) => { - if (!chipPickEntry) return; + if (!chipEntry) return; - // Chip lokal speichern - setChipLS(gameId, chipPickEntry.entry_id, chip); - - // Backend nur "s" setzen - await api(`/games/${gameId}/sheet/${chipPickEntry.entry_id}`, { + await api(`/games/${gameId}/sheet/${chipEntry.entry_id}`, { method: "PATCH", - body: JSON.stringify({ note_tag: "s" }), + body: JSON.stringify({ note_tag: `s.${chip}` }), }); - closeChipPick(); + setChipOpen(false); + setChipEntry(null); await reloadSheet(); }; + const closeChipModalToDash = async () => { + if (chipEntry) { + await api(`/games/${gameId}/sheet/${chipEntry.entry_id}`, { + method: "PATCH", + body: JSON.stringify({ note_tag: null }), + }); + await reloadSheet(); + } + setChipOpen(false); + setChipEntry(null); + }; + // --- helpers --- const getRowBg = (status) => { if (status === 1) return "rgba(255, 35, 35, 0.16)"; @@ -654,41 +659,30 @@ export default function App() { )} - {chipPickOpen && ( -