Changed stash routing.

This commit is contained in:
DebaucheryLibrarian 2023-06-08 04:19:37 +02:00
parent 81f504f33e
commit d847c58d24
9 changed files with 64 additions and 21 deletions

View File

@ -7,6 +7,11 @@
class="dialog-body" class="dialog-body"
@submit.prevent="addStash" @submit.prevent="addStash"
> >
<div
v-if="errorMsg"
class="form-error"
>{{ errorMsg }}</div>
<input <input
ref="name" ref="name"
v-model="name" v-model="name"
@ -27,11 +32,17 @@
<script> <script>
async function addStash() { async function addStash() {
this.errorMsg = null;
try {
await this.$store.dispatch('createStash', { await this.$store.dispatch('createStash', {
name: this.name, name: this.name,
}); });
this.$emit('close', true); this.$emit('close', true);
} catch (error) {
this.errorMsg = error.message;
}
} }
function mounted() { function mounted() {
@ -39,15 +50,22 @@ function mounted() {
} }
export default { export default {
emits: ['close'],
data() { data() {
return { return {
errorMsg: null,
name: null, name: null,
}; };
}, },
emits: ['close'],
mounted, mounted,
methods: { methods: {
addStash, addStash,
}, },
}; };
</script> </script>
<style lang="scss" scoped>
.input {
width: 100%;
}
</style>

View File

@ -115,6 +115,8 @@ import Pagination from '../pagination/pagination.vue';
async function fetchStash() { async function fetchStash() {
this.stash = await this.$store.dispatch('fetchStash', { this.stash = await this.$store.dispatch('fetchStash', {
stashId: this.$route.params.stashId, stashId: this.$route.params.stashId,
stashSlug: this.$route.params.stashSlug,
username: this.$route.params.username,
section: this.$route.params.range, section: this.$route.params.range,
pageNumber: this.$route.params.pageNumber || 1, pageNumber: this.$route.params.pageNumber || 1,
limit: this.limit, limit: this.limit,

View File

@ -1,13 +1,13 @@
<template> <template>
<div class="stash"> <div class="stash">
<div class="stash-section stash-header"> <div class="stash-section stash-header">
<router-link <RouterLink
:to="{ name: 'stash', params: { stashId: stash.id, stashSlug: stash.slug, range: 'scenes', pageNumber: 1 } }" :to="{ name: 'stash', params: { stashId: stash.id, stashSlug: stash.slug, range: 'scenes', pageNumber: 1 } }"
class="stash-link nolink" class="stash-link nolink"
> >
<h4 class="stash-name">{{ stash.name }}</h4> <h4 class="stash-name">{{ stash.name }}</h4>
<span class="stash-more">Browse</span> <span class="stash-more">Browse</span>
</router-link> </RouterLink>
<span class="header-actions noselect"> <span class="header-actions noselect">
<label <label

View File

@ -3,3 +3,11 @@
font-size: 1rem; font-size: 1rem;
font-weight: bold; font-weight: bold;
} }
.form-error {
padding: .5rem;
margin-bottom: .5rem;
color: var(--text-light);
background: var(--error);
font-weight: bold;
}

View File

@ -52,7 +52,7 @@ $breakpoint4: 1500px;
--female: #f0a; --female: #f0a;
--alert: #f00; --alert: #f00;
--error: #f00; --error: #fd5555;
--warn: #fa0; --warn: #fa0;
--success: #5c2; --success: #5c2;

View File

@ -233,7 +233,7 @@ const routes = [
name: 'notifications', name: 'notifications',
}, },
{ {
path: '/stash/:stashId/:stashSlug', path: '/user/:username/stash/:stashSlug',
redirect: (from) => ({ redirect: (from) => ({
name: 'stash', name: 'stash',
params: { params: {
@ -244,7 +244,7 @@ const routes = [
}), }),
}, },
{ {
path: '/stash/:stashId/:stashSlug?/:range/:pageNumber', path: '/user/:username/stash/:stashSlug/:range/:pageNumber',
component: Stash, component: Stash,
name: 'stash', name: 'stash',
}, },

View File

@ -10,14 +10,16 @@ import { curateStash } from '../curate';
function initStashesActions(store, _router) { function initStashesActions(store, _router) {
async function fetchStash(context, { async function fetchStash(context, {
stashId, stashSlug,
username,
section = 'scenes', section = 'scenes',
pageNumber = 1, pageNumber = 1,
limit = 20, limit = 20,
}) { }) {
const { stash } = await graphql(` const { stashes: [stash] } = await graphql(`
query Stash( query Stash(
$stashId: Int! $stashSlug: String!
$username: String!
$includeScenes: Boolean! $includeScenes: Boolean!
$includeActors: Boolean! $includeActors: Boolean!
$includeMovies: Boolean! $includeMovies: Boolean!
@ -26,7 +28,12 @@ function initStashesActions(store, _router) {
$hasAuth: Boolean! $hasAuth: Boolean!
$userId: Int $userId: Int
) { ) {
stash(id: $stashId) { stashes(
filter: {
user: { username: { equalTo: $username } }
slug: { equalTo: $stashSlug }
}
) {
id id
name name
slug slug
@ -101,7 +108,8 @@ function initStashesActions(store, _router) {
} }
} }
`, { `, {
stashId: Number(stashId), stashSlug,
username,
includeScenes: section === 'scenes', includeScenes: section === 'scenes',
includeActors: section === 'actors', includeActors: section === 'actors',
includeMovies: section === 'movies', includeMovies: section === 'movies',

View File

@ -66,11 +66,19 @@ async function createStash(newStash, sessionUser) {
throw new HttpError('You are not authenthicated', 401); throw new HttpError('You are not authenthicated', 401);
} }
try {
const stash = await knex('stashes') const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser)) .insert(curateStashEntry(newStash, sessionUser))
.returning('*'); .returning('*');
return curateStash(stash); return curateStash(stash);
} catch (error) {
if (error.routine === '_bt_check_unique') {
throw new HttpError('Stash name should be unique', 409);
}
throw error;
}
} }
async function updateStash(stashId, newStash, sessionUser) { async function updateStash(stashId, newStash, sessionUser) {

View File

@ -36,7 +36,6 @@ async function curateReleaseEntry(release, batchId, existingRelease, type = 'sce
url: release.url, url: release.url,
date: Number(release.date) ? release.date : null, date: Number(release.date) ? release.date : null,
date_precision: release.datePrecision, date_precision: release.datePrecision,
duration: Number(release.duration) || null,
slug, slug,
description: release.description, description: release.description,
comment: release.comment, comment: release.comment,
@ -48,7 +47,7 @@ async function curateReleaseEntry(release, batchId, existingRelease, type = 'sce
if (type === 'scene') { if (type === 'scene') {
curatedRelease.shoot_id = release.shootId || null; curatedRelease.shoot_id = release.shootId || null;
curatedRelease.production_date = Number(release.productionDate) ? release.productionDate : null; curatedRelease.production_date = Number(release.productionDate) ? release.productionDate : null;
curatedRelease.duration = release.duration; curatedRelease.duration = Number(release.duration) || null;
curatedRelease.qualities = Array.from(new Set(release.qualities?.map(Number).filter(Boolean))).sort((qualityA, qualityB) => qualityB - qualityA); curatedRelease.qualities = Array.from(new Set(release.qualities?.map(Number).filter(Boolean))).sort((qualityA, qualityB) => qualityB - qualityA);
} }