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';
|
2020-05-07 01:20:51 +00:00
|
|
|
import getDateRange from '../get-date-range';
|
2019-06-03 03:31:38 +00:00
|
|
|
|
2019-12-18 01:42:55 +00:00
|
|
|
function initReleasesActions(store, _router) {
|
2020-05-14 02:26:05 +00:00
|
|
|
async function fetchReleases({ _commit }, { limit = 100, range = 'latest' }) {
|
|
|
|
const { before, after, orderBy } = getDateRange(range);
|
2020-05-07 01:20:51 +00:00
|
|
|
|
2020-05-14 02:26:05 +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-30 22:41:10 +00:00
|
|
|
$orderBy:[ReleasesOrderBy!],
|
|
|
|
$exclude: [String!]
|
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
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
limit,
|
|
|
|
after,
|
|
|
|
before,
|
|
|
|
orderBy,
|
|
|
|
exclude: store.state.ui.filter,
|
|
|
|
});
|
2019-12-15 21:16:55 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return releases.map(release => curateRelease(release));
|
|
|
|
}
|
2019-12-15 21:16:55 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
async function searchReleases({ _commit }, { query, limit = 20 }) {
|
|
|
|
const res = await graphql(`
|
2020-02-26 00:15:50 +00:00
|
|
|
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-03-29 02:00:46 +00:00
|
|
|
id
|
|
|
|
title
|
|
|
|
slug
|
|
|
|
date
|
|
|
|
url
|
|
|
|
type
|
|
|
|
isNew
|
|
|
|
site {
|
2020-02-26 00:15:50 +00:00
|
|
|
id
|
2020-03-01 04:28:08 +00:00
|
|
|
slug
|
2020-03-29 02:00:46 +00:00
|
|
|
name
|
2020-02-26 00:15:50 +00:00
|
|
|
url
|
2020-03-29 02:00:46 +00:00
|
|
|
network {
|
2020-02-26 00:15:50 +00:00
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
|
|
|
url
|
|
|
|
}
|
2020-03-29 02:00:46 +00:00
|
|
|
}
|
|
|
|
actors: releasesActors {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
2020-02-26 00:15:50 +00:00
|
|
|
}
|
2020-03-29 02:00:46 +00:00
|
|
|
}
|
|
|
|
tags: releasesTags(orderBy: TAG_BY_TAG_ID__PRIORITY_DESC) {
|
|
|
|
tag {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
2020-02-26 00:15:50 +00:00
|
|
|
}
|
2020-03-29 02:00:46 +00:00
|
|
|
}
|
|
|
|
poster: releasesPosterByReleaseId {
|
|
|
|
media {
|
|
|
|
id
|
|
|
|
thumbnail
|
2020-05-07 00:10:28 +00:00
|
|
|
lazy
|
2020-03-08 03:23:10 +00:00
|
|
|
}
|
2020-03-29 02:00:46 +00:00
|
|
|
}
|
|
|
|
covers: releasesCovers {
|
|
|
|
media {
|
|
|
|
id
|
|
|
|
thumbnail
|
2020-05-07 00:10:28 +00:00
|
|
|
lazy
|
2020-02-26 00:15:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
query,
|
|
|
|
limit,
|
|
|
|
});
|
2020-02-26 00:15:50 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (!res) return [];
|
2020-02-26 00:15:50 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return res.releases.map(release => curateRelease(release));
|
|
|
|
}
|
2020-02-26 00:15:50 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
async function fetchReleaseById({ _commit }, releaseId) {
|
|
|
|
// const release = await get(`/releases/${releaseId}`);
|
2019-12-15 21:16:55 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const { release } = await graphql(`
|
2019-12-15 21:16:55 +00:00
|
|
|
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
|
|
|
`, {
|
2020-05-14 02:26:05 +00:00
|
|
|
releaseId: Number(releaseId),
|
|
|
|
});
|
2019-11-15 01:37:17 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return curateRelease(release);
|
|
|
|
}
|
2019-11-15 01:37:17 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return {
|
|
|
|
fetchReleases,
|
|
|
|
fetchReleaseById,
|
|
|
|
searchReleases,
|
|
|
|
};
|
2019-06-03 03:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default initReleasesActions;
|