Show planet owners in galaxy view

This commit is contained in:
Aelita4 2024-09-26 13:38:10 +02:00
parent 5711506579
commit 8271bdcee6
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,8 @@ import Layout from '../../layouts/Layout.astro';
import NavBar from '../../components/NavBar.astro';
import { getUserByAccessToken } from '../../lib/db/users';
import { getAllPlanets } from '../../lib/db/planets';
import locationManager from '../../lib/classes/managers/LocationManager';
import ResourceBar from '../../components/ResourceBar.astro';
const loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
const username = Astro.cookies.get('username')?.value ?? "";
@ -12,12 +14,20 @@ const checkUser = await getUserByAccessToken(loggedToken);
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
const allPlanets = await getAllPlanets();
const formattedPlanets = allPlanets.map(planet => {
return {
name: planet.name,
owner: locationManager.getUser(planet.owner)?.username ?? "Unowned"
};
})
---
<Layout title="Galaxy view">
<NavBar loggedIn="true" active="galaxyView" />
<ResourceBar />
<ul>
{allPlanets.map(planet => <li>{planet.name} ({planet.owner.username})</li>)}
{formattedPlanets.map(planet => <li>{planet.name} ({planet.owner})</li>)}
</ul>
</Layout>