fix: prevent browser caching of booked dates and ensure booked dates are immediately disabled
This commit is contained in:
@@ -79,6 +79,14 @@
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
try {
|
||||
const localBooked = JSON.parse(localStorage.getItem("bookedDates") || "[]");
|
||||
if (!localBooked.includes(selectedDate)) {
|
||||
localBooked.push(selectedDate);
|
||||
localStorage.setItem("bookedDates", JSON.stringify(localBooked));
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
summarySection.classList.add("hidden");
|
||||
if (backLink) {
|
||||
backLink.classList.add("hidden");
|
||||
|
||||
+14
-5
@@ -38,22 +38,31 @@
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
fetch("appsettings.json").then((res) => res.json()),
|
||||
fetch("/api/booked-dates")
|
||||
fetch("appsettings.json?t=" + Date.now()).then((res) => res.json()),
|
||||
fetch("/api/booked-dates?t=" + Date.now(), { cache: "no-store" })
|
||||
.then((res) => (res.ok ? res.json() : []))
|
||||
.catch(() => []),
|
||||
])
|
||||
.then(([settings, bookedDates]) => {
|
||||
bookedDatesSet = new Set(bookedDates || []);
|
||||
let localBooked = [];
|
||||
try {
|
||||
localBooked = JSON.parse(localStorage.getItem("bookedDates") || "[]");
|
||||
} catch (e) {}
|
||||
|
||||
const allBooked = [...(bookedDates || []), ...localBooked]
|
||||
.map((d) => (typeof d === "string" ? d.trim() : ""))
|
||||
.filter(Boolean);
|
||||
|
||||
bookedDatesSet = new Set(allBooked);
|
||||
|
||||
const datesList = settings.availableDates || [];
|
||||
datesList.forEach((item) => {
|
||||
let key = "";
|
||||
let type = "long";
|
||||
if (typeof item === "string") {
|
||||
key = item;
|
||||
key = item.trim();
|
||||
} else if (item && item.date) {
|
||||
key = item.date;
|
||||
key = item.date.trim();
|
||||
type = item.type || "long";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user