traxxx/assets/js/actors/actions.js

363 lines
7.8 KiB
JavaScript
Raw Normal View History

import config from 'config';
2019-12-15 22:01:48 +00:00
import { graphql, get } from '../api';
import {
2020-05-26 23:40:10 +00:00
releaseFields,
releasePosterFragment,
releaseActorsFragment,
releaseTagsFragment,
} from '../fragments';
2020-05-17 23:22:56 +00:00
import { curateActor, curateRelease } from '../curate';
import getDateRange from '../get-date-range';
2019-12-15 22:01:48 +00:00
function initActorActions(store, router) {
2020-05-26 23:40:10 +00:00
async function fetchActorById({ _commit }, {
actorId,
limit = 10,
pageNumber = 1,
range = 'latest',
}) {
const { before, after, orderBy } = getDateRange(range);
const includeTags = router.currentRoute.query.tags ? router.currentRoute.query.tags.split(',') : [];
2020-05-26 23:40:10 +00:00
const { actor, connection: { releases, totalCount } } = await graphql(`
query Actor(
2020-05-25 02:39:58 +00:00
$actorId: Int!
2020-05-26 23:40:10 +00:00
$limit:Int = 10,
$offset:Int = 0,
$after:Datetime = "1900-01-01",
$before:Datetime = "2100-01-01",
$orderBy:[ReleasesActorsOrderBy!]
$selectableTags: [String],
$excludeTags: [String!]
${includeTags.length > 0 ? '$includeTags: [String!]' : ''}
) {
2020-05-25 02:39:58 +00:00
actor(id: $actorId) {
2019-12-15 22:01:48 +00:00
id
name
slug
realName
gender
dateOfBirth
dateOfDeath
age
ageAtDeath
ethnicity
2020-05-17 01:00:44 +00:00
cup
bust
waist
hip
naturalBoobs
heightMetric: height(units:METRIC)
heightImperial: height(units:IMPERIAL)
weightMetric: weight(units:METRIC)
weightImperial: weight(units:IMPERIAL)
hairColor
hairLength
eyes
hasTattoos
hasPiercings
tattoos
piercings
description
createdAt
updatedAt
2020-06-28 02:22:19 +00:00
entity {
id
name
slug
2020-06-28 02:22:19 +00:00
type
parent {
id
name
slug
type
}
}
2020-05-17 01:00:44 +00:00
avatar: avatarMedia {
id
path
thumbnail
lazy
hash
comment
credit
2020-05-17 23:22:56 +00:00
sfw: sfwMedia {
id
thumbnail
path
comment
}
2020-05-17 01:00:44 +00:00
}
profiles: actorsProfiles(orderBy: PRIORITY_DESC) {
description
descriptionHash
2020-06-28 02:22:19 +00:00
entity {
id
name
2020-06-28 02:22:19 +00:00
slug
type
independent
2020-06-28 02:22:19 +00:00
parent {
id
name
slug
type
}
}
avatar: avatarMedia {
id
path
thumbnail
lazy
2020-05-17 01:00:44 +00:00
hash
comment
credit
2020-05-17 23:22:56 +00:00
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
2019-12-15 22:01:48 +00:00
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocials {
id
url
platform
}
2019-12-15 22:01:48 +00:00
aliases: actorsByAliasFor {
id
name
slug
}
tags(selectableTags: $selectableTags) {
id
name
slug
priority
}
2020-05-26 23:40:10 +00:00
releasesConnection: releasesActorsConnection(
filter: {
release: {
date: {
lessThan: $before,
greaterThan: $after,
}
releasesTagsConnection: {
none: {
tag: {
slug: {
in: $excludeTags
}
}
}
}
}
2020-05-26 23:40:10 +00:00
}
first: $limit
offset: $offset
orderBy: $orderBy
) {
2020-05-26 23:40:10 +00:00
releases: nodes {
release {
id
url
title
date
slug
${releaseActorsFragment}
${releaseTagsFragment}
${releasePosterFragment}
2020-06-28 02:22:19 +00:00
entity {
2020-05-26 23:40:10 +00:00
id
name
slug
url
2020-06-28 02:22:19 +00:00
parent {
2020-05-26 23:40:10 +00:00
id
name
slug
url
}
}
}
}
}
2019-12-15 22:01:48 +00:00
}
2020-05-26 23:40:10 +00:00
connection: releasesActorsConnection(
first: $limit
offset: $offset
orderBy: $orderBy
condition: {
actorId: $actorId
}
2020-05-26 23:40:10 +00:00
filter: {
or: [
{
release: {
date: {
lessThan: $before,
greaterThan: $after
}
}
},
]
${includeTags.length > 0 ? `release: {
releasesTagsConnection: {
some: {
tag: {
slug: {
in: $includeTags
}
}
}
}
}` : ''}
2020-05-26 23:40:10 +00:00
}
) {
releases: nodes {
release {
${releaseFields}
}
}
totalCount
}
2019-12-15 22:01:48 +00:00
}
`, {
2020-05-25 02:39:58 +00:00
actorId,
limit,
2020-05-26 23:40:10 +00:00
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
selectableTags: config.selectableTags,
orderBy: orderBy === 'DATE_DESC' ? 'RELEASE_BY_RELEASE_ID__DATE_DESC' : 'RELEASE_BY_RELEASE_ID__DATE_ASC',
excludeTags: store.state.ui.filter,
includeTags,
});
2019-12-15 22:01:48 +00:00
2020-05-26 23:40:10 +00:00
return {
actor: curateActor(actor, null, curateRelease),
releases: releases.map(release => curateRelease(release.release)),
totalCount,
};
}
2019-12-15 22:01:48 +00:00
async function fetchActors({ _commit }, {
limit = 10,
pageNumber = 1,
letter,
gender,
}) {
const genderFilter = (gender === null && 'gender: { isNull: true }')
|| (gender === 'all' && ' ')
|| `gender: { equalTo: "${gender}" }`;
const { connection: { actors, totalCount } } = await graphql(`
query Actors(
$limit: Int,
$offset: Int = 0,
$letter: String! = "",
) {
connection: actorsConnection(
first: $limit,
offset: $offset
orderBy: NAME_ASC
filter: {
2020-05-17 23:22:56 +00:00
aliasFor: {
isNull: true
}
name: {
startsWith: $letter
2020-05-17 23:22:56 +00:00
}
${genderFilter}
2020-05-17 23:22:56 +00:00
}
) {
totalCount
actors: nodes {
2020-05-17 01:00:44 +00:00
id
name
slug
age
ageAtDeath
dateOfBirth
dateOfDeath
gender
2020-06-28 02:22:19 +00:00
entity {
id
name
slug
2020-06-28 02:22:19 +00:00
type
parent {
id
name
slug
type
}
}
avatar: avatarMedia {
2020-05-17 23:22:56 +00:00
id
path
thumbnail
lazy
2020-05-17 23:22:56 +00:00
comment
credit
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
2020-05-17 23:22:56 +00:00
}
2020-05-17 01:00:44 +00:00
}
2019-12-15 22:01:48 +00:00
}
}
`, {
offset: Math.max(0, (pageNumber - 1)) * limit,
limit,
letter,
});
2019-12-15 22:01:48 +00:00
return {
actors: actors.map(actor => curateActor(actor)),
totalCount,
};
}
async function fetchActorReleases({ _commit }, actorId) {
const releases = await get(`/actors/${actorId}/releases`, {
filter: store.state.ui.filter,
after: store.getters.after,
before: store.getters.before,
});
return releases;
}
return {
2020-05-25 02:39:58 +00:00
fetchActorById,
fetchActors,
fetchActorReleases,
};
}
export default initActorActions;