summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/page/page.note.vue
blob: 543e9afdaf189278d909adb23b9a1f4ddd993957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root">
	<MkNote v-if="note && !block.detailed" :key="note.id + ':normal'" :note="note"/>
	<MkNoteDetailed v-if="note && block.detailed" :key="note.id + ':detail'" :note="note"/>
</div>
</template>

<script lang="ts" setup>
import { onMounted, onUnmounted, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { retryOnThrottled } from '@@/js/retry-on-throttled.js';
import MkNote from '@/components/MkNote.vue';
import MkNoteDetailed from '@/components/MkNoteDetailed.vue';
import { misskeyApi } from '@/utility/misskey-api.js';

const props = defineProps<{
	block: Misskey.entities.PageBlock,
	page: Misskey.entities.Page,
	index: number;
}>();

const note = ref<Misskey.entities.Note | null>(null);

// eslint-disable-next-line id-denylist
let timeoutId: ReturnType<typeof window.setTimeout> | null = null;

onMounted(() => {
	if (props.block.note == null) return;
	timeoutId = window.setTimeout(async () => {
		note.value = await retryOnThrottled(() => misskeyApi('notes/show', { noteId: props.block.note }));
	}, 500 * props.index); // rate limit is 2 reqs per sec
});

onUnmounted(() => {
	if (timeoutId !== null) {
		window.clearTimeout(timeoutId);
	}
});
</script>

<style lang="scss" module>
.root {
	border: 1px solid var(--MI_THEME-divider);
	border-radius: var(--MI-radius);
}
</style>