traxxx/assets/js/actors/actions.js

325 lines
7.3 KiB
JavaScript

import { graphql, get } from '../api';
import {
releaseFields,
releasePosterFragment,
releaseActorsFragment,
releaseTagsFragment,
} from '../fragments';
import { curateActor, curateRelease } from '../curate';
import getDateRange from '../get-date-range';
function initActorActions(store, _router) {
async function fetchActorById({ _commit }, {
actorId,
limit = 10,
pageNumber = 1,
range = 'latest',
}) {
const { before, after, orderBy } = getDateRange(range);
const { actor, connection: { releases, totalCount } } = await graphql(`
query Actor(
$actorId: Int!
$limit:Int = 10,
$offset:Int = 0,
$after:Date = "1900-01-01",
$before:Date = "2100-01-01",
$orderBy:[ReleasesActorsOrderBy!]
$exclude: [String!]
) {
actor(id: $actorId) {
id
name
slug
realName
gender
dateOfBirth
dateOfDeath
age
ageAtDeath
ethnicity
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
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
profiles: actorsProfiles {
description
descriptionHash
network {
id
slug
name
}
site {
id
slug
name
}
avatar: avatarMedia {
id
path
thumbnail
lazy
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocials {
id
url
platform
}
aliases: actorsByAliasFor {
id
name
slug
}
releasesConnection: releasesActorsConnection(
filter: {
release: {
date: {
lessThan: $before,
greaterThan: $after,
},
releasesTagsConnection: {
none: {
tag: {
slug: {
in: $exclude
}
}
}
}
}
}
first: $limit
offset: $offset
orderBy: $orderBy
) {
releases: nodes {
release {
id
url
title
date
slug
${releaseActorsFragment}
${releaseTagsFragment}
${releasePosterFragment}
site {
id
name
slug
url
network {
id
name
slug
url
}
}
}
}
}
}
connection: releasesActorsConnection(
first: $limit
offset: $offset
orderBy: $orderBy
filter: {
actorId: {
equalTo: $actorId
}
or: [
{
release: {
date: {
lessThan: $before,
greaterThan: $after
}
}
},
]
}
) {
releases: nodes {
release {
${releaseFields}
}
}
totalCount
}
}
`, {
actorId,
limit,
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
orderBy: orderBy === 'DATE_DESC' ? 'RELEASE_BY_RELEASE_ID__DATE_DESC' : 'RELEASE_BY_RELEASE_ID__DATE_ASC',
exclude: store.state.ui.filter,
});
return {
actor: curateActor(actor, null, curateRelease),
releases: releases.map(release => curateRelease(release.release)),
totalCount,
};
}
async function fetchActors({ _commit }, {
limit = 10,
pageNumber = 1,
letter,
gender,
}) {
const genderFilter = gender === null
? 'isNull: true'
: `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: {
aliasFor: {
isNull: true
}
name: {
startsWith: $letter
}
gender: {
${genderFilter}
}
}
) {
totalCount
actors: nodes {
id
name
slug
age
ageAtDeath
dateOfBirth
dateOfDeath
gender
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
}
`, {
offset: Math.max(0, (pageNumber - 1)) * limit,
limit,
letter,
});
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 {
fetchActorById,
fetchActors,
fetchActorReleases,
};
}
export default initActorActions;