From ecb7bca9cde07d88d90dae3c4a978478cc63cbf6 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Mon, 19 Feb 2024 20:38:40 +0100 Subject: [PATCH] Fix resource bar not updating values in database on refresh --- src/components/ResourceBar.astro | 7 +++---- src/lib/utils/resourceManager.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index 64421b9..6da3895 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -1,15 +1,14 @@ --- import { ObjectId } from 'mongodb'; -import { getUserResources } from '../lib/utils/resourceManager'; +import { calculateCurrentAvailableResources, getUserResources } from '../lib/utils/resourceManager'; import { getHighestWeightedLanguage, getLocales } from '../lib/lang/langDriver'; import resourceTypes from '../lib/data/resources.json'; -import format from '../lib/utils/format'; const resourceLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); const resBarLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); -const resources = await getUserResources(new ObjectId(Astro.cookies.get('userid')?.value ?? '')); +const resources = await calculateCurrentAvailableResources(new ObjectId(Astro.cookies.get('userid')?.value ?? '')); const resourceArray = []; for(const key in resources) { @@ -33,7 +32,7 @@ for(const key in resources) {
{resourceLang[`Label_${res.name}`]}
-
{Math.floor(res.amount).toString()}
+
[fetching]
{resBarLang['Label_avaliable']} - {Math.floor(res.amount).toString()}
diff --git a/src/lib/utils/resourceManager.ts b/src/lib/utils/resourceManager.ts index a685e85..3ac8a05 100644 --- a/src/lib/utils/resourceManager.ts +++ b/src/lib/utils/resourceManager.ts @@ -82,7 +82,7 @@ export const updateUserResources = async (id: ObjectId, resources: Array> => { +export const calculateCurrentAvailableResources = async (id: ObjectId): Promise> => { const user = await getUserById(id); if(user === null) return [];