Added stash menu to release page, returning stashes from stash API to avoid reloading or local interpolation.

This commit is contained in:
DebaucheryLibrarian
2021-03-21 03:23:58 +01:00
parent de5d104e1e
commit 348aa91832
18 changed files with 309 additions and 93 deletions

View File

@@ -66,6 +66,12 @@ async function del(endpoint) {
credentials: 'same-origin',
});
const contentTypes = res.headers.get('content-type');
if (res.ok && contentTypes?.includes('application/json')) {
return res.json();
}
if (res.ok) {
return true;
}

View File

@@ -56,6 +56,10 @@ function curateActor(actor, release) {
curatedActor.aliasFor = curateActor(curatedActor.aliasFor);
}
if (actor.stashes) {
curatedActor.stashes = actor.stashes.filter(Boolean).map(stash => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
}
curatedActor.stashes = actor.stashes?.map(stash => stash.stash || stash) || [];
return curatedActor;
@@ -80,6 +84,7 @@ function curateRelease(release) {
if (release.directors) curatedRelease.directors = release.directors.filter(Boolean).map(director => curateActor(director.director || director, curatedRelease));
if (release.movieTags && release.movieTags.length > 0) curatedRelease.tags = release.movieTags.filter(Boolean).map(({ tag }) => tag);
if (release.movieActors && release.movieActors.length > 0) curatedRelease.actors = release.movieActors.filter(Boolean).map(({ actor }) => curateActor(actor, curatedRelease));
if (release.stashes) curatedRelease.stashes = release.stashes.filter(Boolean).map(stash => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
if (release.productionLocation) {
curatedRelease.productionLocation = {
@@ -155,7 +160,7 @@ function curateUser(user) {
const curatedUser = user;
if (user.stashes) {
curatedUser.stashes = user.stashes.map(stash => curateStash(stash));
curatedUser.stashes = user.stashes.map(stash => curateStash(stash.stash || stash));
}
return curatedUser;

View File

@@ -228,7 +228,8 @@ const releaseFields = `
url
}
isNew
isStashed
isFavorited
isStashed(includeFavorites: false)
stashes: stashesScenesBySceneId(
filter: {
stash: {
@@ -242,6 +243,7 @@ const releaseFields = `
id
name
slug
primary
}
}
`;
@@ -368,7 +370,8 @@ const releaseFragment = `
}
}
}
isStashed
isFavorited
isStashed(includeFavorites: false)
stashes: stashesScenesBySceneId(
filter: {
stash: {
@@ -382,6 +385,7 @@ const releaseFragment = `
id
name
slug
primary
}
}
}

View File

@@ -21,7 +21,7 @@ function initStashesActions(store, _router) {
name
slug
public
deletable
primary
user {
id
username
@@ -69,15 +69,11 @@ function initStashesActions(store, _router) {
}
async function createStash(context, stash) {
const newStash = await post('/stashes', stash);
return newStash;
return post('/stashes', stash);
}
async function updateStash(context, { stashId, stash }) {
const newStash = await patch(`/stashes/${stashId}`, stash);
return newStash;
return patch(`/stashes/${stashId}`, stash);
}
async function removeStash(context, stashId) {
@@ -85,27 +81,27 @@ function initStashesActions(store, _router) {
}
async function stashActor(context, { actorId, stashId }) {
await post(`/stashes/${stashId}/actors`, { actorId });
return post(`/stashes/${stashId}/actors`, { actorId });
}
async function unstashActor(context, { actorId, stashId }) {
await del(`/stashes/${stashId}/actors/${actorId}`);
return del(`/stashes/${stashId}/actors/${actorId}`);
}
async function stashScene(context, { sceneId, stashId }) {
await post(`/stashes/${stashId}/scenes`, { sceneId });
return post(`/stashes/${stashId}/scenes`, { sceneId });
}
async function unstashScene(context, { sceneId, stashId }) {
await del(`/stashes/${stashId}/scenes/${sceneId}`);
return del(`/stashes/${stashId}/scenes/${sceneId}`);
}
async function stashMovie(context, { movieId, stashId }) {
await post(`/stashes/${stashId}/movies`, { movieId });
return post(`/stashes/${stashId}/movies`, { movieId });
}
async function unstashMovie(context, { movieId, stashId }) {
await del(`/stashes/${stashId}/movies/${movieId}`);
return del(`/stashes/${stashId}/movies/${movieId}`);
}
return {

View File

@@ -19,7 +19,7 @@ function initUsersActions(store, _router) {
name
slug
public
deletable
primary
actors: stashesActors {
comment
actor {