Browse Source

disabled fetch caching

Liontix 11 months ago
parent
commit
6f317e4ee7

+ 20 - 23
public/html/appointments.html

@@ -22,29 +22,26 @@
     </ul>
 </nav>
 <div class="content hidden" id="content">
-
-<div class="container">
-
-    <h2 class="heading">Appointments</h2>
-    <table>
-        <thead>
-        <tr>
-            <th>Title</th>
-            <th>Description</th>
-            <th>Due Date</th>
-            <th>Place</th>
-            <th>Time Span</th>
-            <th>Share</th>
-            <th>Participants</th>
-            <th>Edit</th>
-            <th>Delete</th>
-        </tr>
-        </thead>
-        <tbody id="appointment-table-body">
-        <!-- Data will be inserted here via JavaScript -->
-        </tbody>
-    </table>
-</div>
+    <div class="container">
+        <h2 class="heading">Appointments</h2>
+        <table>
+            <thead>
+            <tr>
+                <th>Title</th>
+                <th>Description</th>
+                <th>Due Date</th>
+                <th>Place</th>
+                <th>Time Span</th>
+                <th>Share</th>
+                <th>Participants</th>
+                <th>Edit</th>
+                <th>Delete</th>
+            </tr>
+            </thead>
+            <tbody id="appointment-table-body">
+            </tbody>
+        </table>
+    </div>
 </div>
 </body>
 </html>

+ 1 - 1
public/html/appointmentscreator.html

@@ -11,8 +11,8 @@
     <link rel="stylesheet" href="../stylesheets/style.css">
     <link rel="stylesheet" href="../stylesheets/create-appointment.css">
 </head>
-<body>
 
+<body>
 <nav class="navbar">
     <div class="navbar-brand">Scheduler</div>
     <ul class="navbar-links">

+ 0 - 1
public/html/auth.html

@@ -27,7 +27,6 @@
             <button class="btn" id="btn-login">Login</button>
             <button class="btn" id="btn-register">Register</button>
             <p class="msg-error" id="login-error"></p>
-
         </div>
     </div>
 </div>

+ 8 - 3
public/javascripts/appointments.js

