2019-02-06 18:05:49 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<button
|
|
|
|
v-if="count > 0"
|
|
|
|
ref="buttonRef"
|
|
|
|
v-ripple="canToggle"
|
|
|
|
class="hkzvhatu _button"
|
|
|
|
:class="{
|
|
|
|
reacted: note.myReaction == reaction,
|
|
|
|
canToggle,
|
|
|
|
newlyAdded: !isInitial,
|
|
|
|
}"
|
2023-07-16 23:24:34 +02:00
|
|
|
@click.stop="toggleReaction()"
|
2023-04-08 02:01:42 +02:00
|
|
|
>
|
|
|
|
<XReactionIcon
|
|
|
|
class="icon"
|
|
|
|
:reaction="reaction"
|
|
|
|
:custom-emojis="note.emojis"
|
|
|
|
/>
|
|
|
|
<span class="count">{{ count }}</span>
|
|
|
|
</button>
|
2019-02-06 18:05:49 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { computed, ref } from "vue";
|
2023-07-03 00:18:30 +02:00
|
|
|
import * as misskey from "firefish-js";
|
2023-04-08 02:01:42 +02:00
|
|
|
import XDetails from "@/components/MkReactionsViewer.details.vue";
|
|
|
|
import XReactionIcon from "@/components/MkReactionIcon.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { useTooltip } from "@/scripts/use-tooltip";
|
|
|
|
import { $i } from "@/account";
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
reaction: string;
|
|
|
|
count: number;
|
|
|
|
isInitial: boolean;
|
|
|
|
note: misskey.entities.Note;
|
|
|
|
}>();
|
|
|
|
|
2023-06-27 05:22:43 +02:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: "reacted", v): void;
|
|
|
|
}>();
|
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
const buttonRef = ref<HTMLElement>();
|
|
|
|
|
|
|
|
const canToggle = computed(() => !props.reaction.match(/@\w/) && $i);
|
|
|
|
|
|
|
|
const toggleReaction = () => {
|
|
|
|
if (!canToggle.value) return;
|
|
|
|
|
|
|
|
const oldReaction = props.note.myReaction;
|
|
|
|
if (oldReaction) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("notes/reactions/delete", {
|
2022-06-30 16:51:18 +02:00
|
|
|
noteId: props.note.id,
|
|
|
|
}).then(() => {
|
|
|
|
if (oldReaction !== props.reaction) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("notes/reactions/create", {
|
2021-11-12 15:53:10 +01:00
|
|
|
noteId: props.note.id,
|
2022-06-30 16:51:18 +02:00
|
|
|
reaction: props.reaction,
|
2019-02-06 18:05:49 +01:00
|
|
|
});
|
|
|
|
}
|
2021-11-12 15:53:10 +01:00
|
|
|
});
|
2022-06-30 16:51:18 +02:00
|
|
|
} else {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("notes/reactions/create", {
|
2022-06-30 16:51:18 +02:00
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction,
|
2021-11-12 15:53:10 +01:00
|
|
|
});
|
2023-06-27 05:22:43 +02:00
|
|
|
emit("reacted");
|
2022-06-30 16:51:18 +02:00
|
|
|
}
|
|
|
|
};
|
2021-11-12 15:53:10 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
useTooltip(
|
|
|
|
buttonRef,
|
|
|
|
async (showing) => {
|
|
|
|
const reactions = await os.apiGet("notes/reactions", {
|
|
|
|
noteId: props.note.id,
|
|
|
|
type: props.reaction,
|
|
|
|
limit: 11,
|
|
|
|
_cacheKey_: props.count,
|
|
|
|
});
|
|
|
|
|
|
|
|
const users = reactions.map((x) => x.user);
|
|
|
|
|
|
|
|
os.popup(
|
|
|
|
XDetails,
|
|
|
|
{
|
|
|
|
showing,
|
|
|
|
reaction: props.reaction,
|
|
|
|
emojis: props.note.emojis,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
targetElement: buttonRef.value,
|
|
|
|
},
|
|
|
|
{},
|
2023-07-06 03:28:27 +02:00
|
|
|
"closed",
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
|
|
|
},
|
2023-07-06 03:28:27 +02:00
|
|
|
100,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2019-02-06 18:05:49 +01:00
|
|
|
</script>
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<style lang="scss" scoped>
|
2020-02-21 22:43:46 +01:00
|
|
|
.hkzvhatu {
|
2023-07-16 23:24:34 +02:00
|
|
|
position: relative;
|
2020-01-29 20:37:25 +01:00
|
|
|
display: inline-block;
|
|
|
|
height: 32px;
|
2023-07-16 23:24:34 +02:00
|
|
|
margin-block: 2px;
|
|
|
|
padding: 0 8px;
|
2023-02-17 06:06:49 +01:00
|
|
|
pointer-events: all;
|
2023-06-27 05:22:43 +02:00
|
|
|
min-width: max-content;
|
2023-07-16 23:24:34 +02:00
|
|
|
&::before {
|
|
|
|
content: "";
|
|
|
|
position: absolute;
|
|
|
|
inset: 0 2px;
|
|
|
|
border-radius: 4px;
|
|
|
|
z-index: -1;
|
|
|
|
}
|
2023-02-25 21:36:35 +01:00
|
|
|
&.newlyAdded {
|
2023-04-08 02:01:42 +02:00
|
|
|
animation: scaleInSmall 0.3s cubic-bezier(0, 0, 0, 1.2);
|
2023-02-25 21:36:35 +01:00
|
|
|
:deep(.mk-emoji) {
|
2023-04-08 02:01:42 +02:00
|
|
|
animation: scaleIn 0.4s cubic-bezier(0.7, 0, 0, 1.5);
|
2023-02-25 21:36:35 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-25 19:50:24 +01:00
|
|
|
:deep(.mk-emoji) {
|
2023-04-08 02:01:42 +02:00
|
|
|
transition: transform 0.4s cubic-bezier(0, 0, 0, 6);
|
2023-02-25 19:50:24 +01:00
|
|
|
}
|
|
|
|
&.reacted :deep(.mk-emoji) {
|
2023-04-08 02:01:42 +02:00
|
|
|
transition: transform 0.4s cubic-bezier(0, 0, 0, 1);
|
2023-02-25 19:50:24 +01:00
|
|
|
}
|
|
|
|
&:active {
|
|
|
|
:deep(.mk-emoji) {
|
2023-04-08 02:01:42 +02:00
|
|
|
transition: transform 0.4s cubic-bezier(0, 0, 0, 1);
|
|
|
|
transform: scale(0.85);
|
2023-02-25 19:50:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-15 17:47:17 +02:00
|
|
|
&.canToggle {
|
2023-07-16 23:24:34 +02:00
|
|
|
&::before {
|
|
|
|
background: rgba(0, 0, 0, 0.05);
|
|
|
|
}
|
|
|
|
&:hover:not(.reacted)::before {
|
2020-04-15 17:47:17 +02:00
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2020-04-15 17:47:17 +02:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2020-04-15 17:47:17 +02:00
|
|
|
&.reacted {
|
2023-06-27 05:22:43 +02:00
|
|
|
order: -1;
|
2023-07-16 23:24:34 +02:00
|
|
|
&::before {
|
2020-04-17 13:30:12 +02:00
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
|
2022-05-19 16:23:12 +02:00
|
|
|
> .count {
|
2021-08-09 11:55:39 +02:00
|
|
|
color: var(--fgOnAccent);
|
2023-02-20 19:19:12 +01:00
|
|
|
font-weight: 600;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2022-05-19 16:23:12 +02:00
|
|
|
|
|
|
|
> .icon {
|
|
|
|
filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2022-05-19 16:23:12 +02:00
|
|
|
> .count {
|
2020-01-29 20:37:25 +01:00
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
2021-10-24 06:54:31 +02:00
|
|
|
margin: 0 0 0 4px;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
</style>
|