2019-12-15 21:16:55 +00:00
|
|
|
import { graphql } from '../api';
|
2019-12-16 04:30:25 +00:00
|
|
|
import { releasesFragment, releaseFragment } from '../fragments';
|
|
|
|
import { curateRelease } from '../curate';
|
2019-06-03 03:31:38 +00:00
|
|
|
|
2019-12-18 01:42:55 +00:00
|
|
|
function initReleasesActions(store, _router) {
|
2019-12-15 22:01:48 +00:00
|
|
|
async function fetchReleases({ _commit }, { limit = 100 }) {
|
2019-12-18 01:42:55 +00:00
|
|
|
console.log(store.state.ui.filter, store.getters.after, store.getters.before);
|
2019-06-03 03:31:38 +00:00
|
|
|
|
2019-12-15 21:16:55 +00:00
|
|
|
const { releases } = await graphql(`
|
2019-12-18 01:42:55 +00:00
|
|
|
query Releases(
|
|
|
|
$limit:Int = 1000,
|
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
2020-01-08 23:23:37 +00:00
|
|
|
$orderBy:[ReleasesOrderBy!]
|
2019-12-18 01:42:55 +00:00
|
|
|
) {
|
2019-12-16 04:30:25 +00:00
|
|
|
${releasesFragment}
|
2019-12-15 21:16:55 +00:00
|
|
|
}
|
2019-12-15 22:01:48 +00:00
|
|
|
`, {
|
|
|
|
limit,
|
2019-12-18 01:42:55 +00:00
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
2020-01-08 23:23:37 +00:00
|
|
|
orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC',
|
2019-12-15 22:01:48 +00:00
|
|
|
});
|
2019-12-15 21:16:55 +00:00
|
|
|
|
|
|
|
return releases.map(release => curateRelease(release));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchReleaseById({ _commit }, releaseId) {
|
|
|
|
// const release = await get(`/releases/${releaseId}`);
|
|
|
|
|
|
|
|
const { release } = await graphql(`
|
|
|
|
query Release($releaseId:Int!) {
|
2019-12-16 04:30:25 +00:00
|
|
|
${releaseFragment}
|
2019-12-15 04:42:51 +00:00
|
|
|
}
|
2019-12-15 21:16:55 +00:00
|
|
|
`, {
|
|
|
|
releaseId: Number(releaseId),
|
|
|
|
});
|
2019-11-15 01:37:17 +00:00
|
|
|
|
2019-12-15 21:16:55 +00:00
|
|
|
return curateRelease(release);
|
2019-11-15 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-03 03:31:38 +00:00
|
|
|
return {
|
|
|
|
fetchReleases,
|
2019-11-15 01:37:17 +00:00
|
|
|
fetchReleaseById,
|
2019-06-03 03:31:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initReleasesActions;
|