traxxx-web/components/actors/tile.vue

275 lines
5.1 KiB
Vue
Raw Normal View History

<template>
2024-03-21 01:54:05 +00:00
<div
class="tile"
:class="{
unstashed: !favorited && pageStash && user && pageStash.id === user.primaryStash?.id
}"
>
<span class="name">{{ actor.name }}</span>
2024-03-21 01:54:05 +00:00
<div class="avatar-container">
<Link
:href="`/actor/${actor.id}/${actor.slug}`"
class="avatar-link no-link"
>
2024-03-21 01:54:05 +00:00
<img
v-if="actor.avatar"
:src="actor.avatar.isS3 ? `https://cdndev.traxxx.me/${actor.avatar.thumbnail}` : `/media/${actor.avatar.thumbnail}`"
:style="{ 'background-image': actor.avatar.isS3 ? `url(https://cdndev.traxxx.me/${actor.avatar.lazy})` : `url(/media/${actor.avatar.lazy})` }"
loading="lazy"
class="avatar"
>
2024-03-23 21:44:49 +00:00
<img
v-else
:src="`/img/avatars/${actor.gender || 'female'}.svg`"
loading="lazy"
class="fallback"
>
2024-03-21 01:54:05 +00:00
</Link>
<Icon
v-show="favorited"
icon="heart7"
class="heart favorited"
@click.native.stop="unstash"
/>
<Icon
v-show="!favorited && user"
icon="heart8"
class="heart"
@click.native.stop="stash"
/>
</div>
<div class="details">
<span class="birth">
<Gender :gender="actor.gender" />
<span
v-if="actor.ageFromBirth"
:title="`Born ${formatDate(actor.dateOfBirth, 'MMMM d, yyyy')}`"
class="age"
>{{ actor.ageFromBirth }}</span>
<span
v-if="actor.ageThen && actor.ageThen < actor.ageFromBirth"
title="Age on date of release"
class="age age-then"
>{{ actor.ageThen }}</span>
</span>
<span
v-if="actor.origin?.country"
:title="`Born in ${actor.origin.country.name}`"
class="country"
>
{{ actor.origin.country.alpha2 }}
<img
:src="`/img/flags/${actor.origin.country.alpha2.toLowerCase()}.svg`"
class="flag"
>
</span>
</div>
</div>
</template>
<script setup>
2024-03-21 01:54:05 +00:00
import { ref, inject } from 'vue';
import { formatDate } from '#/utils/format.js';
2024-03-21 01:54:05 +00:00
import { post, del } from '#/src/api.js';
import events from '#/src/events.js';
import Gender from './gender.vue';
2024-03-21 01:54:05 +00:00
const props = defineProps({
actor: {
type: Object,
default: null,
},
});
2024-03-21 01:54:05 +00:00
const pageContext = inject('pageContext');
const { user } = pageContext;
const pageStash = pageContext.pageProps.stash;
// console.log(props.actor);
const favorited = ref(props.actor.stashes?.some((sceneStash) => sceneStash.primary) || false);
async function stash() {
try {
favorited.value = true;
await post(`/stashes/${user.primaryStash.id}/actors`, { actorId: props.actor.id });
events.emit('feedback', {
type: 'success',
message: `${props.actor.name} stashed to ${user.primaryStash.name}`,
});
} catch (error) {
favorited.value = false;
events.emit('feedback', {
type: 'error',
message: `Failed to stash ${props.actor.name} to ${user.primaryStash.name}`,
});
}
}
async function unstash() {
try {
favorited.value = false;
await del(`/stashes/${user.primaryStash.id}/actors/${props.actor.id}`);
events.emit('feedback', {
type: 'remove',
message: `${props.actor.name} unstashed from ${user.primaryStash.name}`,
});
} catch (error) {
favorited.value = true;
console.error(error);
events.emit('feedback', {
type: 'error',
message: `Failed to unstash ${props.actor.name} from ${user.primaryStash.name}`,
});
}
}
</script>
<style scoped>
2024-03-21 01:54:05 +00:00
.tile {
display: flex;
flex-direction: column;
2024-01-04 00:49:16 +00:00
width: 100%;
aspect-ratio: 2/3;
position: relative;
border-radius: .25rem;
box-shadow: 0 0 3px var(--shadow-weak-30);
2024-01-04 00:49:16 +00:00
overflow: hidden;
&:hover {
box-shadow: 0 0 3px var(--shadow-weak-20);
.name {
color: var(--primary);
}
}
2024-03-21 01:54:05 +00:00
&.unstashed {
opacity: .5;
}
}
.name {
flex-shrink: 0;
padding: .25rem .5rem;
font-weight: bold;
font-size: .9rem;
2024-01-04 00:49:16 +00:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
user-select: all;
}
2024-03-21 01:54:05 +00:00
.avatar-container {
position: relative;
flex-grow: 1;
2024-03-23 21:44:49 +00:00
overflow: hidden;
background: var(--grey-dark-40);
2024-03-21 01:54:05 +00:00
}
.avatar-link {
2024-03-21 01:54:05 +00:00
height: 100%;
display: block;
overflow: hidden;
}
.avatar {
height: 100%;
width: 100%;
object-fit: cover;
object-position: center 0;
background-size: cover;
background-position: center 0;
}
2024-03-23 21:44:49 +00:00
.fallback {
height: 100%;
width: 100%;
display: block;
object-fit: contain;
opacity: .1;
}
2024-03-21 01:54:05 +00:00
.icon.heart {
width: 2rem;
height: 1.5rem;
position: absolute;
top: 0;
right: 0;
padding: .5rem .5rem 1rem 1rem;
fill: var(--highlight-strong-10);
filter: drop-shadow(0 0 3px var(--shadow));
&:hover {
cursor: pointer;
fill: var(--primary);
}
&.favorited {
fill: var(--primary);
}
}
.details {
width: 100%;
height: 1.5rem;
display: flex;
justify-content: space-between;
align-items: center;
position: absolute;
bottom: 0;
box-sizing: border-box;
padding: 0 .5rem;
color: var(--text-light);
background: var(--shadow);
font-size: .9rem;
font-weight: bold;
}
.gender {
display: inline-block;
padding: .25rem 0;
margin-right: .25rem;
transform: translateY(1px);
}
.birth {
display: flex;
align-items: center;
}
.age {
margin-right: .25rem;
}
.age-then {
color: var(--grey-light-20);
font-weight: normal;
}
.country {
display: flex;
align-items: center;
}
.flag {
height: .75rem;
margin-left: .25rem;
}
</style>