2023-04-20 04:53:28 +02:00
|
|
|
<template>
|
|
|
|
<button
|
2023-09-02 01:27:33 +02:00
|
|
|
ref="buttonRef"
|
2023-04-20 04:53:28 +02:00
|
|
|
v-tooltip.noDelay.bottom="i18n.ts._gallery.like"
|
2023-09-17 23:59:09 +02:00
|
|
|
v-vibrate="[30, 50, 50]"
|
2023-05-24 02:30:55 +02:00
|
|
|
class="button _button"
|
2023-04-20 04:53:28 +02:00
|
|
|
:class="$style.root"
|
2023-07-16 23:24:34 +02:00
|
|
|
@click.stop="toggleStar($event)"
|
2023-04-20 04:53:28 +02:00
|
|
|
>
|
|
|
|
<span v-if="!reacted">
|
|
|
|
<i
|
|
|
|
v-if="instance.defaultReaction === '👍'"
|
|
|
|
class="ph-thumbs-up ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="instance.defaultReaction === '❤️'"
|
|
|
|
class="ph-heart ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i v-else class="ph-star ph-bold ph-lg"></i>
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
<i
|
|
|
|
v-if="instance.defaultReaction === '👍'"
|
|
|
|
class="ph-thumbs-up ph-bold ph-lg ph-fill"
|
|
|
|
:class="$style.yellow"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="instance.defaultReaction === '❤️'"
|
|
|
|
class="ph-heart ph-bold ph-lg ph-fill"
|
|
|
|
:class="$style.red"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else
|
|
|
|
class="ph-star ph-bold ph-lg ph-fill"
|
|
|
|
:class="$style.yellow"
|
|
|
|
></i>
|
|
|
|
</span>
|
|
|
|
<template v-if="count > 0"
|
2023-05-26 05:28:31 +02:00
|
|
|
><p class="count">{{ count }}</p></template
|
2023-04-20 04:53:28 +02:00
|
|
|
>
|
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from "vue";
|
2023-07-03 00:18:30 +02:00
|
|
|
import type { Note } from "firefish-js/built/entities";
|
2023-04-20 04:53:28 +02:00
|
|
|
import Ripple from "@/components/MkRipple.vue";
|
|
|
|
import XDetails from "@/components/MkUsersTooltip.vue";
|
|
|
|
import { pleaseLogin } from "@/scripts/please-login";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { instance } from "@/instance";
|
|
|
|
import { useTooltip } from "@/scripts/use-tooltip";
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
note: Note;
|
|
|
|
count: number;
|
|
|
|
reacted: boolean;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const buttonRef = ref<HTMLElement>();
|
|
|
|
|
|
|
|
function toggleStar(ev?: MouseEvent): void {
|
|
|
|
pleaseLogin();
|
|
|
|
|
|
|
|
if (!props.reacted) {
|
|
|
|
os.api("notes/reactions/create", {
|
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: instance.defaultReaction,
|
|
|
|
});
|
|
|
|
const el =
|
|
|
|
ev &&
|
|
|
|
((ev.currentTarget ?? ev.target) as HTMLElement | null | undefined);
|
|
|
|
if (el) {
|
|
|
|
const rect = el.getBoundingClientRect();
|
|
|
|
const x = rect.left + el.offsetWidth / 2;
|
|
|
|
const y = rect.top + el.offsetHeight / 2;
|
|
|
|
os.popup(Ripple, { x, y }, {}, "end");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os.api("notes/reactions/delete", {
|
|
|
|
noteId: props.note.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useTooltip(buttonRef, async (showing) => {
|
|
|
|
const reactions = await os.apiGet("notes/reactions", {
|
|
|
|
noteId: props.note.id,
|
|
|
|
limit: 11,
|
|
|
|
_cacheKey_: props.count,
|
|
|
|
});
|
|
|
|
|
|
|
|
const users = reactions.map((x) => x.user);
|
|
|
|
|
|
|
|
if (users.length < 1) return;
|
|
|
|
|
|
|
|
os.popup(
|
|
|
|
XDetails,
|
|
|
|
{
|
|
|
|
showing,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
targetElement: buttonRef.value,
|
|
|
|
},
|
|
|
|
{},
|
2023-07-06 03:28:27 +02:00
|
|
|
"closed",
|
2023-04-20 04:53:28 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.yellow {
|
|
|
|
color: var(--warn);
|
|
|
|
}
|
|
|
|
|
|
|
|
.red {
|
|
|
|
color: var(--error);
|
|
|
|
}
|
|
|
|
</style>
|