From 9da63baf6556023e13cb575b218e932a04ac8e6b Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Thu, 9 Jan 2020 00:23:37 +0100 Subject: [PATCH] Modified network releases query to accomodate date sorting. Showing upcoming releases first to last. --- assets/components/networks/network.vue | 2 +- assets/js/actors/actions.js | 4 +- assets/js/curate.js | 12 ++--- assets/js/fragments.js | 37 +++++++------ assets/js/networks/actions.js | 36 +++++++++---- assets/js/releases/actions.js | 2 + assets/js/sites/actions.js | 4 +- assets/js/tags/actions.js | 72 ++++++++++++++++---------- 8 files changed, 102 insertions(+), 67 deletions(-) diff --git a/assets/components/networks/network.vue b/assets/components/networks/network.vue index bdbea8b6..308c1322 100644 --- a/assets/components/networks/network.vue +++ b/assets/components/networks/network.vue @@ -89,7 +89,7 @@ async function fetchNetwork() { // .concat(this.studios) .sort(({ name: nameA }, { name: nameB }) => nameA.localeCompare(nameB)); - this.releases = this.network.sites.map(site => site.releases).flat(); + this.releases = this.network.releases; } async function mounted() { diff --git a/assets/js/actors/actions.js b/assets/js/actors/actions.js index a9778a3e..bb05a554 100644 --- a/assets/js/actors/actions.js +++ b/assets/js/actors/actions.js @@ -52,6 +52,7 @@ function initActorActions(store, _router) { $limit:Int = 1000, $after:Date = "1900-01-01", $before:Date = "2100-01-01", + $orderBy:[ReleasesActorsOrderBy!] ) { actor: actorBySlug(slug: $actorSlug) { id @@ -120,7 +121,7 @@ function initActorActions(store, _router) { } }, first: $limit, - orderBy: RELEASE_BY_RELEASE_ID__DATE_DESC, + orderBy: $orderBy ) { release { id @@ -151,6 +152,7 @@ function initActorActions(store, _router) { limit, after: store.getters.after, before: store.getters.before, + orderBy: store.state.ui.range === 'upcoming' ? 'RELEASE_BY_RELEASE_ID__DATE_ASC' : 'RELEASE_BY_RELEASE_ID__DATE_DESC', }); return curateActor(actor); diff --git a/assets/js/curate.js b/assets/js/curate.js index dd7b9864..5087d6bd 100644 --- a/assets/js/curate.js +++ b/assets/js/curate.js @@ -48,7 +48,7 @@ function curateSite(site, network) { return curatedSite; } -function curateNetwork(network) { +function curateNetwork(network, releases) { const curatedNetwork = { id: network.id, name: network.name, @@ -56,13 +56,9 @@ function curateNetwork(network) { url: network.url, }; - if (network.sites) { - curatedNetwork.sites = network.sites.map(site => curateSite(site, curatedNetwork)); - } - - if (network.studios) { - curatedNetwork.studios = network.studios; - } + if (network.sites) curatedNetwork.sites = network.sites.map(site => curateSite(site, curatedNetwork)); + if (network.studios) curatedNetwork.studios = network.studios; + if (releases) curatedNetwork.releases = releases.map(release => curateRelease(release)); return curatedNetwork; } diff --git a/assets/js/fragments.js b/assets/js/fragments.js index 24ec159e..5c0428cb 100644 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -95,6 +95,24 @@ const releaseTrailerFragment = ` } `; +const releaseFields = ` + id + title + date + createdAt + url + ${releaseActorsFragment} + ${releaseTagsFragment} + ${releasePosterFragment} + ${siteFragment} + studio { + id + name + slug + url + } +`; + const releasesFragment = ` releases( filter: { @@ -104,23 +122,9 @@ const releasesFragment = ` } }, first: $limit, - orderBy: DATE_DESC, + orderBy: $orderBy, ) { - id - title - date - createdAt - url - ${releaseActorsFragment} - ${releaseTagsFragment} - ${releasePosterFragment} - ${siteFragment} - studio { - id - name - slug - url - } + ${releaseFields} } `; @@ -151,6 +155,7 @@ const releaseFragment = ` export { releaseActorsFragment, + releaseFields, releaseTagsFragment, releasePosterFragment, releasePhotosFragment, diff --git a/assets/js/networks/actions.js b/assets/js/networks/actions.js index b83ad0eb..636ffa24 100644 --- a/assets/js/networks/actions.js +++ b/assets/js/networks/actions.js @@ -1,15 +1,16 @@ import { graphql } from '../api'; -import { sitesFragment, releasesFragment } from '../fragments'; +import { sitesFragment, releaseFields } from '../fragments'; import { curateNetwork } from '../curate'; function initNetworksActions(store, _router) { async function fetchNetworkBySlug(networkSlug, limit = 100) { - const { network } = await graphql(` + const { network, releases } = await graphql(` query Network( $networkSlug: String! $limit:Int = 1000, $after:Date = "1900-01-01", $before:Date = "2100-01-01", + $orderBy: [ReleasesOrderBy!] ) { network: networkBySlug(slug: $networkSlug) { id @@ -17,18 +18,17 @@ function initNetworksActions(store, _router) { slug url sites { - id - name - slug - url - independent - ${releasesFragment} - network { id name slug url - } + independent + network { + id + name + slug + url + } } studios { id @@ -37,15 +37,29 @@ function initNetworksActions(store, _router) { url } } + releases( + first: $limit, + orderBy: $orderBy, + filter: { + site: { network: { slug: { equalTo: $networkSlug } } } + date: { + lessThan: $before, + greaterThan: $after, + } + } + ) { + ${releaseFields} + } } `, { networkSlug, limit, after: store.getters.after, before: store.getters.before, + orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC', }); - return curateNetwork(network); + return curateNetwork(network, releases); } async function fetchNetworks({ _commit }, networkSlug) { diff --git a/assets/js/releases/actions.js b/assets/js/releases/actions.js index f5a1d484..2c78571a 100644 --- a/assets/js/releases/actions.js +++ b/assets/js/releases/actions.js @@ -11,6 +11,7 @@ function initReleasesActions(store, _router) { $limit:Int = 1000, $after:Date = "1900-01-01", $before:Date = "2100-01-01", + $orderBy:[ReleasesOrderBy!] ) { ${releasesFragment} } @@ -18,6 +19,7 @@ function initReleasesActions(store, _router) { limit, after: store.getters.after, before: store.getters.before, + orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC', }); return releases.map(release => curateRelease(release)); diff --git a/assets/js/sites/actions.js b/assets/js/sites/actions.js index 660d7f82..8be2bae1 100644 --- a/assets/js/sites/actions.js +++ b/assets/js/sites/actions.js @@ -10,6 +10,7 @@ function initSitesActions(store, _router) { $limit:Int = 100, $after:Date = "1900-01-01", $before:Date = "2100-01-01", + $orderBy:[ReleasesOrderBy!] ) { site: siteBySlug(slug: $siteSlug) { name @@ -29,10 +30,9 @@ function initSitesActions(store, _router) { limit, after: store.getters.after, before: store.getters.before, + orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC', }); - console.log(site); - return curateSite(site); } diff --git a/assets/js/tags/actions.js b/assets/js/tags/actions.js index cae5cd0f..5a060daf 100644 --- a/assets/js/tags/actions.js +++ b/assets/js/tags/actions.js @@ -1,16 +1,19 @@ import { graphql, get } from '../api'; import { - releasePosterFragment, - releaseActorsFragment, - releaseTagsFragment, - siteFragment, + releaseFields, } from '../fragments'; import { curateTag } from '../curate'; function initTagsActions(store, _router) { - async function fetchTagBySlug(tagSlug) { + async function fetchTagBySlug(tagSlug, limit = 100) { const { tagBySlug } = await graphql(` - query Tag($tagSlug:String!) { + query Tag( + $tagSlug:String! + $limit:Int = 1000, + $after:Date = "1900-01-01", + $before:Date = "2100-01-01", + $orderBy: [ReleasesTagsOrderBy!] + ) { tagBySlug(slug:$tagSlug) { id name @@ -36,23 +39,30 @@ function initTagsActions(store, _router) { comment } } - releases: releasesTags { + releases: releasesTags( + filter: { + release: { + date: { + lessThan: $before, + greaterThan: $after, + } + } + }, + first: $limit, + orderBy: $orderBy, + ) { release { - id - title - date - createdAt - url - ${releaseActorsFragment} - ${releaseTagsFragment} - ${releasePosterFragment} - ${siteFragment} + ${releaseFields} } } } } `, { tagSlug, + limit, + after: store.getters.after, + before: store.getters.before, + orderBy: store.state.ui.range === 'upcoming' ? 'RELEASE_BY_RELEASE_ID__DATE_ASC' : 'RELEASE_BY_RELEASE_ID__DATE_DESC', }); return curateTag(tagBySlug); @@ -70,21 +80,27 @@ function initTagsActions(store, _router) { } const { tags } = await graphql(` - query Tags($slugs: [String!] = [], $limit: Int = 100) { - tags(filter: {slug: {in: $slugs}}, first: $limit) { - id - name - slug - poster: tagsPosterByTagId { - media { - thumbnail - } - } - group { + query Tags( + $slugs: [String!] = [], + $limit: Int = 100 + ) { + tags( + filter: { slug: { in: $slugs } }, + first: $limit + ) { + id name slug + poster: tagsPosterByTagId { + media { + thumbnail + } + } + group { + name + slug + } } - } } `, { slugs,