Show planet owners in galaxy view
This commit is contained in:
parent
5711506579
commit
8271bdcee6
|
@ -3,6 +3,8 @@ import Layout from '../../layouts/Layout.astro';
|
||||||
import NavBar from '../../components/NavBar.astro';
|
import NavBar from '../../components/NavBar.astro';
|
||||||
import { getUserByAccessToken } from '../../lib/db/users';
|
import { getUserByAccessToken } from '../../lib/db/users';
|
||||||
import { getAllPlanets } from '../../lib/db/planets';
|
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 loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
|
||||||
const username = Astro.cookies.get('username')?.value ?? "";
|
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');
|
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
||||||
|
|
||||||
const allPlanets = await getAllPlanets();
|
const allPlanets = await getAllPlanets();
|
||||||
|
|
||||||
|
const formattedPlanets = allPlanets.map(planet => {
|
||||||
|
return {
|
||||||
|
name: planet.name,
|
||||||
|
owner: locationManager.getUser(planet.owner)?.username ?? "Unowned"
|
||||||
|
};
|
||||||
|
})
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Galaxy view">
|
<Layout title="Galaxy view">
|
||||||
<NavBar loggedIn="true" active="galaxyView" />
|
<NavBar loggedIn="true" active="galaxyView" />
|
||||||
|
<ResourceBar />
|
||||||
<ul>
|
<ul>
|
||||||
{allPlanets.map(planet => <li>{planet.name} ({planet.owner.username})</li>)}
|
{formattedPlanets.map(planet => <li>{planet.name} ({planet.owner})</li>)}
|
||||||
</ul>
|
</ul>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue