Skip to content

Commit

Permalink
add(collection activity.): loading skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
hassnian committed Oct 2, 2024
1 parent 9dd5171 commit 8a0cc9d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
18 changes: 13 additions & 5 deletions components/collection/activity/Activity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<div class="w-2/3 pr-2">
<ActivityChart
:events="events"
class="mt-2"
:loading="loading"
:class="{ 'mt-2': !loading }"
/>
</div>
<div class="flex-1">
Expand All @@ -29,15 +30,21 @@
:flippers="flippers"
/>
<div class="max-width">
<ActivityChart :events="events" />
<ActivityChart
:events="events"
:loading="loading"
/>
</div>
</div>
</div>
<hr
class="mb-7"
:class="{ 'my-7': !isBreadCrumbsShowing }"
>
<Events :events="sortedEventsWithOffersDesc" />
<Events
:events="sortedEventsWithOffersDesc"
:loading="loading"
/>
</div>
</div>
</template>
Expand All @@ -63,8 +70,9 @@ const isBreadCrumbsShowing = computed(
() => isAnyActivityFilterActive() && tablet.value,
)
const collectionId = computed(() => route.params.id)
const { events, flippers, owners, offers } = useCollectionActivity({
const collectionId = computed(() => route.params.id.toString())
const { events, flippers, owners, offers, loading } = useCollectionActivity({
collectionId,
})
Expand Down
11 changes: 11 additions & 0 deletions components/collection/activity/ActivityChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
chart-height="350px"
data-testid="collection-activity-chart"
/>
<div
v-else-if="loading"
class="relative h-[350px]"
>
<SkeletonLoader
:title="$t('activity.generatingChart')"
class="absolute"
/>
</div>
</template>

<script setup lang="ts">
Expand All @@ -29,9 +38,11 @@ const { decimals } = useChain()
const props = withDefaults(
defineProps<{
events: ActivityInteraction[]
loading?: boolean
}>(),
{
events: () => [],
loading: false,
},
)
const hideOutliers = ref(true)
Expand Down
3 changes: 3 additions & 0 deletions components/collection/activity/events/Events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:no-results-main="$t('activity.noResults')"
:no-results-sub="$t('activity.noResultsSub')"
:show-no-results="events.length > 0 && !displayedEvents.length"
:loading="loading"
data-testid="nfts-event-table"
>
<template #columns>
Expand Down Expand Up @@ -62,9 +63,11 @@ import { toSubstrateAddress } from '@/services/profile'
const props = withDefaults(
defineProps<{
events: (InteractionWithNFT | Offer)[]
loading: boolean
}>(),
{
events: () => [],
loading: false,
},
)
Expand Down
17 changes: 8 additions & 9 deletions composables/collectionActivity/useCollectionActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ export const useCollectionActivity = ({
id: collectionId.value,
}))

const { data: queryData, isLoading: loading } = useQuery({
const { data, isPending: loading } = useQuery({
queryKey: ['collection-activity-events', prefix, variables],
queryFn: () =>
queryFn: async () =>
collectionId.value
? useGraphql({
queryPrefix,
queryName: 'collectionActivityEvents',
variables: variables.value,
clientName: prefix,
})
? (await useAsyncGraphql({
query: 'collectionActivityEvents',
variables: variables.value,
prefix: queryPrefix,
})).data.value
: null,
staleTime: 1000 * 10,
})

watch(
computed(() => queryData.value?.data),
data,
(result) => {
if (result) {
const nfts
Expand Down
9 changes: 6 additions & 3 deletions composables/useAsyncGraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ type AyncQueryParams = {
query: string
variables: Record<string, unknown>
clientId?: string
prefix?: string
}

export default async function ({ query, clientId, variables }: AyncQueryParams) {
export default async function ({ query, variables, clientId, prefix }: AyncQueryParams) {
const { urlPrefix, client } = usePrefix()

return useAsyncQuery({
query: (await resolveQueryPath(clientId || usePrefix().client.value, query)).default,
query: (await resolveQueryPath(prefix || urlPrefix.value, query)).default,
variables: variables,
clientId: clientId,
clientId: clientId || client.value,
})
}
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"floorPrice": "FLOOR PRICE",
"followers": "Followers",
"following": "Following",
"generatingChart": "Generating Chart",
"hideOutliers": "Hide Outliers",
"highestSale": "HIGHEST SALE",
"items": "Items",
Expand Down

0 comments on commit 8a0cc9d

Please sign in to comment.