111 lines
2.6 KiB
JavaScript
111 lines
2.6 KiB
JavaScript
import { graphql } from '../api';
|
|
import { releasesFragment } from '../fragments';
|
|
import { curateSite } from '../curate';
|
|
import getDateRange from '../get-date-range';
|
|
|
|
function initSitesActions(store, _router) {
|
|
async function fetchSiteBySlug({ _commit }, { siteSlug, limit = 100, range = 'latest' }) {
|
|
const { before, after, orderBy } = getDateRange(range);
|
|
|
|
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,
|
|
before,
|
|
orderBy,
|
|
isNew: store.getters.isNew,
|
|
exclude: store.state.ui.filter,
|
|
});
|
|
|
|
return curateSite(site);
|
|
}
|
|
|
|
async function fetchSites({ _commit }, { limit = 100 }) {
|
|
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 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,
|
|
});
|
|
|
|
return sites;
|
|
}
|
|
|
|
return {
|
|
fetchSiteBySlug,
|
|
fetchSites,
|
|
searchSites,
|
|
};
|
|
}
|
|
|
|
export default initSitesActions;
|