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';
|
2020-05-08 23:10:07 +00:00
|
|
|
import getDateRange from '../get-date-range';
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2019-11-15 01:37:17 +00:00
|
|
|
function initNetworksActions(store, _router) {
|
2020-05-24 01:54:29 +00:00
|
|
|
async function fetchNetworkBySlug({ _commit }, {
|
|
|
|
networkSlug,
|
|
|
|
limit = 10,
|
|
|
|
pageNumber = 1,
|
|
|
|
range = 'latest',
|
|
|
|
}) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const { before, after, orderBy } = getDateRange(range);
|
2020-05-08 23:10:07 +00:00
|
|
|
|
2020-05-26 02:11:29 +00:00
|
|
|
const { network, connection: { releases, totalCount } } = await graphql(`
|
2020-01-02 23:59:02 +00:00
|
|
|
query Network(
|
|
|
|
$networkSlug: String!
|
2020-05-24 01:54:29 +00:00
|
|
|
$limit:Int = 10,
|
|
|
|
$offset:Int = 0,
|
2020-01-02 23:59:02 +00:00
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
2020-02-21 02:51:57 +00:00
|
|
|
$afterTime:Datetime = "1900-01-01",
|
|
|
|
$beforeTime:Datetime = "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-20 01:35:23 +00:00
|
|
|
networks: childNetworks(
|
|
|
|
orderBy: NAME_ASC,
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
2020-02-02 04:14:58 +00:00
|
|
|
sites(
|
2020-02-03 23:18:53 +00:00
|
|
|
orderBy: [PRIORITY_DESC, NAME_ASC],
|
2020-02-03 01:57:53 +00:00
|
|
|
filter: {
|
2020-02-07 02:40:11 +00:00
|
|
|
show: {
|
2020-02-03 01:57:53 +00:00
|
|
|
equalTo: true,
|
|
|
|
},
|
|
|
|
},
|
2020-02-02 04:14:58 +00:00
|
|
|
) {
|
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-02-20 01:35:23 +00:00
|
|
|
parent {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
2020-01-02 23:59:02 +00:00
|
|
|
}
|
2020-05-26 02:11:29 +00:00
|
|
|
connection: releasesConnection(
|
|
|
|
first: $limit
|
2020-05-24 01:54:29 +00:00
|
|
|
offset: $offset
|
2020-05-26 02:11:29 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
releasesTagsConnection: {
|
|
|
|
none: {
|
|
|
|
tag: {
|
|
|
|
slug: {
|
|
|
|
in: $exclude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
releases: nodes {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
totalCount
|
|
|
|
}
|
2020-01-02 23:59:02 +00:00
|
|
|
}
|
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
networkSlug,
|
|
|
|
limit,
|
2020-05-24 01:54:29 +00:00
|
|
|
offset: Math.max(0, (pageNumber - 1)) * limit,
|
2020-05-14 02:26:05 +00:00
|
|
|
after,
|
|
|
|
before,
|
|
|
|
orderBy,
|
|
|
|
afterTime: store.getters.after,
|
|
|
|
beforeTime: store.getters.before,
|
|
|
|
exclude: store.state.ui.filter,
|
|
|
|
});
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-05-26 02:11:29 +00:00
|
|
|
return {
|
|
|
|
network: curateNetwork(network, releases),
|
|
|
|
totalCount,
|
|
|
|
};
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
async function fetchNetworks({ _commit }) {
|
|
|
|
const { networks } = await graphql(`
|
2020-01-02 23:59:02 +00:00
|
|
|
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-05-14 02:26:05 +00:00
|
|
|
return networks.map(network => curateNetwork(network));
|
|
|
|
}
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return {
|
|
|
|
fetchNetworkBySlug,
|
|
|
|
fetchNetworks,
|
|
|
|
};
|
2019-11-10 03:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default initNetworksActions;
|