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.
This commit is contained in:
2026-02-03 20:15:46 +01:00
parent a9dbbd65a4
commit bf37850e79

View File

@@ -392,45 +392,64 @@ export default function App() {
const chooseChip = async (chip) => {
if (!chipEntry) return;
setChipLS(gameId, chipEntry.entry_id, chip);
// UI sofort schließen -> fühlt sich besser an
const entry = chipEntry;
setChipOpen(false);
setChipEntry(null);
await api(`/games/${gameId}/sheet/${chipEntry.entry_id}`, {
// 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" }),
});
setChipOpen(false);
setChipEntry(null);
} 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 ---