2019-02-07 02:05:49 +09:00
|
|
|
<template>
|
2020-02-22 06:43:46 +09:00
|
|
|
<button
|
2021-11-19 19:36:12 +09:00
|
|
|
ref="buttonRef"
|
2021-12-27 22:59:14 +09:00
|
|
|
v-ripple="canToggle"
|
2020-02-22 06:43:46 +09:00
|
|
|
class="hkzvhatu _button"
|
2020-07-27 23:25:37 +09:00
|
|
|
:class="{ reacted: note.myReaction == reaction, canToggle }"
|
2021-11-12 23:53:10 +09:00
|
|
|
@click="toggleReaction()"
|
2019-02-07 02:05:49 +09:00
|
|
|
>
|
2023-01-08 14:22:04 +09:00
|
|
|
<MkReactionIcon class="icon" :reaction="reaction"/>
|
2022-05-19 23:23:12 +09:00
|
|
|
<span class="count">{{ count }}</span>
|
2020-02-22 06:43:46 +09:00
|
|
|
</button>
|
2019-02-07 02:05:49 +09:00
|
|
|
</template>
|
|
|
|
|
2022-06-30 23:51:18 +09:00
|
|
|
<script lang="ts" setup>
|
2023-01-03 10:12:37 +09:00
|
|
|
import { computed, onMounted, ref, shallowRef, watch } from 'vue';
|
2022-06-30 23:51:18 +09:00
|
|
|
import * as misskey from 'misskey-js';
|
2022-08-31 00:24:33 +09:00
|
|
|
import XDetails from '@/components/MkReactionsViewer.details.vue';
|
2023-01-08 14:22:04 +09:00
|
|
|
import MkReactionIcon from '@/components/MkReactionIcon.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2021-11-12 23:53:10 +09:00
|
|
|
import { useTooltip } from '@/scripts/use-tooltip';
|
|
|
|
import { $i } from '@/account';
|
2023-01-01 12:28:30 +09:00
|
|
|
import MkPlusOneEffect from '@/components/MkPlusOneEffect.vue';
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2022-06-30 23:51:18 +09:00
|
|
|
const props = defineProps<{
|
|
|
|
reaction: string;
|
|
|
|
count: number;
|
|
|
|
isInitial: boolean;
|
|
|
|
note: misskey.entities.Note;
|
|
|
|
}>();
|
|
|
|
|
2023-01-03 10:12:37 +09:00
|
|
|
const buttonRef = shallowRef<HTMLElement>();
|
2022-06-30 23:51:18 +09:00
|
|
|
|
|
|
|
const canToggle = computed(() => !props.reaction.match(/@\w/) && $i);
|
|
|
|
|
|
|
|
const toggleReaction = () => {
|
|
|
|
if (!canToggle.value) return;
|
|
|
|
|
|
|
|
const oldReaction = props.note.myReaction;
|
|
|
|
if (oldReaction) {
|
|
|
|
os.api('notes/reactions/delete', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
}).then(() => {
|
|
|
|
if (oldReaction !== props.reaction) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('notes/reactions/create', {
|
2021-11-12 23:53:10 +09:00
|
|
|
noteId: props.note.id,
|
2022-06-30 23:51:18 +09:00
|
|
|
reaction: props.reaction,
|
2019-02-07 02:05:49 +09:00
|
|
|
});
|
|
|
|
}
|
2021-11-12 23:53:10 +09:00
|
|
|
});
|
2022-06-30 23:51:18 +09:00
|
|
|
} else {
|
|
|
|
os.api('notes/reactions/create', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction,
|
2021-11-12 23:53:10 +09:00
|
|
|
});
|
2022-06-30 23:51:18 +09:00
|
|
|
}
|
|
|
|
};
|
2021-11-12 23:53:10 +09:00
|
|
|
|
2022-06-30 23:51:18 +09:00
|
|
|
const anime = () => {
|
|
|
|
if (document.hidden) return;
|
|
|
|
|
2023-01-01 12:28:30 +09:00
|
|
|
const rect = buttonRef.value.getBoundingClientRect();
|
|
|
|
const x = rect.left + (buttonRef.value.offsetWidth / 2);
|
|
|
|
const y = rect.top + (buttonRef.value.offsetHeight / 2);
|
2023-01-07 17:37:30 +09:00
|
|
|
os.popup(MkPlusOneEffect, { reaction: props.reaction, x, y }, {}, 'end');
|
2022-06-30 23:51:18 +09:00
|
|
|
};
|
2021-11-12 23:53:10 +09:00
|
|
|
|
2022-06-30 23:51:18 +09:00
|
|
|
watch(() => props.count, (newCount, oldCount) => {
|
|
|
|
if (oldCount < newCount) anime();
|
2019-02-07 02:05:49 +09:00
|
|
|
});
|
2022-06-30 23:51:18 +09:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (!props.isInitial) anime();
|
|
|
|
});
|
|
|
|
|
|
|
|
useTooltip(buttonRef, async (showing) => {
|
2022-07-05 19:16:21 +09:00
|
|
|
const reactions = await os.apiGet('notes/reactions', {
|
2022-06-30 23:51:18 +09:00
|
|
|
noteId: props.note.id,
|
|
|
|
type: props.reaction,
|
|
|
|
limit: 11,
|
2022-07-05 19:16:21 +09:00
|
|
|
_cacheKey_: props.count,
|
2022-06-30 23:51:18 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const users = reactions.map(x => x.user);
|
|
|
|
|
|
|
|
os.popup(XDetails, {
|
|
|
|
showing,
|
|
|
|
reaction: props.reaction,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
targetElement: buttonRef.value,
|
|
|
|
}, {}, 'closed');
|
|
|
|
}, 100);
|
2019-02-07 02:05:49 +09:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 18:29:39 +09:00
|
|
|
<style lang="scss" scoped>
|
2020-02-22 06:43:46 +09:00
|
|
|
.hkzvhatu {
|
2020-01-30 04:37:25 +09:00
|
|
|
display: inline-block;
|
|
|
|
height: 32px;
|
|
|
|
margin: 2px;
|
|
|
|
padding: 0 6px;
|
|
|
|
border-radius: 4px;
|
2019-09-03 06:20:04 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&.canToggle {
|
|
|
|
background: rgba(0, 0, 0, 0.05);
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2020-04-16 00:47:17 +09:00
|
|
|
&.reacted {
|
|
|
|
background: var(--accent);
|
|
|
|
|
2020-04-17 20:30:12 +09:00
|
|
|
&:hover {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
|
2022-05-19 23:23:12 +09:00
|
|
|
> .count {
|
2021-08-09 18:55:39 +09:00
|
|
|
color: var(--fgOnAccent);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2022-05-19 23:23:12 +09:00
|
|
|
|
|
|
|
> .icon {
|
|
|
|
filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
|
2022-05-19 23:23:12 +09:00
|
|
|
> .count {
|
2020-01-30 04:37:25 +09:00
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
2021-10-24 13:54:31 +09:00
|
|
|
margin: 0 0 0 4px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 02:05:49 +09:00
|
|
|
</style>
|