Abstracted fragments and curation. Using GraphQL for tags.

This commit is contained in:
2019-12-16 05:30:25 +01:00
parent f4c2e6c08c
commit 6950a76cb5
10 changed files with 260 additions and 159 deletions

View File

@@ -1,24 +1,6 @@
import { graphql } from '../api';
function curateRelease(release) {
const curatedRelease = {
...release,
actors: release.actors.map(({ actor }) => ({
...actor,
avatar: actor.avatar[0],
origin: actor.originCountry && {
country: actor.originCountry,
},
})),
poster: release.poster[0],
network: release.site.network,
tags: release.tags.map(({ tag }) => tag),
};
if (release.trailer) [curatedRelease.trailer] = release.trailer;
return curatedRelease;
}
import { releasesFragment, releaseFragment } from '../fragments';
import { curateRelease } from '../curate';
function initReleasesActions(_store, _router) {
async function fetchReleases({ _commit }, { limit = 100 }) {
@@ -32,58 +14,7 @@ function initReleasesActions(_store, _router) {
const { releases } = await graphql(`
query Releases($limit:Int!) {
releases(first:$limit, orderBy: DATE_DESC) {
id
title
description
date
duration
createdAt
shootId
url
actors: actorsAssociateds {
actor {
id
name
slug
birthdate
age
originCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
avatar: actorsMediasByTargetId(condition: { role: "avatar" }) {
thumbnail
}
}
}
poster: releasesMediasByTargetId(condition: { role: "poster" }) {
index
path
thumbnail
}
tags: releasesTagsByTargetId {
tag: releaseTag {
name
priority
slug
id
}
}
site {
id
name
slug
url
network {
id
name
slug
url
}
}
}
${releasesFragment}
}
`, {
limit,
@@ -97,68 +28,7 @@ function initReleasesActions(_store, _router) {
const { release } = await graphql(`
query Release($releaseId:Int!) {
release(id: $releaseId) {
id
title
description
date
duration
createdAt
shootId
url
actors: actorsAssociateds {
actor {
id
name
slug
birthdate
age
originCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
avatar: actorsMediasByTargetId(condition: { role: "avatar" }) {
thumbnail
}
}
}
poster: releasesMediasByTargetId(condition: { role: "poster" }) {
index
path
thumbnail
}
photos: releasesMediasByTargetId(condition: { role: "photo" }) {
index
path
thumbnail
}
trailer: releasesMediasByTargetId(condition: { role: "trailer" }) {
index
path
thumbnail
}
tags: releasesTagsByTargetId {
tag: releaseTag {
name
priority
slug
id
}
}
site {
id
name
slug
url
network {
id
name
slug
url
}
}
}
${releaseFragment}
}
`, {
releaseId: Number(releaseId),