2020-01-04 01:51:58 +00:00
|
|
|
import { graphql } from '../api';
|
2020-05-24 01:54:29 +00:00
|
|
|
import { releaseFields } from '../fragments';
|
2020-05-26 23:40:10 +00:00
|
|
|
import { curateSite, curateRelease } from '../curate';
|
2020-05-08 23:10:07 +00:00
|
|
|
import getDateRange from '../get-date-range';
|
2019-11-11 02:20:00 +00:00
|
|
|
|
2019-11-15 04:10:59 +00:00
|
|
|
function initSitesActions(store, _router) {
|
2020-05-24 01:54:29 +00:00
|
|
|
async function fetchSiteBySlug({ _commit }, {
|
|
|
|
siteSlug,
|
|
|
|
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 23:40:10 +00:00
|
|
|
const { site, connection: { releases, totalCount } } = await graphql(`
|
2020-01-04 01:51:58 +00:00
|
|
|
query Site(
|
|
|
|
$siteSlug: String!,
|
|
|
|
$limit:Int = 100,
|
2020-05-24 01:54:29 +00:00
|
|
|
$offset:Int = 0,
|
2020-01-04 01:51:58 +00:00
|
|
|
$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-04 01:51:58 +00:00
|
|
|
) {
|
2020-06-27 00:57:30 +00:00
|
|
|
site: entityBySlugAndType(slug: $siteSlug, type: 2) {
|
2020-01-04 01:51:58 +00:00
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-06-27 00:57:30 +00:00
|
|
|
tags: entitiesTags {
|
2020-01-13 22:45:09 +00:00
|
|
|
tag {
|
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
network: parent {
|
2020-01-04 01:51:58 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
2020-05-26 23:40:10 +00:00
|
|
|
releasesConnection(
|
2020-05-24 01:54:29 +00:00
|
|
|
filter: {
|
|
|
|
date: {
|
|
|
|
lessThan: $before,
|
|
|
|
greaterThan: $after,
|
|
|
|
},
|
|
|
|
releasesTagsConnection: {
|
|
|
|
none: {
|
|
|
|
tag: {
|
|
|
|
slug: {
|
|
|
|
in: $exclude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
orderBy: $orderBy
|
|
|
|
) {
|
2020-05-26 23:40:10 +00:00
|
|
|
releases: nodes {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
totalCount
|
2020-05-24 01:54:29 +00:00
|
|
|
}
|
2020-01-04 01:51:58 +00:00
|
|
|
}
|
2020-05-26 23:40:10 +00:00
|
|
|
connection: releasesConnection(
|
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
orderBy: $orderBy
|
|
|
|
filter: {
|
2020-06-27 00:57:30 +00:00
|
|
|
entity: {
|
2020-05-26 23:40:10 +00:00
|
|
|
slug: {
|
|
|
|
equalTo: $siteSlug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
date: {
|
|
|
|
lessThan: $before,
|
|
|
|
greaterThan: $after
|
|
|
|
}
|
|
|
|
releasesTagsConnection: {
|
|
|
|
none: {
|
|
|
|
tag: {
|
|
|
|
slug: {
|
|
|
|
in: $exclude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
releases: nodes {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
totalCount
|
|
|
|
}
|
2020-01-04 01:51:58 +00:00
|
|
|
}
|
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
siteSlug,
|
|
|
|
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,
|
|
|
|
exclude: store.state.ui.filter,
|
|
|
|
});
|
2020-01-04 01:51:58 +00:00
|
|
|
|
2020-05-26 23:40:10 +00:00
|
|
|
return {
|
|
|
|
site: curateSite(site),
|
|
|
|
releases: releases.map(release => curateRelease(release)),
|
|
|
|
totalCount,
|
|
|
|
};
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2020-01-04 01:51:58 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
async function fetchSites({ _commit }, { limit = 100 }) {
|
|
|
|
const { sites } = await graphql(`
|
2020-01-04 01:51:58 +00:00
|
|
|
query Sites(
|
|
|
|
$actorSlug: String!
|
|
|
|
$limit:Int = 100,
|
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
|
|
|
) {
|
2020-06-27 00:57:30 +00:00
|
|
|
site: entity {
|
2020-01-04 01:51:58 +00:00
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
limit,
|
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
|
|
|
});
|
2019-11-11 02:20:00 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return sites;
|
|
|
|
}
|
2019-11-11 02:20:00 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return {
|
|
|
|
fetchSiteBySlug,
|
|
|
|
fetchSites,
|
|
|
|
};
|
2019-11-11 02:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default initSitesActions;
|