Add basic resource bar

This commit is contained in:
Aelita4 2023-12-25 16:23:57 +01:00
parent cfc7fef6c4
commit 0d4a187bed
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
4 changed files with 42 additions and 7 deletions

View File

@ -0,0 +1,32 @@
---
import { getHighestWeightedLanguage, getLocales } from '../lib/lang/langDriver';
interface Props {
loggedIn: string;
}
const lang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar');
// const { loggedIn } = Astro.props;
---
<div id="resourcebar">
<div>
<!-- <div style="width: 64px; height: 64px; background-color: red; margin: 10px; border-radius: 10px;"></div> -->
<div>coal</div>
</div>
</div>
<style>
/* #resourcebar {
color: pink;
background-color: blueviolet;
border-radius: 15px;
}
#resourcebar ul {
list-style: none;
display: flex;
flex-direction: row;
padding-left: 15px;
} */
</style>

View File

@ -4,6 +4,6 @@
},
"Link": {
"logout": "Log out",
"build": "Build {}"
"build": "[build]"
}
}

View File

@ -0,0 +1,7 @@
{
"Label": {
"avaliable": "Avaliable: {}",
"production": "Production: {}/h",
"capacity": "Storage capacity: {}"
}
}

View File

@ -3,6 +3,7 @@ import Layout from '../../layouts/Layout.astro';
import NavBar from '../../components/NavBar.astro';
import { getUserResources, updateUserResources } from '../../lib/db/users';
import { getHighestWeightedLanguage, getLocales } from '../../lib/lang/langDriver';
import ResourceBar from '../../components/ResourceBar.astro';
const loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
const username = Astro.cookies.get('username')?.value ?? "";
@ -11,17 +12,12 @@ if(loggedToken === null || username === "") return Astro.redirect('/');
const resources = await getUserResources(username);
await updateUserResources(username, {
coal: resources.coal * 2,
iron: resources.iron * 3,
gold: resources.gold * 4,
});
const langResources = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources');
---
<Layout title="chujów sto">
<NavBar loggedIn="true" active="overview" />
<ResourceBar loggedIn="true" />
<ul>
<li>{langResources['Label_coal']}: <span id="coal">{resources.coal * 2}</span></li>
<li>{langResources['Label_iron']}: <span id="iron">{resources.iron * 3}</span></li>