firefish/packages/client/src/pages/note.vue

247 lines
5.3 KiB
Vue
Raw Normal View History

2023-07-20 04:17:05 +09:00
<template>
<MkStickyContainer>
<template #header
><MkPageHeader
:actions="headerActions"
:tabs="headerTabs"
:display-back-button="true"
:to="`#${noteId}`"
/></template>
2023-09-04 17:47:24 +09:00
<MkSpacer :content-max="800" :margin-min="6">
2023-07-20 04:17:05 +09:00
<div class="fcuexfpr">
<transition
2023-10-17 02:12:35 +09:00
:name="defaultStore.state.animation ? 'fade' : ''"
2023-07-20 04:17:05 +09:00
mode="out-in"
>
<div v-if="appearNote" class="note">
<div v-if="showNext" class="_gap">
<XNotes
class="_content"
:pagination="nextPagination"
:no-gap="true"
/>
</div>
<div class="main _gap">
<MkButton
v-if="!showNext && hasNext"
class="load next"
@click="showNext = true"
>
2023-10-17 02:12:35 +09:00
<i :class="icon('ph-caret-up')"></i>
2023-07-20 04:17:05 +09:00
{{ `${i18n.ts.loadMore} (${i18n.ts.newer})` }}
</MkButton>
<div class="note _gap">
<MkRemoteCaution
v-if="appearNote.user.host != null"
:href="appearNote.url ?? appearNote.uri"
/>
<XNoteDetailed
:key="appearNote.id"
v-model:note="appearNote"
class="note"
/>
</div>
<MkButton
v-if="!showPrev && hasPrev"
class="load prev"
@click="showPrev = true"
>
2023-10-17 02:12:35 +09:00
<i :class="icon('ph-caret-down')"></i>
2023-07-20 04:17:05 +09:00
{{ `${i18n.ts.loadMore} (${i18n.ts.older})` }}
</MkButton>
</div>
<div v-if="showPrev" class="_gap">
<XNotes
class="_content"
:pagination="prevPagination"
:no-gap="true"
/>
</div>
</div>
<MkError v-else-if="error" @retry="fetch()" />
<MkLoading v-else />
</transition>
</div>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
2023-09-04 17:47:24 +09:00
import { computed, ref, watch } from "vue";
2023-10-10 23:28:06 +09:00
import type * as firefish from "firefish-js";
2023-07-20 04:17:05 +09:00
import XNoteDetailed from "@/components/MkNoteDetailed.vue";
import XNotes from "@/components/MkNotes.vue";
import MkRemoteCaution from "@/components/MkRemoteCaution.vue";
import MkButton from "@/components/MkButton.vue";
import * as os from "@/os";
import { definePageMetadata } from "@/scripts/page-metadata";
import { i18n } from "@/i18n";
2023-09-15 02:08:23 +09:00
import { defaultStore } from "@/store";
import { $i } from "@/account";
2023-10-17 02:12:35 +09:00
import icon from "@/scripts/icon";
2023-07-20 04:17:05 +09:00
const props = defineProps<{
noteId: string;
}>();
2023-10-10 23:28:06 +09:00
const note = ref<null | firefish.entities.Note>();
2023-09-04 17:47:24 +09:00
const hasPrev = ref(false);
const hasNext = ref(false);
const showPrev = ref(false);
const showNext = ref(false);
const error = ref();
const isRenote = ref(false);
2023-10-10 23:28:06 +09:00
const appearNote = ref<null | firefish.entities.Note>();
2023-07-20 04:17:05 +09:00
const prevPagination = {
endpoint: "users/notes" as const,
limit: 10,
params: computed(() =>
2023-08-25 07:19:12 +09:00
appearNote.value
2023-07-20 04:17:05 +09:00
? {
2023-08-25 07:19:12 +09:00
userId: appearNote.value.userId,
untilId: appearNote.value.id,
2023-07-20 04:17:05 +09:00
}
: null,
),
};
const nextPagination = {
reversed: true,
endpoint: "users/notes" as const,
limit: 10,
params: computed(() =>
2023-08-25 07:19:12 +09:00
appearNote.value
2023-07-20 04:17:05 +09:00
? {
2023-08-25 07:19:12 +09:00
userId: appearNote.value.userId,
sinceId: appearNote.value.id,
2023-07-20 04:17:05 +09:00
}
: null,
),
};
function fetchNote() {
2023-08-25 07:19:12 +09:00
hasPrev.value = false;
hasNext.value = false;
showPrev.value = false;
showNext.value = false;
note.value = null;
2023-07-20 04:17:05 +09:00
os.api("notes/show", {
noteId: props.noteId,
})
.then((res) => {
2023-08-25 07:19:12 +09:00
note.value = res;
isRenote.value =
note.value.renote != null &&
note.value.text == null &&
note.value.fileIds.length === 0 &&
note.value.poll == null;
appearNote.value = isRenote.value
2023-10-10 23:28:06 +09:00
? (note.value.renote as firefish.entities.Note)
2023-08-25 07:19:12 +09:00
: note.value;
2023-07-20 04:17:05 +09:00
Promise.all([
os.api("users/notes", {
2023-08-25 07:19:12 +09:00
userId: note.value.userId,
untilId: note.value.id,
2023-07-20 04:17:05 +09:00
limit: 1,
}),
os.api("users/notes", {
2023-08-25 07:19:12 +09:00
userId: note.value.userId,
sinceId: note.value.id,
2023-07-20 04:17:05 +09:00
limit: 1,
}),
]).then(([prev, next]) => {
2023-08-25 07:19:12 +09:00
hasPrev.value = prev.length !== 0;
hasNext.value = next.length !== 0;
2023-07-20 04:17:05 +09:00
});
})
.catch((err) => {
2023-08-25 07:19:12 +09:00
error.value = err;
2023-07-20 04:17:05 +09:00
});
}
watch(() => props.noteId, fetchNote, {
immediate: true,
});
2023-08-25 07:19:12 +09:00
const headerActions = computed(() => []);
2023-07-20 04:17:05 +09:00
2023-08-25 07:19:12 +09:00
const headerTabs = computed(() => []);
2023-07-20 04:17:05 +09:00
definePageMetadata(
computed(() =>
2023-08-25 07:19:12 +09:00
appearNote.value
2023-07-20 04:17:05 +09:00
? {
2023-09-15 02:08:23 +09:00
title:
defaultStore.state.hideMyName &&
appearNote.value.userId === $i.id
? ""
: i18n.t("noteOf", {
user:
appearNote.value.user.name ||
appearNote.value.user.username,
}),
2023-08-25 07:19:12 +09:00
subtitle: new Date(
appearNote.value.createdAt,
).toLocaleString(),
avatar: appearNote.value.user,
path: `/notes/${appearNote.value.id}`,
2023-07-20 04:17:05 +09:00
share: {
title: i18n.t("noteOf", {
user:
2023-08-25 07:19:12 +09:00
appearNote.value.user.name ||
appearNote.value.user.username,
2023-07-20 04:17:05 +09:00
}),
2023-08-25 07:19:12 +09:00
text: appearNote.value.text,
2023-07-20 04:17:05 +09:00
},
}
: null,
),
);
</script>
<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.125s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.fcuexfpr {
#firefish_app > :not(.wallpaper) & {
background: var(--bg);
}
> .note {
> .main {
> .load {
min-width: 0;
margin: 0 auto;
border-radius: 999px;
&.next {
margin-bottom: var(--margin);
}
&.prev {
margin-top: var(--margin);
}
}
> .note {
> .note {
border-radius: var(--radius);
background: var(--panel);
}
}
}
}
}
</style>