Added delete stash icons and dialog.

This commit is contained in:
DebaucheryLibrarian 2021-03-20 23:03:13 +01:00
parent 07643870cd
commit eee47111a6
14 changed files with 204 additions and 33 deletions

View File

@ -44,7 +44,7 @@
import Warning from './warning.vue'; import Warning from './warning.vue';
import Header from '../header/header.vue'; import Header from '../header/header.vue';
import Sidebar from '../sidebar/sidebar.vue'; import Sidebar from '../sidebar/sidebar.vue';
import Filters from './filters.vue'; import Filters from '../filters/filters.vue';
function toggleSidebar(state) { function toggleSidebar(state) {
this.showSidebar = typeof state === 'boolean' ? state : !this.showSidebar; this.showSidebar = typeof state === 'boolean' ? state : !this.showSidebar;

View File

@ -76,7 +76,6 @@ export default {
color: var(--text-light); color: var(--text-light);
font-size: 1.5rem; font-size: 1.5rem;
font-weight: bold; font-weight: bold;
text-transform: capitalize;
} }
.header-title { .header-title {
@ -106,7 +105,11 @@ export default {
::v-deep(.dialog-actions) { ::v-deep(.dialog-actions) {
display: flex; display: flex;
padding: .5rem 0; padding: 1rem 0 0 0;
&.center {
justify-content: center;
}
&.right { &.right {
justify-content: flex-end; justify-content: flex-end;

View File

@ -1,6 +1,6 @@
<template> <template>
<Dialog <Dialog
title="filters" title="Filters"
@close="$emit('close')" @close="$emit('close')"
> >
<div class="filters"> <div class="filters">

View File

@ -0,0 +1,38 @@
<template>
<Dialog
title="Remove stash"
@close="$emit('close', false)"
>
<form @submit.prevent="removeStash">
Are you sure you want to remove stash "{{ stash.name }}"?
<div class="dialog-actions right">
<button
type="submit"
class="button button-primary"
>Remove</button>
</div>
</form>
</Dialog>
</template>
<script>
async function removeStash() {
await this.$store.dispatch('removeStash', this.stash.id);
this.$emit('close', true);
}
export default {
props: {
stash: {
type: Object,
default: null,
},
},
emits: ['close'],
methods: {
removeStash,
},
};
</script>

View File

@ -7,6 +7,12 @@
<h2 class="stash-name">{{ stash.name }}</h2> <h2 class="stash-name">{{ stash.name }}</h2>
<span class="header-section"> <span class="header-section">
<router-link
v-if="stash.user"
:to="{ name: 'user', params: { username: stash.user.username } }"
class="header-item stash-username nolink"
><Icon icon="user3" />{{ stash.user.username }}</router-link>
<label <label
v-if="isMine" v-if="isMine"
v-tooltip="'Public'" v-tooltip="'Public'"
@ -30,11 +36,18 @@
/> />
</label> </label>
<router-link <Icon
v-if="stash.user" v-if="stash.deletable"
:to="{ name: 'user', params: { username: stash.user.username } }" icon="bin"
class="header-item stash-username nolink" class="stash-remove"
><Icon icon="user3" />{{ stash.user.username }}</router-link> @click.native="showRemoveStash = true"
/>
<RemoveStash
v-if="showRemoveStash"
:stash="stash"
@close="removeStash"
/>
</span> </span>
</div> </div>
@ -62,6 +75,7 @@
<script> <script>
import Actor from '../actors/tile.vue'; import Actor from '../actors/tile.vue';
import Releases from '../releases/releases.vue'; import Releases from '../releases/releases.vue';
import RemoveStash from './remove-stash.vue';
import Toggle from '../form/toggle.vue'; import Toggle from '../form/toggle.vue';
async function fetchStash() { async function fetchStash() {
@ -78,6 +92,19 @@ async function publishStash(isPublic) {
this.fetchStash(); this.fetchStash();
} }
async function removeStash(removed) {
this.showRemoveStash = false;
if (removed && this.stash.user) {
this.$router.replace({ name: 'user', params: { username: this.stash.user.username } });
return;
}
if (removed) {
this.$router.replace({ name: 'home' });
}
}
async function mounted() { async function mounted() {
this.fetchStash(); this.fetchStash();
} }
@ -86,11 +113,13 @@ export default {
components: { components: {
Actor, Actor,
Releases, Releases,
RemoveStash,
Toggle, Toggle,
}, },
data() { data() {
return { return {
stash: null, stash: null,
showRemoveStash: false,
isMine: false, isMine: false,
}; };
}, },
@ -98,6 +127,7 @@ export default {
methods: { methods: {
fetchStash, fetchStash,
publishStash, publishStash,
removeStash,
}, },
}; };
</script> </script>
@ -136,6 +166,17 @@ export default {
} }
} }
.stash-remove.icon {
height: 100%;
padding: 0 1rem;
fill: var(--lighten-strong);
&:hover {
fill: var(--text-light);
cursor: pointer;
}
}
.stash-name, .stash-name,
.stash-username { .stash-username {
display: inline-flex; display: inline-flex;

View File

@ -8,27 +8,42 @@
<h4 class="stash-name">{{ stash.name }}</h4> <h4 class="stash-name">{{ stash.name }}</h4>
</router-link> </router-link>
<label <span class="header-actions noselect">
v-if="isMe" <label
v-tooltip="'Public'" v-if="isMe"
:class="{ public: stash.public }" v-tooltip="'Public'"
class="stash-public" :class="{ public: stash.public }"
> class="stash-public"
<Icon >
v-show="stash.public" <Icon
icon="eye" v-show="stash.public"
/> icon="eye"
/>
<Icon
v-show="!stash.public"
icon="eye-blocked"
/>
<Toggle
:checked="stash.public"
@change="checked => publishStash(checked)"
/>
</label>
<Icon <Icon
v-show="!stash.public" v-if="stash.deletable"
icon="eye-blocked" icon="bin"
class="stash-remove"
@click.native="showRemoveStash = true"
/> />
<Toggle <RemoveStash
:checked="stash.public" v-if="showRemoveStash"
@change="checked => publishStash(stash, checked)" :stash="stash"
@close="removeStash"
/> />
</label> </span>
</div> </div>
<ul <ul
@ -68,21 +83,31 @@
<script> <script>
import ActorPreview from './actor-preview.vue'; import ActorPreview from './actor-preview.vue';
import ScenePreview from './scene-preview.vue'; import ScenePreview from './scene-preview.vue';
import RemoveStash from '../stashes/remove-stash.vue';
import Toggle from '../form/toggle.vue'; import Toggle from '../form/toggle.vue';
async function publishStash(stash, isPublic) { async function publishStash(isPublic) {
await this.$store.dispatch('updateStash', { await this.$store.dispatch('updateStash', {
stashId: stash.id, stashId: this.stash.id,
stash: { public: isPublic }, stash: { public: isPublic },
}); });
this.$emit('publish', isPublic); this.$emit('publish', isPublic);
} }
async function removeStash(removed) {
this.showRemoveStash = false;
if (removed) {
this.$emit('remove');
}
}
export default { export default {
components: { components: {
ActorPreview, ActorPreview,
ScenePreview, ScenePreview,
RemoveStash,
Toggle, Toggle,
}, },
props: { props: {
@ -95,9 +120,15 @@ export default {
default: false, default: false,
}, },
}, },
emits: ['publish'], emits: ['publish', 'remove'],
data() {
return {
showRemoveStash: false,
};
},
methods: { methods: {
publishStash, publishStash,
removeStash,
}, },
}; };
</script> </script>
@ -142,8 +173,13 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.stash-public { .header-actions {
display: flex; display: flex;
align-items: stretch;
}
.stash-public {
display: inline-flex;
align-items: center; align-items: center;
padding: .5rem; padding: .5rem;
cursor: pointer; cursor: pointer;
@ -154,6 +190,17 @@ export default {
} }
} }
.stash-remove {
height: auto;
padding: 0 1rem 0 .75rem;
fill: var(--shadow);
&:hover {
cursor: pointer;
fill: var(--shadow-strong);
}
}
.stash-actors, .stash-actors,
.stash-scenes { .stash-scenes {
display: flex; display: flex;

View File

@ -23,6 +23,7 @@
:stash="stash" :stash="stash"
:is-me="isMe" :is-me="isMe"
@publish="() => fetchUser()" @publish="() => fetchUser()"
@remove="() => fetchUser()"
/> />
</li> </li>
@ -131,20 +132,20 @@ export default {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background: var(--shadow-hint); background: var(--shadow-touch);
.icon { .icon {
width: 1.5rem; width: 1.5rem;
height: 1.5rem; height: 1.5rem;
fill: var(--shadow-weak); fill: var(--shadow-hint);
} }
&:hover { &:hover {
background: var(--shadow-weak); background: var(--shadow-hint);
cursor: pointer; cursor: pointer;
.icon { .icon {
fill: var(--shadow); fill: var(--shadow-weak);
} }
} }
} }

View File

@ -21,6 +21,7 @@ function initStashesActions(store, _router) {
name name
slug slug
public public
deletable
user { user {
id id
username username
@ -79,6 +80,10 @@ function initStashesActions(store, _router) {
return newStash; return newStash;
} }
async function removeStash(context, stashId) {
await del(`/stashes/${stashId}`);
}
async function stashActor(context, { actorId, stashId }) { async function stashActor(context, { actorId, stashId }) {
await post(`/stashes/${stashId}/actors`, { actorId }); await post(`/stashes/${stashId}/actors`, { actorId });
} }
@ -106,6 +111,7 @@ function initStashesActions(store, _router) {
return { return {
createStash, createStash,
fetchStash, fetchStash,
removeStash,
stashActor, stashActor,
stashScene, stashScene,
stashMovie, stashMovie,

View File

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

View File

@ -1067,6 +1067,10 @@ exports.up = knex => Promise.resolve()
.notNullable() .notNullable()
.defaultTo(false); .defaultTo(false);
table.boolean('deletable')
.notNullable()
.defaultTo(true);
table.datetime('created_at') table.datetime('created_at')
.notNullable() .notNullable()
.defaultTo(knex.fn.now()); .defaultTo(knex.fn.now());

View File

@ -80,6 +80,7 @@ async function signup(credentials) {
name: 'Favorites', name: 'Favorites',
slug: 'favorites', slug: 'favorites',
public: false, public: false,
deletable: false,
}); });
return fetchUser(userId); return fetchUser(userId);

View File

@ -80,6 +80,24 @@ async function updateStash(stashId, newStash, sessionUser) {
return curateStash(stash); return curateStash(stash);
} }
async function removeStash(stashId, sessionUser) {
if (!sessionUser) {
throw new HttpError('You are not authenthicated', 401);
}
const removed = await knex('stashes')
.where({
id: stashId,
user_id: sessionUser.id,
deletable: true,
})
.delete();
if (removed === 0) {
throw new HttpError('Unable to remove this stash', 400);
}
}
async function stashActor(actorId, stashId, sessionUser) { async function stashActor(actorId, stashId, sessionUser) {
const stash = await fetchStash(stashId, sessionUser); const stash = await fetchStash(stashId, sessionUser);
@ -149,6 +167,7 @@ async function unstashMovie(movieId, stashId, sessionUser) {
module.exports = { module.exports = {
createStash, createStash,
curateStash, curateStash,
removeStash,
stashActor, stashActor,
stashScene, stashScene,
stashMovie, stashMovie,

View File

@ -45,6 +45,7 @@ const {
const { const {
createStash, createStash,
removeStash,
stashActor, stashActor,
stashScene, stashScene,
stashMovie, stashMovie,
@ -87,6 +88,7 @@ async function initServer() {
router.post('/api/stashes', createStash); router.post('/api/stashes', createStash);
router.patch('/api/stashes/:stashId', updateStash); router.patch('/api/stashes/:stashId', updateStash);
router.delete('/api/stashes/:stashId', removeStash);
router.post('/api/stashes/:stashId/actors', stashActor); router.post('/api/stashes/:stashId/actors', stashActor);
router.post('/api/stashes/:stashId/scenes', stashScene); router.post('/api/stashes/:stashId/scenes', stashScene);

View File

@ -2,6 +2,7 @@
const { const {
createStash, createStash,
removeStash,
stashActor, stashActor,
stashScene, stashScene,
stashMovie, stashMovie,
@ -23,6 +24,12 @@ async function updateStashApi(req, res) {
res.send(stash); res.send(stash);
} }
async function removeStashApi(req, res) {
await removeStash(req.params.stashId, req.session.user);
res.status(204).send();
}
async function stashActorApi(req, res) { async function stashActorApi(req, res) {
await stashActor(req.body.actorId, req.params.stashId, req.session.user); await stashActor(req.body.actorId, req.params.stashId, req.session.user);
@ -61,6 +68,7 @@ async function unstashMovieApi(req, res) {
module.exports = { module.exports = {
createStash: createStashApi, createStash: createStashApi,
removeStash: removeStashApi,
stashActor: stashActorApi, stashActor: stashActorApi,
stashScene: stashSceneApi, stashScene: stashSceneApi,
stashMovie: stashMovieApi, stashMovie: stashMovieApi,