Add continents to the game

This commit is contained in:
2019-12-29 19:14:24 +01:00
parent c99ae42690
commit 10a98539fe
2 changed files with 33 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
<script context="module"> <script context="module">
import { api, site, countries, locations, currentLocation } from '../store' import { api, site, continents, countries, locations, currentLocation } from '../store'
export async function preload (page, segment) { export async function preload (page, segment) {
const res = await this.fetch(api.graphql, { const res = await this.fetch(api.graphql, {
@@ -14,19 +14,38 @@
instagram instagram
} }
} }
continents {
data {
id
name
}
}
countries { countries {
data { data {
id
name name
slug slug
flag { metadata } continent { id name }
flag {
full_url
title
}
} }
} }
locations (filter: { status_eq: "published" }) { locations (filter: { status_eq: "published" }) {
data { data {
id
name name
slug slug
region region
country { name slug } country {
name slug
flag {
full_url
title
}
continent { id name }
}
description description
} }
} }
@@ -35,6 +54,7 @@
const data = await res.json() const data = await res.json()
// Set data into store // Set data into store
continents.set(data.data.continents.data)
countries.set(data.data.countries.data) countries.set(data.data.countries.data)
locations.set(data.data.locations.data) locations.set(data.data.locations.data)
site.set(data.data.site.data[0]) site.set(data.data.site.data[0])
@@ -48,6 +68,15 @@
// Components // Components
import Footer from '../parts/Footer.svelte' import Footer from '../parts/Footer.svelte'
// Manipulate continents data
$countries.forEach(country => {
const continent = $continents.find(c => c.id === country.continent.id)
continent.countries = []
if (!continent.countries.includes(country)) {
continent.countries.push(country)
}
})
</script> </script>
<svelte:head> <svelte:head>

View File

@@ -14,5 +14,6 @@ export let loaded = writable(false)
// Data // Data
export let site = writable() export let site = writable()
export let continents = writable()
export let countries = writable() export let countries = writable()
export let locations = writable() export let locations = writable()