diff --git a/src/components/PlanetView.astro b/src/components/PlanetView.astro new file mode 100644 index 0000000..3eaffa1 --- /dev/null +++ b/src/components/PlanetView.astro @@ -0,0 +1,36 @@ +--- +import { ObjectId } from 'mongodb'; +import { getHighestWeightedLanguage, getLocales } from '../lib/utils/langDriver'; +import { getUserWithPlanets } from '../lib/db/users'; +import { createPlanet } from '../lib/db/planets'; + +// await createPlanet({ +// name: "BiałePodNapletem2", +// ownerId: new ObjectId(Astro.cookies.get('userid')?.value ?? ""), +// fields: 69 +// }) + +if(!Astro.cookies.get('userid')?.value) return; +const planets = (await getUserWithPlanets(new ObjectId(Astro.cookies.get('userid')?.value ?? "")))?.planets.data; +if(!planets) return; + +// console.log(planets); + +// const resourceLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); +// const resBarLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); + + +--- +
+ {planets.map(planet =>
+ {planet.name}
+

{planet.fields}

+
)} +
+ + \ No newline at end of file diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index e0616e8..e051905 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -1,6 +1,6 @@ --- import { ObjectId } from 'mongodb'; -import { calculateCurrentAvailableResources, getUserResources } from '../lib/utils/resourceManager'; +import { calculateCurrentAvailableResources } from '../lib/utils/resourceManager'; import { getHighestWeightedLanguage, getLocales } from '../lib/utils/langDriver'; import resourceTypes from '../lib/data/resources.json'; @@ -8,7 +8,7 @@ import resourceTypes from '../lib/data/resources.json'; const resourceLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); const resBarLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); -const resources = await calculateCurrentAvailableResources(new ObjectId(Astro.cookies.get('userid')?.value ?? '')); +const resources = await calculateCurrentAvailableResources(new ObjectId(Astro.cookies.get('planetid')?.value ?? '')); const resourceArray = []; for(const key in resources) { diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 7b552be..0018557 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,4 +1,6 @@ --- +import PlanetView from '../components/PlanetView.astro'; + interface Props { title: string; } @@ -18,6 +20,7 @@ const { title } = Astro.props; +