traxxx/assets/js/networks/actions.js

131 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-01-02 23:59:02 +00:00
import { graphql } from '../api';
// import { sitesFragment, releaseFields } from '../fragments';
import { releaseFields } from '../fragments';
2023-07-02 20:21:19 +00:00
import { curateEntity } from '../curate';
import getDateRange from '../get-date-range';
function initNetworksActions(store, _router) {
async function fetchNetworkBySlug({ _commit }, {
networkSlug,
limit = 10,
pageNumber = 1,
range = 'latest',
}) {
const { before, after, orderBy } = getDateRange(range);
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!
$limit:Int = 10,
$offset:Int = 0,
2020-01-02 23:59:02 +00:00
$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: entityBySlugAndType(slug: $networkSlug, type: "network") {
2020-01-02 23:59:02 +00:00
id
name
slug
url
sites: childEntities(
orderBy: [PRIORITY_DESC, NAME_ASC],
) {
2020-01-02 23:59:02 +00:00
id
name
slug
url
type
priority
}
parent {
id
name
slug
type
url
}
2020-01-02 23:59:02 +00:00
}
2020-05-26 02:11:29 +00:00
connection: releasesConnection(
first: $limit
offset: $offset
2020-05-26 02:11:29 +00:00
orderBy: $orderBy
filter: {
entity: {
2020-05-26 02:11:29 +00:00
or: [
{ parent: { slug: { equalTo: $networkSlug } } },
{ parent: { parent: { slug: { equalTo: $networkSlug } } } }
2020-05-26 02:11:29 +00:00
]
}
2023-07-02 20:21:19 +00:00
effectiveDate: {
lessThan: $before,
greaterThan: $after
}
2020-05-26 02:11:29 +00:00
releasesTagsConnection: {
none: {
tag: {
slug: {
in: $exclude
}
}
}
}
}
) {
releases: nodes {
${releaseFields}
}
totalCount
}
2020-01-02 23:59:02 +00:00
}
`, {
networkSlug,
limit,
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
orderBy,
afterTime: store.getters.after,
beforeTime: store.getters.before,
exclude: store.state.ui.filter,
});
2020-05-26 02:11:29 +00:00
return {
2023-07-02 20:21:19 +00:00
network: curateEntity(network, releases),
2020-05-26 02:11:29 +00:00
totalCount,
};
}
async function fetchNetworks({ _commit }) {
const { networks } = await graphql(`
2020-01-02 23:59:02 +00:00
query Networks {
networks: entities(
orderBy: NAME_ASC
filter: {
type: {
equalTo: "network"
}
}
) {
2020-01-02 23:59:02 +00:00
id
name
slug
type
2020-01-02 23:59:02 +00:00
url
}
}
`);
2023-07-02 20:21:19 +00:00
return networks.map((network) => curateEntity(network));
}
return {
fetchNetworkBySlug,
fetchNetworks,
};
}
export default initNetworksActions;