forked from DebaucheryLibrarian/traxxx
Abstracted fragments and curation. Using GraphQL for tags.
This commit is contained in:
@@ -1,23 +1,100 @@
|
||||
import { get } from '../api';
|
||||
import { graphql, get } from '../api';
|
||||
import {
|
||||
releasePosterFragment,
|
||||
releaseActorsFragment,
|
||||
releaseTagsFragment,
|
||||
siteFragment,
|
||||
} from '../fragments';
|
||||
import { curateRelease } from '../curate';
|
||||
|
||||
function curateTag(tag) {
|
||||
const curatedTag = {
|
||||
...tag,
|
||||
};
|
||||
|
||||
if (tag.releases) curatedTag.releases = tag.releases.map(({ tagRelease }) => curateRelease(tagRelease));
|
||||
if (tag.poster) [curatedTag.poster] = tag.poster;
|
||||
|
||||
return curatedTag;
|
||||
}
|
||||
|
||||
function initTagsActions(store, _router) {
|
||||
async function fetchTagBySlug(tagSlug) {
|
||||
const { tagBySlug } = await graphql(`
|
||||
query Tag($tagSlug:String!) {
|
||||
tagBySlug(slug:$tagSlug) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
description
|
||||
group {
|
||||
name
|
||||
slug
|
||||
}
|
||||
poster: tagsMediasByTargetId(condition: { role: "poster" }) {
|
||||
id
|
||||
thumbnail
|
||||
path
|
||||
}
|
||||
photos: tagsMediasByTargetId(condition: { role: "photo" }) {
|
||||
id
|
||||
thumbnail
|
||||
path
|
||||
}
|
||||
releases: releasesTags {
|
||||
tagRelease {
|
||||
id
|
||||
title
|
||||
date
|
||||
createdAt
|
||||
url
|
||||
${releaseActorsFragment}
|
||||
${releaseTagsFragment}
|
||||
${releasePosterFragment}
|
||||
${siteFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
tagSlug,
|
||||
});
|
||||
|
||||
return curateTag(tagBySlug);
|
||||
}
|
||||
|
||||
async function fetchTags({ _commit }, {
|
||||
tagId,
|
||||
tagSlug,
|
||||
limit = 100,
|
||||
slug,
|
||||
group,
|
||||
priority,
|
||||
slugs = [],
|
||||
_group,
|
||||
_priority,
|
||||
}) {
|
||||
if (tagId) {
|
||||
return get(`/tags/${tagId}`);
|
||||
if (tagSlug) {
|
||||
return fetchTagBySlug(tagSlug);
|
||||
}
|
||||
|
||||
return get('/tags', {
|
||||
const { tags } = await graphql(`
|
||||
query Tags($slugs: [String!] = [], $limit: Int = 100) {
|
||||
tags(filter: {slug: {in: $slugs}}, first: $limit) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
poster: tagsMediasByTargetId(condition: { role: "poster" }) {
|
||||
thumbnail
|
||||
}
|
||||
group {
|
||||
name
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
slugs,
|
||||
limit,
|
||||
slug,
|
||||
priority,
|
||||
group,
|
||||
});
|
||||
|
||||
return tags.map(tag => curateTag(tag));
|
||||
}
|
||||
|
||||
async function fetchTagReleases({ _commit }, tagId) {
|
||||
@@ -33,6 +110,7 @@ function initTagsActions(store, _router) {
|
||||
return {
|
||||
fetchTags,
|
||||
fetchTagReleases,
|
||||
fetchTagBySlug,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user