From bf37850e79f4238c95d0c38997e1748dd34b4c4e Mon Sep 17 00:00:00 2001 From: nessi Date: Tue, 3 Feb 2026 20:15:46 +0100 Subject: [PATCH] Improve chip selection and modal closing behavior Updated the chip handling logic to ensure a smoother user experience by immediately closing modals in the frontend before performing asynchronous operations. Enhanced error handling and streamlined tag display logic for clarity and consistency. --- frontend/src/App.jsx | 53 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 572e7d4..86b2737 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -392,45 +392,64 @@ export default function App() { const chooseChip = async (chip) => { if (!chipEntry) return; - setChipLS(gameId, chipEntry.entry_id, chip); - - await api(`/games/${gameId}/sheet/${chipEntry.entry_id}`, { - method: "PATCH", - body: JSON.stringify({ note_tag: "s" }), - }); - + // UI sofort schließen -> fühlt sich besser an + const entry = chipEntry; setChipOpen(false); setChipEntry(null); - await reloadSheet(); + + // local speichern + setChipLS(gameId, entry.entry_id, chip); + + try { + // Backend bekommt nur "s" + await api(`/games/${gameId}/sheet/${entry.entry_id}`, { + method: "PATCH", + body: JSON.stringify({ note_tag: "s" }), + }); + } finally { + await reloadSheet(); + } }; // X im Modal: // Backend zurück auf null und lokalen Chip löschen const closeChipModalToDash = async () => { - if (chipEntry) { - clearChipLS(gameId, chipEntry.entry_id); + if (!chipEntry) { + setChipOpen(false); + return; + } - await api(`/games/${gameId}/sheet/${chipEntry.entry_id}`, { + // UI sofort schließen + const entry = chipEntry; + setChipOpen(false); + setChipEntry(null); + + // Frontend-only Chip entfernen + clearChipLS(gameId, entry.entry_id); + + try { + // Backend zurück auf — + await api(`/games/${gameId}/sheet/${entry.entry_id}`, { method: "PATCH", body: JSON.stringify({ note_tag: null }), }); - + } finally { await reloadSheet(); } - setChipOpen(false); - setChipEntry(null); }; // Anzeige im Tag-Button: - // - "s" wird zu "s.AL" (aus localStorage), sonst "s.XX" + // - "s" wird zu "s.AL" (aus localStorage), sonst "s" const displayTag = (entry) => { const t = entry.note_tag; if (!t) return "—"; + if (t === "s") { const chip = getChipLS(gameId, entry.entry_id); - return `s.${chip || "XX"}`; + return chip ? `s.${chip}` : "s"; // <-- genau wie gewünscht } - return t; + + return t; // i oder m }; // --- helpers ---