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