forked from DebaucheryLibrarian/traxxx
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
import { graphql } from '../api';
|
|
import { releasesFragment } from '../fragments';
|
|
import { curateSite } from '../curate';
|
|
|
|
function initSitesActions(store, _router) {
|
|
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",
|
|
$orderBy:[ReleasesOrderBy!]
|
|
$exclude: [String!]
|
|
) {
|
|
site: siteBySlug(slug: $siteSlug) {
|
|
name
|
|
slug
|
|
url
|
|
tags: sitesTags {
|
|
tag {
|
|
id
|
|
slug
|
|
name
|
|
}
|
|
}
|
|
network {
|
|
id
|
|
name
|
|
slug
|
|
url
|
|
}
|
|
${releasesFragment}
|
|
}
|
|
}
|
|
`, {
|
|
siteSlug,
|
|
limit,
|
|
after: store.getters.after,
|
|
before: store.getters.before,
|
|
orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC',
|
|
exclude: store.state.ui.filter,
|
|
});
|
|
|
|
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,
|
|
});
|
|
|
|
return sites;
|
|
}
|
|
|
|
/*
|
|
async function fetchSiteReleases({ _commit }, siteId) {
|
|
const releases = await get(`/sites/${siteId}/releases`, {
|
|
filter: store.state.ui.filter,
|
|
after: store.getters.after,
|
|
before: store.getters.before,
|
|
});
|
|
|
|
return releases;
|
|
}
|
|
*/
|
|
|
|
return {
|
|
fetchSites,
|
|
// fetchSiteReleases,
|
|
};
|
|
}
|
|
|
|
export default initSitesActions;
|