2020-01-04 01:51:58 +00:00
|
|
|
import { graphql } from '../api';
|
|
|
|
import { releasesFragment } from '../fragments';
|
|
|
|
import { curateSite } from '../curate';
|
2019-11-11 02:20:00 +00:00
|
|
|
|
2019-11-15 04:10:59 +00:00
|
|
|
function initSitesActions(store, _router) {
|
2020-01-04 01:51:58 +00:00
|
|
|
async function fetchSiteBySlug(siteSlug, limit = 100) {
|
|
|
|
const { site } = await graphql(`
|
|
|
|
query Site(
|
|
|
|
$siteSlug: String!,
|
|
|
|
$limit:Int = 100,
|
|
|
|
$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
|
|
|
) {
|
|
|
|
site: siteBySlug(slug: $siteSlug) {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-01-13 22:45:09 +00:00
|
|
|
tags: sitesTags {
|
|
|
|
tag {
|
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2020-01-04 01:51:58 +00:00
|
|
|
network {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
|
|
|
${releasesFragment}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
siteSlug,
|
|
|
|
limit,
|
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
2020-03-02 02:41:41 +00:00
|
|
|
isNew: store.getters.isNew,
|
2020-04-16 20:54:07 +00:00
|
|
|
orderBy: store.getters.orderBy,
|
2020-01-30 22:41:10 +00:00
|
|
|
exclude: store.state.ui.filter,
|
2020-01-04 01:51:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return curateSite(site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchSites({ _commit }, { siteSlug, limit = 100 }) {
|
|
|
|
if (siteSlug) {
|
|
|
|
return fetchSiteBySlug(siteSlug, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { sites } = await graphql(`
|
|
|
|
query Sites(
|
|
|
|
$actorSlug: String!
|
|
|
|
$limit:Int = 100,
|
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
|
|
|
) {
|
|
|
|
site {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
limit,
|
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
|
|
|
});
|
2019-11-11 02:20:00 +00:00
|
|
|
|
|
|
|
return sites;
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:10:32 +00:00
|
|
|
async function searchSites({ _commit }, { query, limit = 20 }) {
|
|
|
|
const { sites } = await graphql(`
|
|
|
|
query SearchSites(
|
|
|
|
$query: String!
|
|
|
|
$limit:Int = 20,
|
|
|
|
) {
|
|
|
|
sites: searchSites(
|
|
|
|
search: $query,
|
|
|
|
first: $limit
|
|
|
|
) {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
network {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
query,
|
|
|
|
limit,
|
2019-11-15 04:10:59 +00:00
|
|
|
});
|
2019-11-11 02:20:00 +00:00
|
|
|
|
2020-02-15 00:10:32 +00:00
|
|
|
return sites;
|
2019-11-11 02:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetchSites,
|
2020-02-15 00:10:32 +00:00
|
|
|
searchSites,
|
2019-11-11 02:20:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initSitesActions;
|