import { graphql } from '../api'; import { sitesFragment, releaseFields } from '../fragments'; import { curateNetwork } from '../curate'; import getDateRange from '../get-date-range'; function initNetworksActions(store, _router) { async function fetchNetworkBySlug({ _commit }, { networkSlug, limit = 100, range = 'latest' }) { const { before, after, orderBy } = getDateRange(range); const { network, releases } = await graphql(` query Network( $networkSlug: String! $limit:Int = 1000, $after:Date = "1900-01-01", $before:Date = "2100-01-01", $afterTime:Datetime = "1900-01-01", $beforeTime:Datetime = "2100-01-01", $orderBy: [ReleasesOrderBy!] $exclude: [String!] ) { network: networkBySlug(slug: $networkSlug) { id name slug url networks: childNetworks( orderBy: NAME_ASC, ) { id name slug url } sites( orderBy: [PRIORITY_DESC, NAME_ASC], filter: { show: { equalTo: true, }, }, ) { id name slug url independent priority network { id name slug url } } studios { id name slug url } parent { id name slug url } } releases( first: $limit, orderBy: $orderBy, filter: { site: { or: [ { network: { slug: { equalTo: $networkSlug } } }, { network: { parent: { slug: { equalTo: $networkSlug } } } } ] } or: [ { date: { lessThan: $before, greaterThan: $after } }, { date: { isNull: true }, createdAt: { lessThan: $beforeTime, greaterThan: $afterTime, } } ] releasesTags: { none: { tag: { slug: { in: $exclude } } } } } ) { ${releaseFields} } } `, { networkSlug, limit, after, before, orderBy, afterTime: store.getters.after, beforeTime: store.getters.before, exclude: store.state.ui.filter, }); return curateNetwork(network, releases); } async function fetchNetworks({ _commit }) { const { networks } = await graphql(` query Networks { networks(orderBy: NAME_ASC) { id name slug url ${sitesFragment} } } `); return networks.map(network => curateNetwork(network)); } return { fetchNetworkBySlug, fetchNetworks, }; } export default initNetworksActions;