@@ -32,11 +32,16 @@ function renderAppointments(data) {
         const participantATag = document.createElement('a');
         const editATag = document.createElement('a');
         const deleteButton = document.createElement('button');
-        participantATag.href = `/html/bookings.html?appointment=${appointment._id}`;
+
+        const searchParams = new URLSearchParams({
+            appointment: appointment._id,
+        });
+
+        participantATag.href = '/html/bookings.html?' + searchParams.toString();
         participantATag.innerText = 'participants';
         participantATag.classList.add('participants-link');
-        editATag.href = `/html/appointmentscreator.html?appointment=${appointment._id}`;
-        shareATag.href = `/html/schedule.html?appointment=${appointment._id}`;
+        editATag.href = '/html/appointmentscreator.html?' + searchParams.toString();
+        shareATag.href = '/html/schedule.html?' + searchParams.toString();
         shareATag.innerText = 'share';
         shareATag.classList.add('share-link');
         editATag.innerText = 'edit';

+ 3 - 1
public/javascripts/auth.js

@@ -1,5 +1,7 @@
 "use strict";
 
+import {fetchRegular} from "./utils.js";
+
 const emailInput = document.getElementById("login-email");
 const passwordInput = document.getElementById("login-password");
 const errorMessageParagraph = document.getElementById("login-error");
@@ -19,7 +21,7 @@ window.addEventListener("load", function () {
 async function sendAuthRequest(type) {
     console.log(emailInput.value);
     console.log(passwordInput.value);
-    const response = await fetch(
+    const response = await fetchRegular(
         "/api/auth/" + type,
         {
             method: "POST",

+ 12 - 3
public/javascripts/bookings.js

@@ -1,4 +1,4 @@
-import {fetchWithToken, getTimeSpan, parseOrRedirect} from "./utils.js";
+import {fetchRegular, fetchWithToken, getTimeSpan, parseOrRedirect} from "./utils.js";
 "use strict";
 
 window.addEventListener("load", async function () {
@@ -62,7 +62,12 @@ function displayAppointmentDetails(appointmentData) {
 async function getAppointment(appointment) {
     const options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
 
-    const response = await fetch(`/api/schedule?isUser=true&appointmentId=${appointment}`, options)
+    const searchParams = new URLSearchParams({
+        appointmentId: appointment,
+        isUser: true
+    });
+
+    const response = await fetchRegular(`/api/schedule?` + searchParams.toString(), options)
         .catch(err => console.error('error:' + err));
 
     const js = await parseOrRedirect(response);
@@ -100,7 +105,11 @@ function renderBookings(data) {
 
 
 async function fetchBookings(appointmentId) {
-    const response = await fetchWithToken(`/api/users/bookings?appointmentId=${appointmentId}`);
+    const searchParams = new URLSearchParams({
+        appointmentId: appointmentId,
+    });
+
+    const response = await fetchWithToken('/api/users/bookings?' + searchParams.toString());
     const js = await parseOrRedirect(response);
     renderBookings(js);
 }

+ 16 - 5
public/javascripts/creator-appointments.js

@@ -1,6 +1,6 @@
 "use strict";
 
-import {fetchWithToken, parseOrRedirect} from "./utils.js";
+import {fetchRegular, fetchWithToken, parseOrRedirect} from "./utils.js";
 
 const appointmentErrorParagraph = document.getElementById("appointment-error");
 const appointmentSuccessParagraph = document.getElementById("appointment-success");
@@ -12,7 +12,7 @@ const endDateInput = document.getElementById('endDate');
 const placeInput = document.getElementById('place');
 
 
-window.addEventListener("load", async function() {
+window.addEventListener("load", async function () {
     const urlParams = new URLSearchParams(window.location.search);
     const appointment = urlParams.get('appointment');
 
@@ -46,7 +46,14 @@ async function displayAppointment(data) {
 async function loadAppointment(appointment) {
     let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
 
-    const response = await fetch(`/api/schedule?appointmentId=${appointment}&isUser=true`, options)
+    console.log(window.location.host);
+
+    const searchParams = new URLSearchParams({
+        appointmentId: appointment,
+        isUser: true
+    });
+
+    const response = await fetchRegular("/api/schedule?" + searchParams.toString(), options)
         .catch(err => console.error('error:' + err));
 
     const js = await parseOrRedirect(response);
@@ -74,7 +81,7 @@ async function createAppointment() {
 }
 
 async function setAppointment(endpoint, appointment) {
-    const { title, description, dueDate, startDate, endDate, place } = getParameters();
+    const {title, description, dueDate, startDate, endDate, place} = getParameters();
 
     if (!title || !description || !dueDate || !startDate || !endDate) {
         appointmentSuccessParagraph.innerText = "";
@@ -100,7 +107,11 @@ async function setAppointment(endpoint, appointment) {
         appointmentSuccessParagraph.innerText = "";
         appointmentErrorParagraph.innerText = js["message"];
     } else {
-        const path = `/html/schedule.html?appointment=${js["id"]}`;
+        const searchParams = new URLSearchParams({
+            appointment: js["id"],
+        });
+
+        const path = '/html/schedule.html?' + searchParams.toString();
         appointmentErrorParagraph.innerText = "";
         appointmentSuccessParagraph.innerText = "Appointment created successfully. The share link " +
             "was copied to your clipboard";

+ 8 - 3
public/javascripts/schedule.js

@@ -1,6 +1,6 @@
 "use strict";
 
-import {getTimeSpan, parseOrRedirect} from "./utils.js";
+import {fetchRegular, getTimeSpan, parseOrRedirect} from "./utils.js";
 
 let appointment;
 const errorParagraph = document.getElementById('appointment-error');
@@ -23,7 +23,12 @@ window.addEventListener("load", async function () {
 async function getAppointment() {
     let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
 
-    const response = await fetch(`/api/schedule?appointmentId=${appointment}`, options)
+    const searchParams = new URLSearchParams({
+        appointmentId: appointment,
+
+    });
+
+    const response = await fetchRegular('/api/schedule?' + searchParams.toString(), options)
         .catch(err => console.error('error:' + err));
 
     const js = await parseOrRedirect(response);
@@ -65,7 +70,7 @@ async function attendEvent() {
         return;
     }
 
-    const response = await fetch("/api/schedule/create",
+    const response = await fetchRegular("/api/schedule/create",
         {
             method: 'POST',
             headers: {'Content-Type': 'application/json'},

+ 9 - 1
public/javascripts/utils.js

@@ -5,6 +5,14 @@ async function fetchWithToken(url, options) {
     return await fetch(url, {...options, headers: {
             'Authorization': `Bearer ${authToken}`,
             'Content-Type': 'application/json',
+            'Cache-Control': 'no-cache, no-store',
+        }});
+}
+
+async function fetchRegular(url, options) {
+    return await fetch(url, {...options, headers: {
+            'Content-Type': 'application/json',
+            'Cache-Control': 'no-cache, no-store',
         }});
 }
 
@@ -39,4 +47,4 @@ async function parseOrRedirect(response) {
     return js;
 }
 
-export { fetchWithToken, getTimeSpan, parseOrRedirect };
+export { fetchWithToken, getTimeSpan, parseOrRedirect, fetchRegular };