2024-03-27 01:28:21 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
v-if="user"
|
|
|
|
class="bookmarks"
|
|
|
|
>
|
2024-07-07 19:01:44 +00:00
|
|
|
<VDropdown
|
|
|
|
v-if="showSecondary || (hasSecondaryStash && pageStash?.user.id !== user.id)"
|
|
|
|
:shown="showStashes"
|
|
|
|
@hide="showStashes = false"
|
|
|
|
>
|
2024-03-27 01:28:21 +00:00
|
|
|
<Icon
|
|
|
|
icon="folder-heart"
|
|
|
|
class="heart noselect"
|
|
|
|
:class="{ favorited: itemStashes.some((itemStash) => !itemStash.isPrimary) }"
|
2024-07-07 19:01:44 +00:00
|
|
|
@contextmenu.prevent="showStashes = true"
|
2024-03-27 01:28:21 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<template #popper>
|
2024-07-07 19:01:44 +00:00
|
|
|
<StashMenu
|
|
|
|
:user="user"
|
|
|
|
:item-stashes="itemStashes"
|
|
|
|
@stash="(stash) => stashItem(stash)"
|
|
|
|
@unstash="(stash) => unstashItem(stash)"
|
2024-08-04 21:40:25 +00:00
|
|
|
@create="showStashDialog = true"
|
2024-07-07 19:01:44 +00:00
|
|
|
/>
|
2024-03-27 01:28:21 +00:00
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
|
2024-07-07 19:01:44 +00:00
|
|
|
<VDropdown
|
|
|
|
v-if="showSecondary || !hasSecondaryStash || pageStash?.user.id === user.id"
|
|
|
|
:triggers="[]"
|
|
|
|
:shown="showStashes"
|
|
|
|
:disabled="showSecondary"
|
|
|
|
@hide="showStashes = false"
|
|
|
|
>
|
|
|
|
<template v-if="pageStash?.user.id === user.id">
|
|
|
|
<Icon
|
|
|
|
v-if="itemStashes.some((itemStash) => itemStash.id === pageStash.id)"
|
|
|
|
:icon="pageStash.isPrimary ? 'heart7' : 'folder-heart'"
|
|
|
|
class="heart favorited noselect"
|
|
|
|
@click.native.stop="unstashItem(pageStash)"
|
|
|
|
@contextmenu.prevent="toggleShowStashes(true)"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Icon
|
|
|
|
v-else
|
|
|
|
:icon="pageStash.isPrimary ? 'heart8' : 'folder-heart'"
|
|
|
|
class="heart noselect"
|
|
|
|
@click.native.stop="stashItem(pageStash)"
|
|
|
|
@contextmenu.prevent="toggleShowStashes(true)"
|
|
|
|
/>
|
|
|
|
</template>
|
2024-03-27 01:28:21 +00:00
|
|
|
|
2024-07-07 19:01:44 +00:00
|
|
|
<template v-else>
|
|
|
|
<Icon
|
|
|
|
v-if="itemStashes.some((itemStash) => itemStash.id === user.primaryStash.id)"
|
|
|
|
icon="heart7"
|
|
|
|
class="heart favorited noselect"
|
|
|
|
@click.native.stop="unstashItem(user.primaryStash)"
|
|
|
|
@contextmenu.prevent="toggleShowStashes(true)"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Icon
|
|
|
|
v-else
|
|
|
|
icon="heart8"
|
|
|
|
class="heart noselect"
|
|
|
|
@click.native.stop="stashItem(user.primaryStash)"
|
|
|
|
@contextmenu.prevent="toggleShowStashes(true)"
|
|
|
|
/>
|
|
|
|
</template>
|
2024-04-02 00:50:24 +00:00
|
|
|
|
2024-07-07 19:01:44 +00:00
|
|
|
<template #popper>
|
|
|
|
<StashMenu
|
|
|
|
:user="user"
|
|
|
|
:item-stashes="itemStashes"
|
|
|
|
@stash="(stash) => stashItem(stash)"
|
|
|
|
@unstash="(stash) => unstashItem(stash)"
|
2024-08-04 21:40:25 +00:00
|
|
|
@create="showStashDialog = true"
|
2024-07-07 19:01:44 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</VDropdown>
|
2024-08-04 21:40:25 +00:00
|
|
|
|
|
|
|
<StashDialog
|
|
|
|
v-if="showStashDialog"
|
|
|
|
@created="showStashDialog = false; reloadStashes();"
|
|
|
|
/>
|
2024-03-27 01:28:21 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2024-07-07 19:01:44 +00:00
|
|
|
import { ref, computed, inject } from 'vue';
|
2024-03-27 01:28:21 +00:00
|
|
|
|
2024-08-04 21:40:25 +00:00
|
|
|
import { get, post, del } from '#/src/api.js';
|
2024-03-27 01:28:21 +00:00
|
|
|
import ellipsis from '#/utils/ellipsis.js';
|
|
|
|
|
|
|
|
import Icon from '#/components/icon/icon.vue';
|
2024-07-07 19:01:44 +00:00
|
|
|
import StashMenu from '#/components/stashes/menu.vue';
|
2024-08-04 21:40:25 +00:00
|
|
|
import StashDialog from '#/components/stashes/create.vue';
|
2024-03-27 01:28:21 +00:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
domain: {
|
|
|
|
type: String,
|
|
|
|
default: 'scenes',
|
|
|
|
},
|
|
|
|
item: {
|
|
|
|
type: Object,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
showSecondary: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits(['stashed', 'unstashed']);
|
|
|
|
|
2024-03-27 02:05:32 +00:00
|
|
|
const { user, pageProps } = inject('pageContext');
|
2024-04-02 00:50:24 +00:00
|
|
|
const pageStash = pageProps.stash;
|
2024-03-27 01:28:21 +00:00
|
|
|
|
|
|
|
const itemStashes = ref(props.item.stashes);
|
2024-07-07 19:01:44 +00:00
|
|
|
const hasSecondaryStash = computed(() => itemStashes.value.some((itemStash) => !itemStash.isPrimary));
|
2024-03-27 01:28:21 +00:00
|
|
|
|
|
|
|
const done = ref(true);
|
2024-07-07 19:01:44 +00:00
|
|
|
const showStashes = ref(false);
|
2024-08-04 21:40:25 +00:00
|
|
|
const showStashDialog = ref(false);
|
2024-03-27 01:28:21 +00:00
|
|
|
const feedbackCutoff = 20;
|
|
|
|
|
|
|
|
const itemKeys = {
|
|
|
|
scenes: 'sceneId',
|
|
|
|
actors: 'actorId',
|
|
|
|
movies: 'movieId',
|
|
|
|
};
|
|
|
|
|
|
|
|
async function stashItem(stash) {
|
|
|
|
if (!done.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stashState = itemStashes.value;
|
|
|
|
|
|
|
|
done.value = false;
|
|
|
|
itemStashes.value = itemStashes.value.concat(stash);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await post(`/stashes/${stash.id}/${props.domain}`, { [itemKeys[props.domain]]: props.item.id }, {
|
|
|
|
successFeedback: `"${ellipsis(props.item.title || props.item.name, feedbackCutoff)}" stashed to ${stash.name}`,
|
|
|
|
errorFeedback: `Failed to stash "${ellipsis(props.item.title || props.item.name, feedbackCutoff)}" to ${stash.name}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
emit('stashed', stash);
|
|
|
|
} catch (error) {
|
|
|
|
itemStashes.value = stashState;
|
|
|
|
}
|
|
|
|
|
|
|
|
done.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function unstashItem(stash) {
|
|
|
|
if (!done.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stashState = itemStashes.value;
|
|
|
|
|
|
|
|
done.value = false;
|
|
|
|
itemStashes.value = itemStashes.value.filter((itemStash) => itemStash.id !== stash.id);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await del(`/stashes/${stash.id}/${props.domain}/${props.item.id}`, {
|
|
|
|
undoFeedback: `"${ellipsis(props.item.title || props.item.name, feedbackCutoff)}" unstashed from ${stash.name}`,
|
|
|
|
errorFeedback: `Failed to unstash "${ellipsis(props.item.title || props.item.name, feedbackCutoff)}" from ${stash.name}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
emit('unstashed', stash);
|
|
|
|
} catch (error) {
|
|
|
|
itemStashes.value = stashState;
|
|
|
|
}
|
|
|
|
|
|
|
|
done.value = true;
|
|
|
|
}
|
2024-07-07 19:01:44 +00:00
|
|
|
|
|
|
|
function toggleShowStashes(state) {
|
|
|
|
if (props.showSecondary) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
showStashes.value = state;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showStashes.value = !showStashes.value;
|
|
|
|
}
|
2024-08-04 21:40:25 +00:00
|
|
|
|
|
|
|
async function reloadStashes() {
|
|
|
|
const profile = await get(`/users/${user.id}`);
|
|
|
|
|
|
|
|
console.log(profile);
|
|
|
|
}
|
2024-03-27 01:28:21 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.bookmarks {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
width: 1.5rem;
|
|
|
|
height: 1.5rem;
|
|
|
|
padding: .5rem .5rem;
|
2024-06-10 01:24:48 +00:00
|
|
|
fill: var(--glass);
|
2024-03-27 01:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.light .icon {
|
|
|
|
fill: var(--highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.tiled {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
fill: var(--highlight-strong-20);
|
|
|
|
filter: drop-shadow(0 0 3px var(--shadow-strong-10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon.heart:hover,
|
|
|
|
.icon.heart.favorited {
|
|
|
|
cursor: pointer;
|
|
|
|
fill: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|