Return destructured data only if existing on layout

This commit is contained in:
2022-06-14 11:58:54 +02:00
parent 6873ad6a66
commit 2831600f57

View File

@@ -47,6 +47,7 @@
}) })
</script> </script>
<Switcher isOver={!!$page.params.location && !!$page.params.photo} /> <Switcher isOver={!!$page.params.location && !!$page.params.photo} />
<slot /> <slot />
@@ -61,6 +62,7 @@
<SVGSprite /> <SVGSprite />
<script context="module" lang="ts"> <script context="module" lang="ts">
import type { LoadEvent, LoadOutput } from '@sveltejs/kit' import type { LoadEvent, LoadOutput } from '@sveltejs/kit'
import { fetchAPI } from '$utils/api' import { fetchAPI } from '$utils/api'
@@ -149,21 +151,27 @@
} }
`) `)
const { data } = res if (res) {
const filteredContinents = data.continents.filter((cont: any) => cont.countries.length) const { data } = res
const filteredContinents = data.continents.filter((cont: any) => cont.countries.length)
return {
props: {
data: {
...data,
continents: filteredContinents,
},
count: {
photos: data.countPhotos[0].count.id,
locations: data.countLocations[0].count.id,
countries: data.countCountries[0].count.id,
},
},
}
}
return { return {
props: { status: 500,
data: {
...data,
continents: filteredContinents,
},
count: {
photos: data.countPhotos[0].count.id,
locations: data.countLocations[0].count.id,
countries: data.countCountries[0].count.id,
},
},
} }
} }
</script> </script>