Fix resource bar not updating values in database on refresh
This commit is contained in:
parent
ef50c8fed2
commit
ecb7bca9cd
|
@ -1,15 +1,14 @@
|
||||||
---
|
---
|
||||||
import { ObjectId } from 'mongodb';
|
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 { getHighestWeightedLanguage, getLocales } from '../lib/lang/langDriver';
|
||||||
|
|
||||||
import resourceTypes from '../lib/data/resources.json';
|
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 resourceLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources');
|
||||||
const resBarLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar');
|
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 = [];
|
const resourceArray = [];
|
||||||
for(const key in resources) {
|
for(const key in resources) {
|
||||||
|
@ -33,7 +32,7 @@ for(const key in resources) {
|
||||||
</div>
|
</div>
|
||||||
<div class="resourcebar-item-text-wrapper" data-resname={res.name}>
|
<div class="resourcebar-item-text-wrapper" data-resname={res.name}>
|
||||||
<div class="resourcebar-item-text">{resourceLang[`Label_${res.name}`]}</div>
|
<div class="resourcebar-item-text">{resourceLang[`Label_${res.name}`]}</div>
|
||||||
<div class="resourcebar-item-amount">{Math.floor(res.amount).toString()}</div>
|
<div class="resourcebar-item-amount">[fetching]</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="resourcebar-item-tooltip">
|
<div class="resourcebar-item-tooltip">
|
||||||
<div class="resourcebar-item-tooltip-name">{resBarLang['Label_avaliable']} - <span class="resourcebar-item-tooltip-avaliable">{Math.floor(res.amount).toString()}</span></div>
|
<div class="resourcebar-item-tooltip-name">{resBarLang['Label_avaliable']} - <span class="resourcebar-item-tooltip-avaliable">{Math.floor(res.amount).toString()}</span></div>
|
||||||
|
|
|
@ -82,7 +82,7 @@ export const updateUserResources = async (id: ObjectId, resources: Array<DBResou
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calculateCurrentAvailableResources = async (id: ObjectId): Promise<Array<Resource>> => {
|
export const calculateCurrentAvailableResources = async (id: ObjectId): Promise<Array<DBResource>> => {
|
||||||
const user = await getUserById(id);
|
const user = await getUserById(id);
|
||||||
|
|
||||||
if(user === null) return [];
|
if(user === null) return [];
|
||||||
|
|
Loading…
Reference in New Issue