traxxx/assets/js/networks/actions.js

146 lines
4.6 KiB
JavaScript
Raw Normal View History

2020-01-02 23:59:02 +00:00
import { graphql } from '../api';
import { sitesFragment, releaseFields } from '../fragments';
2020-01-02 23:59:02 +00:00
import { curateNetwork } from '../curate';
function initNetworksActions(store, _router) {
2020-01-02 23:59:02 +00:00
async function fetchNetworkBySlug(networkSlug, limit = 100) {
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",
$afterTime:Datetime = "1900-01-01",
$beforeTime:Datetime = "2100-01-01",
$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
networks: childNetworks(
orderBy: NAME_ASC,
) {
id
name
slug
url
}
sites(
orderBy: [PRIORITY_DESC, NAME_ASC],
filter: {
show: {
equalTo: true,
},
},
) {
2020-01-02 23:59:02 +00:00
id
name
slug
url
independent
priority
network {
id
name
slug
url
}
2020-01-02 23:59:02 +00:00
}
studios {
id
name
slug
url
}
parent {
id
name
slug
url
}
2020-01-02 23:59:02 +00:00
}
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,
}
}
],
2020-01-30 22:41:10 +00:00
releasesTags: {
none: {
tag: {
slug: {
in: $exclude
}
}
}
}
}
) {
${releaseFields}
}
2020-01-02 23:59:02 +00:00
}
`, {
networkSlug,
limit,
after: store.getters.after,
before: store.getters.before,
afterTime: store.getters.after,
beforeTime: store.getters.before,
orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC',
2020-01-30 22:41:10 +00:00
exclude: store.state.ui.filter,
});
return curateNetwork(network, releases);
}
2020-01-02 23:59:02 +00:00
async function fetchNetworks({ _commit }, networkSlug) {
if (networkSlug) {
return fetchNetworkBySlug(networkSlug);
}
const { networks } = await graphql(`
query Networks {
networks(orderBy: NAME_ASC) {
2020-01-02 23:59:02 +00:00
id
name
slug
url
${sitesFragment}
}
}
`);
2020-01-02 23:59:02 +00:00
return networks.map(network => curateNetwork(network));
}
return {
fetchNetworks,
};
}
export default initNetworksActions;