2020-01-02 23:59:02 +00:00
|
|
|
import { graphql } from '../api';
|
2020-01-08 23:23:37 +00:00
|
|
|
import { sitesFragment, releaseFields } from '../fragments';
|
2020-01-02 23:59:02 +00:00
|
|
|
import { curateNetwork } from '../curate';
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2019-11-15 01:37:17 +00:00
|
|
|
function initNetworksActions(store, _router) {
|
2020-01-02 23:59:02 +00:00
|
|
|
async function fetchNetworkBySlug(networkSlug, limit = 100) {
|
2020-01-08 23:23:37 +00:00
|
|
|
const { network, releases } = await graphql(`
|
2020-01-02 23:59:02 +00:00
|
|
|
query Network(
|
|
|
|
$networkSlug: String!
|
|
|
|
$limit:Int = 1000,
|
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
2020-01-08 23:23:37 +00:00
|
|
|
$orderBy: [ReleasesOrderBy!]
|
2020-01-30 22:41:10 +00:00
|
|
|
$exclude: [String!]
|
2020-01-02 23:59:02 +00:00
|
|
|
) {
|
|
|
|
network: networkBySlug(slug: $networkSlug) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-02-02 04:14:58 +00:00
|
|
|
sites(
|
|
|
|
orderBy: PRIORITY_DESC
|
|
|
|
) {
|
2020-01-02 23:59:02 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-01-08 23:23:37 +00:00
|
|
|
independent
|
2020-02-02 04:14:58 +00:00
|
|
|
priority
|
2020-01-08 23:23:37 +00:00
|
|
|
network {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
2020-01-02 23:59:02 +00:00
|
|
|
}
|
2020-01-06 04:19:38 +00:00
|
|
|
studios {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
2020-01-02 23:59:02 +00:00
|
|
|
}
|
2020-01-08 23:23:37 +00:00
|
|
|
releases(
|
|
|
|
first: $limit,
|
|
|
|
orderBy: $orderBy,
|
|
|
|
filter: {
|
|
|
|
site: { network: { slug: { equalTo: $networkSlug } } }
|
|
|
|
date: {
|
|
|
|
lessThan: $before,
|
|
|
|
greaterThan: $after,
|
|
|
|
}
|
2020-01-30 22:41:10 +00:00
|
|
|
releasesTags: {
|
|
|
|
none: {
|
|
|
|
tag: {
|
|
|
|
slug: {
|
|
|
|
in: $exclude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-08 23:23:37 +00:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
2020-01-02 23:59:02 +00:00
|
|
|
}
|
|
|
|
`, {
|
|
|
|
networkSlug,
|
|
|
|
limit,
|
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
2020-01-08 23:23:37 +00:00
|
|
|
orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC',
|
2020-01-30 22:41:10 +00:00
|
|
|
exclude: store.state.ui.filter,
|
2019-11-15 01:37:17 +00:00
|
|
|
});
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-01-08 23:23:37 +00:00
|
|
|
return curateNetwork(network, releases);
|
2019-11-10 03:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
async function fetchNetworks({ _commit }, networkSlug) {
|
|
|
|
if (networkSlug) {
|
|
|
|
return fetchNetworkBySlug(networkSlug);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { networks } = await graphql(`
|
|
|
|
query Networks {
|
2020-01-06 20:49:37 +00:00
|
|
|
networks(orderBy: NAME_ASC) {
|
2020-01-02 23:59:02 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
${sitesFragment}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
return networks.map(network => curateNetwork(network));
|
2019-11-10 03:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetchNetworks,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initNetworksActions;
|