traxxx/assets/js/releases/actions.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

import { graphql } from '../api';
import { releasesFragment, releaseFragment } from '../fragments';
import { curateRelease } from '../curate';
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 }) {
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-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,
2019-12-18 01:42:55 +00:00
after: store.getters.after,
before: store.getters.before,
orderBy: store.state.ui.range === 'upcoming' ? 'DATE_ASC' : 'DATE_DESC',
2020-01-30 22:41:10 +00:00
exclude: store.state.ui.filter,
2019-12-15 22:01:48 +00:00
});
return releases.map(release => curateRelease(release));
}
2020-02-26 00:15:50 +00:00
async function searchReleases({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
$query: String!
$limit: Int = 20
) {
releases: searchReleases(
2020-02-26 02:38:21 +00:00
query: $query
2020-02-26 00:15:50 +00:00
first: $limit
) {
2020-02-26 02:38:21 +00:00
releaseById {
2020-02-26 00:15:50 +00:00
id
2020-02-26 02:38:21 +00:00
title
date
2020-02-26 00:15:50 +00:00
url
2020-02-26 02:38:21 +00:00
site {
2020-02-26 00:15:50 +00:00
id
slug
name
url
2020-02-26 02:38:21 +00:00
network {
id
slug
name
url
}
2020-02-26 00:15:50 +00:00
}
2020-02-26 02:38:21 +00:00
actors: releasesActors {
actor {
id
slug
name
}
2020-02-26 00:15:50 +00:00
}
2020-02-26 02:38:21 +00:00
tags: releasesTags {
tag {
id
name
slug
}
2020-02-26 00:15:50 +00:00
}
2020-02-26 02:38:21 +00:00
poster: releasesPosterByReleaseId {
media {
thumbnail
}
2020-02-26 00:15:50 +00:00
}
}
}
}
`, {
query,
limit,
});
if (!res) return [];
2020-02-26 02:38:21 +00:00
return res.releases.map(release => curateRelease(release.releaseById));
2020-02-26 00:15:50 +00:00
}
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,
2020-02-26 00:15:50 +00:00
searchReleases,
};
}
export default initReleasesActions;