Use aggregated data from Directus to count photos on Location page
This commit is contained in:
@@ -210,6 +210,7 @@
|
||||
},
|
||||
limit: ${import.meta.env.VITE_LIST_AMOUNT},
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
description
|
||||
@@ -243,24 +244,21 @@
|
||||
date_created
|
||||
}
|
||||
|
||||
total_published: photo (
|
||||
filter: {
|
||||
status: { _eq: "published" },
|
||||
location: { slug: { _eq: "${location}" }}
|
||||
}
|
||||
) {
|
||||
id
|
||||
total_published: photo_aggregated (groupBy: "location") {
|
||||
group
|
||||
count { id }
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
const { data } = res
|
||||
const locationPhotosCount = data.total_published.find(({ group }: any) => group.id === data.location.id)
|
||||
|
||||
return {
|
||||
props: {
|
||||
data: data.location[0],
|
||||
photos: data.photos,
|
||||
totalPhotos: data.total_published.length,
|
||||
totalPhotos: locationPhotosCount.count.id,
|
||||
lastUpdated: data.photos[0].date_created,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user