From 63aa8e2aa8d0b3051c17892d45d854c023a39016 Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:14:19 +0100 Subject: [PATCH] Add NEXT_PUBLIC_BUILD_TIME to config and append timestamp to API requests for fresh category data retrieval --- frontend/next.config.mjs | 4 ++++ frontend/src/app/scripts/page.tsx | 16 +++++++++------- frontend/src/components/CommandMenu.tsx | 24 +++++++++++++----------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index 805af40a..fcb7365f 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -14,6 +14,10 @@ const nextConfig = { ], }, + env: { + NEXT_PUBLIC_BUILD_TIME: Date.now(), + }, + output: "export", basePath: "/ProxmoxVE", }; diff --git a/frontend/src/app/scripts/page.tsx b/frontend/src/app/scripts/page.tsx index 58f37be2..23143b1c 100644 --- a/frontend/src/app/scripts/page.tsx +++ b/frontend/src/app/scripts/page.tsx @@ -47,13 +47,15 @@ function ScriptContent() { }; useEffect(() => { - fetch("api/categories") - .then((response) => response.json()) - .then((categories) => { - const sortedCategories = sortCategories(categories); - setLinks(sortedCategories); - }) - .catch((error) => console.error(error)); + fetch( + `/api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`, + ) + .then((response) => response.json()) + .then((categories) => { + const sortedCategories = sortCategories(categories); + setLinks(sortedCategories); + }) + .catch((error) => console.error(error)); }, []); return ( diff --git a/frontend/src/components/CommandMenu.tsx b/frontend/src/components/CommandMenu.tsx index f7ad7dfa..e830b2ba 100644 --- a/frontend/src/components/CommandMenu.tsx +++ b/frontend/src/components/CommandMenu.tsx @@ -52,17 +52,19 @@ export default function CommandMenu() { const fetchCategories = async () => { setIsLoading(true); - fetch("api/categories") - .then((response) => response.json()) - .then((categories) => { - const sortedCategories = sortCategories(categories); - setLinks(sortedCategories); - setIsLoading(false); - }) - .catch((error) => { - setIsLoading(false); - console.error(error) - }); + fetch( + `/api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`, + ) + .then((response) => response.json()) + .then((categories) => { + const sortedCategories = sortCategories(categories); + setLinks(sortedCategories); + setIsLoading(false); + }) + .catch((error) => { + setIsLoading(false); + console.error(error); + }); }; return (