hippofish/packages/client/src/components/MkReactedUsers.vue

95 lines
1.8 KiB
Vue
Raw Normal View History

2023-05-20 06:14:14 +02:00
<template>
2023-06-20 16:30:13 +02:00
<div v-if="note" class="reacted-users">
2023-05-20 06:41:42 +02:00
<div :class="$style.tabs">
<button
v-for="reaction in reactions"
:key="reaction"
2023-05-20 08:27:56 +02:00
:class="[$style.tab, { [$style.tabActive]: tab === reaction }]"
2023-05-20 06:41:42 +02:00
class="_button"
@click="tab = reaction"
>
<MkReactionIcon
ref="reactionRef"
:reaction="
reaction
2023-05-20 08:27:56 +02:00
? reaction.replace(/^:(\w+):$/, ':$1@.:')
2023-05-20 06:41:42 +02:00
: reaction
"
:custom-emojis="note.emojis"
style="max-width: 100%"
2023-05-20 06:41:42 +02:00
/>
<span style="margin-left: 4px">{{
note.reactions[reaction]
}}</span>
</button>
2023-05-20 06:14:14 +02:00
</div>
2023-05-20 06:41:42 +02:00
<MkUserCardMini
v-for="user in users"
:key="user.id"
:user="user"
2023-05-20 08:27:56 +02:00
:with-chart="false"
2023-05-20 06:41:42 +02:00
/>
2023-05-20 06:14:14 +02:00
</div>
<div v-else>
<MkLoading />
</div>
</template>
<script lang="ts" setup>
2023-09-02 01:27:33 +02:00
import { onMounted, ref, watch } from "vue";
import type { entities } from "firefish-js";
2023-05-20 06:14:14 +02:00
import MkReactionIcon from "@/components/MkReactionIcon.vue";
import MkUserCardMini from "@/components/MkUserCardMini.vue";
import * as os from "@/os";
const props = defineProps<{
noteId: entities.Note["id"];
2023-05-20 06:14:14 +02:00
}>();
const note = ref<entities.Note>();
const tab = ref<string | null>(null);
2023-09-02 01:27:33 +02:00
const reactions = ref<string[]>();
const users = ref();
2023-05-20 06:14:14 +02:00
async function updateUsers(): void {
2023-05-20 06:14:14 +02:00
const res = await os.api("notes/reactions", {
noteId: props.noteId,
type: tab.value,
2023-05-20 06:14:14 +02:00
limit: 30,
});
users.value = res.map((x) => x.user);
}
watch(tab, updateUsers);
2023-05-20 06:14:14 +02:00
onMounted(() => {
os.api("notes/show", {
noteId: props.noteId,
}).then(async (res) => {
reactions.value = Object.keys(res.reactions);
note.value = res;
await updateUsers();
2023-05-20 06:14:14 +02:00
});
});
</script>
<style lang="scss" module>
.tabs {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.tab {
padding: 4px 6px;
border: solid 1px var(--divider);
border-radius: 6px;
max-width: 50%;
2023-05-20 06:14:14 +02:00
}
.tabActive {
border-color: var(--accent);
}
</style>