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

View File

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

View File

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

View File

@ -3,3 +3,11 @@
font-size: 1rem;
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;
--alert: #f00;
--error: #f00;
--error: #fd5555;
--warn: #fa0;
--success: #5c2;

View File

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

View File

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

View File

@ -66,11 +66,19 @@ async function createStash(newStash, sessionUser) {
throw new HttpError('You are not authenthicated', 401);
}
try {
const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser))
.returning('*');
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) {

View File

@ -36,7 +36,6 @@ async function curateReleaseEntry(release, batchId, existingRelease, type = 'sce
url: release.url,
date: Number(release.date) ? release.date : null,
date_precision: release.datePrecision,
duration: Number(release.duration) || null,
slug,
description: release.description,
comment: release.comment,
@ -48,7 +47,7 @@ async function curateReleaseEntry(release, batchId, existingRelease, type = 'sce
if (type === 'scene') {
curatedRelease.shoot_id = release.shootId || 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);
}