Skip to content

Commit

Permalink
Merge pull request #46 from TechLabs-Berlin/develop
Browse files Browse the repository at this point in the history
Fixes on async fetching
  • Loading branch information
danrocha authored Mar 18, 2021
2 parents 6848adf + d96fa77 commit fa0bc8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
20 changes: 13 additions & 7 deletions pages/event/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
><TIcon icon="chevron-left" class="inline-block" /> Back to the
Timeline</NuxtLink
>
<EventListItem :tl-event="event[0]" show-resources />
<WrapperContentBox v-if="$fetchState.pending"
>Loading...</WrapperContentBox
>
<EventListItem v-else :tl-event="event[0]" show-resources />
</div>
</main>
</template>
Expand All @@ -14,19 +17,22 @@
import {
defineComponent,
useContext,
useAsync,
useFetch,
useRoute,
ref,
} from '@nuxtjs/composition-api'
export default defineComponent({
setup() {
const { $content } = useContext()
const route = useRoute()
const event = useAsync(() =>
$content('/events')
.where({ slug: route.value.params.slug })
.limit(1)
.fetch()
const event = ref('')
useFetch(
async () =>
(event.value = await $content('/events')
.where({ slug: route.value.params.slug })
.limit(1)
.fetch())
)
return {
Expand Down
24 changes: 17 additions & 7 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<main class="h-full bg-gray-50">
<div class="w-full main-grid">
<div v-if="!$fetchState.pending" class="w-full main-grid">
<div class="w-64 mx-auto timeline">
<h3 class="md:hidden title-with-lines">Timeline</h3>
<Timeline
Expand Down Expand Up @@ -28,15 +28,25 @@
</template>

<script>
import { useAsync, defineComponent, useContext } from '@nuxtjs/composition-api'
import {
useFetch,
defineComponent,
useContext,
ref,
} from '@nuxtjs/composition-api'
export default defineComponent({
setup() {
const { $content } = useContext()
const events = useAsync(() => $content('/events').sortBy('date').fetch())
const timeline = useAsync(() => $content('timeline').fetch())
const milestones = useAsync(() =>
$content('/milestones').sortBy('deadline').fetch()
)
const events = ref()
const timeline = ref()
const milestones = ref()
useFetch(async () => {
events.value = await $content('/events').sortBy('date').fetch()
timeline.value = await $content('timeline').fetch()
milestones.value = await $content('/milestones')
.sortBy('deadline')
.fetch()
})
return {
events,
Expand Down

0 comments on commit fa0bc8b

Please sign in to comment.