traxxx/assets/js/releases/actions.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

import { graphql } from '../api';
import { releasesFragment, releaseFragment } from '../fragments';
import { curateRelease } from '../curate';
import getDateRange from '../get-date-range';
2019-12-18 01:42:55 +00:00
function initReleasesActions(store, _router) {
2020-05-22 02:32:16 +00:00
async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range);
2020-05-22 02:32:16 +00:00
const { connection: { releases, totalCount } } = await graphql(`
2019-12-18 01:42:55 +00:00
query Releases(
$limit:Int = 1000,
2020-05-22 02:32:16 +00:00
$offset:Int = 0,
$after:Datetime = "1900-01-01",
$before:Datetime = "2100-01-01",
2020-01-30 22:41:10 +00:00
$orderBy:[ReleasesOrderBy!],
$exclude: [String!]
2019-12-18 01:42:55 +00:00
) {
${releasesFragment}
}
2019-12-15 22:01:48 +00:00
`, {
limit,
2020-05-22 02:32:16 +00:00
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
orderBy,
exclude: store.state.ui.filter,
});
2020-05-22 02:32:16 +00:00
return {
releases: releases.map(release => curateRelease(release)),
totalCount,
};
}
async function fetchReleaseById({ _commit }, releaseId) {
// const release = await get(`/releases/${releaseId}`);
const { release } = await graphql(`
query Release($releaseId:Int!) {
${releaseFragment}
}
`, {
releaseId: Number(releaseId),
});
return curateRelease(release);
}
return {
fetchReleases,
fetchReleaseById,
};
}
export default initReleasesActions;