Skip to content

Commit

Permalink
964: Fixed check for existence
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Apr 5, 2024
1 parent 2dbdd23 commit 93c7d99
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions build/calendar-config-develop.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"id": "01FRJPF4XATRN8PBZ35XN84PS6",
"description": "Mulighed for at vise et kalenderfeed.",
"resources": {
"component": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar.js?ts=1712312137403",
"admin": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-admin.json?ts=1712312137403",
"schema": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-schema.json?ts=1712312137403",
"component": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar.js?ts=1712320739376",
"admin": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-admin.json?ts=1712320739376",
"schema": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-schema.json?ts=1712320739376",
"assets": [],
"options": {},
"content": {}
Expand Down
6 changes: 3 additions & 3 deletions build/calendar-config-main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"id": "01FRJPF4XATRN8PBZ35XN84PS6",
"description": "Mulighed for at vise et kalenderfeed.",
"resources": {
"component": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar.js?ts=1712312137403",
"admin": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-admin.json?ts=1712312137403",
"schema": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-schema.json?ts=1712312137403",
"component": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar.js?ts=1712320739376",
"admin": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-admin.json?ts=1712320739376",
"schema": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-schema.json?ts=1712320739376",
"assets": [],
"options": {},
"content": {}
Expand Down
2 changes: 1 addition & 1 deletion build/calendar.js

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions src/calendar/calendar-single-booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ function CalendarSingleBooking({
const tenantKey = localStorage.getItem("tenantKey");
const apiUrl = localStorage.getItem("apiUrl");

const instantBookingLocalStorageKey = "instantBookings";
const instantBookingKey = "instantBookings";
const getInstantBookingFromLocalStorage = (slideId) => {
const localstorageEntry = localStorage.getItem(
instantBookingLocalStorageKey
);
const localstorageEntry = localStorage.getItem(instantBookingKey);

if (localstorageEntry === null) {
return null;
Expand All @@ -52,19 +50,18 @@ function CalendarSingleBooking({
};

const setInstantBookingFromLocalStorage = (slideId, value) => {
const localstorageEntry = localStorage.getItem(
instantBookingLocalStorageKey
);
const localstorageEntry = localStorage.getItem(instantBookingKey);

const instantBookings =
localstorageEntry !== null ? JSON.parse(localstorageEntry) : {};

instantBookings[slideId] = value;
if (value !== null) {
instantBookings[slideId] = value;
} else {
delete instantBookings[slideId];
}

localStorage.setItem(
instantBookingLocalStorageKey,
JSON.stringify(instantBookings)
);
localStorage.setItem(instantBookingKey, JSON.stringify(instantBookings));
};

const [bookableIntervals, setBookableIntervals] = useState([]);
Expand Down Expand Up @@ -190,9 +187,11 @@ function CalendarSingleBooking({

const instantBooking = getInstantBookingFromLocalStorage(slide["@id"]);

if (instantBooking !== null) {
if (dayjs(instantBooking.interval.to) > dayjs) {
// Clean out old instantBookings.
if (instantBooking) {
if (dayjs(instantBooking.interval.to) < dayjs()) {
setInstantBookingFromLocalStorage(slide["@id"], null);
setBookingResult(null);
} else {
setBookingResult(instantBooking);
}
Expand Down

0 comments on commit 93c7d99

Please sign in to comment.