Merge branch 'refactor/split-mknote' into 'develop'
refactor: split MkNote into smaller components Co-authored-by: Lhcfl <Lhcfl@outlook.com> See merge request firefish/firefish!10899
This commit is contained in:
commit
97dfb8d2aa
17 changed files with 865 additions and 984 deletions
|
@ -10,10 +10,12 @@
|
||||||
:aria-label="accessibleLabel"
|
:aria-label="accessibleLabel"
|
||||||
class="tkcbzcuz note-container"
|
class="tkcbzcuz note-container"
|
||||||
:tabindex="!isDeleted ? '-1' : undefined"
|
:tabindex="!isDeleted ? '-1' : undefined"
|
||||||
:class="{ renote: isRenote || (renotesSliced && renotesSliced.length > 0) }"
|
:class="{ renote: isRenote || (renotes && renotes.length > 0) }"
|
||||||
>
|
>
|
||||||
<MkNoteSub
|
<MkNoteSub
|
||||||
v-if="appearNote.reply && !detailedView && !collapsedReply && !parents"
|
v-if="
|
||||||
|
appearNote.reply && !detailedView && !collapsedReply && !parents
|
||||||
|
"
|
||||||
:note="appearNote.reply"
|
:note="appearNote.reply"
|
||||||
class="reply-to"
|
class="reply-to"
|
||||||
/>
|
/>
|
||||||
|
@ -32,106 +34,11 @@
|
||||||
}"
|
}"
|
||||||
@click="noteClick"
|
@click="noteClick"
|
||||||
>
|
>
|
||||||
<div v-if="!collapsedReply" class="line"></div>
|
<XNoteHeaderInfo v-bind="{ appearNote, note, collapsedReply, pinned }" />
|
||||||
<div v-if="appearNote._prId_" class="info">
|
<XRenoteBar
|
||||||
<i :class="icon('ph-megaphone-simple-bold')"></i>
|
v-bind="{ appearNote, note, isRenote, renotes }"
|
||||||
{{ i18n.ts.promotion
|
@deleted="isDeleted = true"
|
||||||
}}<button class="_textButton hide" @click.stop="readPromo()">
|
/>
|
||||||
{{ i18n.ts.hideThisNote }}
|
|
||||||
<i :class="icon('ph-x')"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div v-if="appearNote._featuredId_" class="info">
|
|
||||||
<i :class="icon('ph-lightning')"></i>
|
|
||||||
{{ i18n.ts.featured }}
|
|
||||||
</div>
|
|
||||||
<div v-if="pinned" class="info">
|
|
||||||
<i :class="icon('ph-push-pin')"></i>{{ i18n.ts.pinnedNote }}
|
|
||||||
</div>
|
|
||||||
<div v-if="collapsedReply && appearNote.reply" class="info">
|
|
||||||
<MkAvatar class="avatar" :user="appearNote.reply.user" />
|
|
||||||
<MkUserName
|
|
||||||
class="username"
|
|
||||||
:user="appearNote.reply.user"
|
|
||||||
></MkUserName>
|
|
||||||
<Mfm
|
|
||||||
class="summary"
|
|
||||||
:text="getNoteSummary(appearNote.reply)"
|
|
||||||
:plain="true"
|
|
||||||
:nowrap="true"
|
|
||||||
:lang="appearNote.reply.lang"
|
|
||||||
:custom-emojis="note.emojis"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div v-if="isRenote || (renotesSliced && renotesSliced.length > 0)" class="renote">
|
|
||||||
<i :class="icon('ph-rocket-launch')"></i>
|
|
||||||
<I18n
|
|
||||||
v-if="renotesSliced == null"
|
|
||||||
:src="i18n.ts.renotedBy"
|
|
||||||
tag="span"
|
|
||||||
>
|
|
||||||
<template #user>
|
|
||||||
<MkAvatar class="avatar" :user="note.user" />
|
|
||||||
<MkA
|
|
||||||
v-user-preview="note.userId"
|
|
||||||
class="name"
|
|
||||||
:to="userPage(note.user)"
|
|
||||||
@click.stop
|
|
||||||
>
|
|
||||||
<MkUserName :user="note.user" />
|
|
||||||
</MkA>
|
|
||||||
</template>
|
|
||||||
</I18n>
|
|
||||||
<I18n
|
|
||||||
v-else
|
|
||||||
:src="i18n.ts.renotedBy"
|
|
||||||
tag="span"
|
|
||||||
>
|
|
||||||
<template #user>
|
|
||||||
<template
|
|
||||||
v-for="(renote, index) in renotesSliced"
|
|
||||||
>
|
|
||||||
<MkAvatar
|
|
||||||
class="avatar"
|
|
||||||
:user="renote.user"
|
|
||||||
/>
|
|
||||||
<MkA
|
|
||||||
v-user-preview="renote.userId"
|
|
||||||
class="name"
|
|
||||||
:to="userPage(renote.user)"
|
|
||||||
@click.stop
|
|
||||||
>
|
|
||||||
<MkUserName :user="renote.user" />
|
|
||||||
</MkA>
|
|
||||||
{{
|
|
||||||
index !== renotesSliced.length - 1
|
|
||||||
? ", "
|
|
||||||
: renotesSliced.length < renotes!.length
|
|
||||||
? "..."
|
|
||||||
: ""
|
|
||||||
}}
|
|
||||||
</template>
|
|
||||||
</template>
|
|
||||||
</I18n>
|
|
||||||
<div class="info">
|
|
||||||
<button
|
|
||||||
ref="renoteTime"
|
|
||||||
class="_button time"
|
|
||||||
@click.stop="showRenoteMenu()"
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
v-if="isMyNote"
|
|
||||||
:class="icon('ph-dots-three-outline dropdownIcon')"
|
|
||||||
></i>
|
|
||||||
<MkTime
|
|
||||||
v-if="(renotesSliced && renotesSliced.length > 0)"
|
|
||||||
:time="renotesSliced[0].createdAt"
|
|
||||||
/>
|
|
||||||
<MkTime v-else :time="note.createdAt" />
|
|
||||||
</button>
|
|
||||||
<MkVisibility :note="note" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<article
|
<article
|
||||||
class="article"
|
class="article"
|
||||||
|
@ -154,7 +61,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<MkSubNoteContent
|
<XNoteContent
|
||||||
class="text"
|
class="text"
|
||||||
:note="appearNote"
|
:note="appearNote"
|
||||||
:detailed="true"
|
:detailed="true"
|
||||||
|
@ -164,148 +71,22 @@
|
||||||
@push="(e) => router.push(notePage(e))"
|
@push="(e) => router.push(notePage(e))"
|
||||||
@focusfooter="footerEl!.focus()"
|
@focusfooter="footerEl!.focus()"
|
||||||
@expanded="(e) => setPostExpanded(e)"
|
@expanded="(e) => setPostExpanded(e)"
|
||||||
></MkSubNoteContent>
|
></XNoteContent>
|
||||||
<div v-if="translating || translation" class="translation">
|
<XNoteTranslation ref="noteTranslation" :note="note"/>
|
||||||
<MkLoading v-if="translating" mini />
|
|
||||||
<div v-else-if="translation != null" class="translated">
|
|
||||||
<b
|
|
||||||
>{{
|
|
||||||
i18n.t("translatedFrom", {
|
|
||||||
x: translation.sourceLang,
|
|
||||||
})
|
|
||||||
}}:
|
|
||||||
</b>
|
|
||||||
<Mfm
|
|
||||||
:text="translation.text"
|
|
||||||
:author="appearNote.user"
|
|
||||||
:i="me"
|
|
||||||
:lang="targetLang"
|
|
||||||
:custom-emojis="appearNote.emojis"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<XNoteFooterInfo class="info" :note="appearNote" :detailedView />
|
||||||
v-if="detailedView || (appearNote.channel && !inChannel)"
|
<XNoteFooter
|
||||||
class="info"
|
|
||||||
>
|
|
||||||
<MkA
|
|
||||||
v-if="detailedView"
|
|
||||||
class="created-at"
|
|
||||||
:to="notePage(appearNote)"
|
|
||||||
>
|
|
||||||
<MkTime v-if="appearNote.scheduledAt != null" :time="appearNote.scheduledAt"/>
|
|
||||||
<MkTime v-else :time="appearNote.createdAt" mode="absolute" />
|
|
||||||
</MkA>
|
|
||||||
<MkA
|
|
||||||
v-if="appearNote.channel && !inChannel"
|
|
||||||
class="channel"
|
|
||||||
:to="`/channels/${appearNote.channel.id}`"
|
|
||||||
@click.stop
|
|
||||||
><i :class="icon('ph-television', false)"></i>
|
|
||||||
{{ appearNote.channel.name }}</MkA
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<footer
|
|
||||||
v-show="!hideFooter"
|
|
||||||
ref="footerEl"
|
|
||||||
class="footer"
|
class="footer"
|
||||||
tabindex="-1"
|
ref="footerEl"
|
||||||
>
|
:note="appearNote"
|
||||||
<XReactionsViewer
|
:enableEmojiReactions
|
||||||
v-if="enableEmojiReactions && !hideEmojiViewer"
|
:hideEmojiViewer
|
||||||
ref="reactionsViewer"
|
:detailedView
|
||||||
:note="appearNote"
|
:note-translation="noteTranslation!"
|
||||||
/>
|
@deleted="isDeleted = true"
|
||||||
<button
|
@event:focus="focus"
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.reply"
|
@event:blur="blur"
|
||||||
class="button _button"
|
/>
|
||||||
@click.stop="reply()"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-arrow-u-up-left')"></i>
|
|
||||||
<template
|
|
||||||
v-if="appearNote.repliesCount > 0 && !detailedView"
|
|
||||||
>
|
|
||||||
<p class="count">{{ appearNote.repliesCount }}</p>
|
|
||||||
</template>
|
|
||||||
</button>
|
|
||||||
<XRenoteButton
|
|
||||||
ref="renoteButton"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
:count="appearNote.renoteCount"
|
|
||||||
:detailed-view="detailedView"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
/>
|
|
||||||
<XStarButtonNoEmoji
|
|
||||||
v-if="!enableEmojiReactions"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
:count="reactionCount"
|
|
||||||
:reacted="appearNote.myReaction != null"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
/>
|
|
||||||
<XStarButton
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction == null
|
|
||||||
"
|
|
||||||
ref="starButton"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction == null
|
|
||||||
"
|
|
||||||
ref="reactButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.reaction"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="react()"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-smiley')"></i>
|
|
||||||
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">{{reactionCount}}</p>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction != null
|
|
||||||
"
|
|
||||||
ref="reactButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.removeReaction"
|
|
||||||
class="button _button reacted"
|
|
||||||
@click.stop="undoReact(appearNote)"
|
|
||||||
:disabled="note.scheduledAt != null"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-minus')"></i>
|
|
||||||
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">{{reactionCount}}</p>
|
|
||||||
</button>
|
|
||||||
<XQuoteButton class="button" :note="appearNote" :disabled="note.scheduledAt != null"/>
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
isSignedIn(me) &&
|
|
||||||
isForeignLanguage &&
|
|
||||||
translation == null
|
|
||||||
"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.translate"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="translate"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-translate')"></i>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
ref="menuButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.more"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="menu()"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-dots-three-outline')"></i>
|
|
||||||
</button>
|
|
||||||
</footer>
|
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
@ -333,39 +114,29 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, onMounted, ref, watch } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
import type { Ref } from "vue";
|
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import MkSubNoteContent from "./MkSubNoteContent.vue";
|
import XNoteContent from "@/components/note/MkNoteContent.vue";
|
||||||
import MkNoteSub from "@/components/MkNoteSub.vue";
|
import MkNoteSub from "@/components/MkNoteSub.vue";
|
||||||
import XNoteHeader from "@/components/MkNoteHeader.vue";
|
import XNoteHeader from "@/components/note/MkNoteHeader.vue";
|
||||||
import XRenoteButton from "@/components/MkRenoteButton.vue";
|
|
||||||
import XReactionsViewer from "@/components/MkReactionsViewer.vue";
|
|
||||||
import XStarButton from "@/components/MkStarButton.vue";
|
|
||||||
import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
|
|
||||||
import XQuoteButton from "@/components/MkQuoteButton.vue";
|
|
||||||
import MkVisibility from "@/components/MkVisibility.vue";
|
|
||||||
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
|
||||||
import { detectLanguage } from "@/scripts/language-utils";
|
|
||||||
import { url } from "@/config";
|
|
||||||
import { pleaseLogin } from "@/scripts/please-login";
|
|
||||||
import { focusNext, focusPrev } from "@/scripts/focus";
|
import { focusNext, focusPrev } from "@/scripts/focus";
|
||||||
import { getWordSoftMute } from "@/scripts/check-word-mute";
|
import { getWordSoftMute } from "@/scripts/check-word-mute";
|
||||||
import { useRouter } from "@/router";
|
import { useRouter } from "@/router";
|
||||||
import { userPage } from "@/filters/user";
|
import { userPage } from "@/filters/user";
|
||||||
import * as os from "@/os";
|
|
||||||
import { defaultStore, noteViewInterruptors } from "@/store";
|
import { defaultStore, noteViewInterruptors } from "@/store";
|
||||||
import { reactionPicker } from "@/scripts/reaction-picker";
|
import { me } from "@/me";
|
||||||
import { isSignedIn, me } from "@/me";
|
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { getNoteMenu } from "@/scripts/get-note-menu";
|
|
||||||
import { useNoteCapture } from "@/scripts/use-note-capture";
|
import { useNoteCapture } from "@/scripts/use-note-capture";
|
||||||
import { notePage } from "@/filters/note";
|
import { notePage } from "@/filters/note";
|
||||||
import { deepClone } from "@/scripts/clone";
|
import { deepClone } from "@/scripts/clone";
|
||||||
import { getNoteSummary } from "@/scripts/get-note-summary";
|
import type { NoteType } from "@/types/note";
|
||||||
import icon from "@/scripts/icon";
|
|
||||||
import type { NoteTranslation, NoteType } from "@/types/note";
|
|
||||||
import { isDeleted as _isDeleted, isRenote as _isRenote } from "@/scripts/note";
|
import { isDeleted as _isDeleted, isRenote as _isRenote } from "@/scripts/note";
|
||||||
|
import XNoteHeaderInfo from "@/components/note/MkNoteHeaderInfo.vue";
|
||||||
|
import XNoteFooterInfo from "@/components/note/MkNoteFooterInfo.vue";
|
||||||
|
import XRenoteBar from "@/components/note/MkRenoteBar.vue";
|
||||||
|
import XNoteFooter from "./note/MkNoteFooter.vue";
|
||||||
|
import XNoteTranslation from "./note/MkNoteTranslation.vue";
|
||||||
|
import { showNoteContextMenu } from "@/scripts/show-note-context-menu";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
note: NoteType;
|
note: NoteType;
|
||||||
|
@ -381,42 +152,28 @@ const props = defineProps<{
|
||||||
|
|
||||||
// #region Constants
|
// #region Constants
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const inChannel = inject("inChannel", null);
|
|
||||||
const keymap = {
|
const keymap = {
|
||||||
r: () => reply(true),
|
r: () => footerEl.value!.reply(true),
|
||||||
"e|a|plus": () => react(true),
|
"e|a|plus": () => footerEl.value!.react(true),
|
||||||
q: () => renoteButton.value!.renote(true),
|
q: () => footerEl.value!.renote(true),
|
||||||
"up|k": focusBefore,
|
"up|k": focusBefore,
|
||||||
"down|j": focusAfter,
|
"down|j": focusAfter,
|
||||||
esc: blur,
|
esc: blur,
|
||||||
"m|o": () => menu(true),
|
"m|o": () => footerEl.value!.menu(true),
|
||||||
// FIXME: What's this?
|
// FIXME: What's this?
|
||||||
// s: () => showContent.value !== showContent.value,
|
// s: () => showContent.value !== showContent.value,
|
||||||
};
|
};
|
||||||
const el = ref<HTMLElement | null>(null);
|
const el = ref<HTMLElement | null>(null);
|
||||||
const footerEl = ref<HTMLElement>();
|
const footerEl = ref<InstanceType<typeof XNoteFooter> | null>(null);
|
||||||
const menuButton = ref<HTMLElement>();
|
|
||||||
const starButton = ref<InstanceType<typeof XStarButton>>();
|
|
||||||
const renoteButton = ref<InstanceType<typeof XRenoteButton> | null>(null);
|
|
||||||
const renoteTime = ref<HTMLElement>();
|
|
||||||
const reactButton = ref<HTMLElement | null>(null);
|
|
||||||
const enableEmojiReactions = defaultStore.reactiveState.enableEmojiReactions;
|
const enableEmojiReactions = defaultStore.reactiveState.enableEmojiReactions;
|
||||||
const expandOnNoteClick = defaultStore.reactiveState.expandOnNoteClick;
|
const expandOnNoteClick = defaultStore.reactiveState.expandOnNoteClick;
|
||||||
const lang = localStorage.getItem("lang");
|
const noteTranslation = ref<InstanceType<typeof XNoteTranslation> | null>(null);
|
||||||
const translateLang = localStorage.getItem("translateLang");
|
|
||||||
const targetLang = (translateLang || lang || navigator.language)?.slice(0, 2);
|
|
||||||
const currentClipPage = inject<Ref<entities.Clip> | null>(
|
|
||||||
"currentClipPage",
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Variables bound to Notes
|
// #region Variables bound to Notes
|
||||||
let capture: ReturnType<typeof useNoteCapture> | undefined;
|
let capture: ReturnType<typeof useNoteCapture> | undefined;
|
||||||
const note = ref(deepClone(props.note));
|
const note = ref(deepClone(props.note));
|
||||||
const postIsExpanded = ref(false);
|
const postIsExpanded = ref(false);
|
||||||
const translation = ref<NoteTranslation | null>(null);
|
|
||||||
const translating = ref(false);
|
|
||||||
const isDeleted = ref(false);
|
const isDeleted = ref(false);
|
||||||
const renotes = ref(props.renotes?.filter((rn) => !_isDeleted(rn.id)));
|
const renotes = ref(props.renotes?.filter((rn) => !_isDeleted(rn.id)));
|
||||||
const muted = ref(
|
const muted = ref(
|
||||||
|
@ -430,31 +187,10 @@ const muted = ref(
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region computed
|
// #region computed
|
||||||
|
|
||||||
const renotesSliced = computed(() => renotes.value?.slice(0, 5));
|
|
||||||
|
|
||||||
const isRenote = computed(() => _isRenote(note.value));
|
const isRenote = computed(() => _isRenote(note.value));
|
||||||
const appearNote = computed(() =>
|
const appearNote = computed(() =>
|
||||||
isRenote.value ? (note.value.renote as NoteType) : note.value,
|
isRenote.value ? (note.value.renote as NoteType) : note.value,
|
||||||
);
|
);
|
||||||
const isMyNote = computed(
|
|
||||||
() => isSignedIn(me) && me.id === note.value.userId && props.renotes == null,
|
|
||||||
);
|
|
||||||
const isForeignLanguage = computed(
|
|
||||||
() =>
|
|
||||||
defaultStore.state.detectPostLanguage &&
|
|
||||||
appearNote.value.text != null &&
|
|
||||||
(() => {
|
|
||||||
const postLang = detectLanguage(appearNote.value.text);
|
|
||||||
return postLang !== "" && postLang !== targetLang;
|
|
||||||
})(),
|
|
||||||
);
|
|
||||||
const reactionCount = computed(() =>
|
|
||||||
Object.values(appearNote.value.reactions).reduce(
|
|
||||||
(partialSum, val) => partialSum + val,
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const accessibleLabel = computed(() => {
|
const accessibleLabel = computed(() => {
|
||||||
let label = `${appearNote.value.user.username}; `;
|
let label = `${appearNote.value.user.username}; `;
|
||||||
if (appearNote.value.renote) {
|
if (appearNote.value.renote) {
|
||||||
|
@ -507,9 +243,6 @@ async function init(newNote: NoteType, first = false) {
|
||||||
note.value = deepClone(newNote);
|
note.value = deepClone(newNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translation.value = null;
|
|
||||||
translating.value = false;
|
|
||||||
postIsExpanded.value = false;
|
postIsExpanded.value = false;
|
||||||
isDeleted.value = _isDeleted(note.value.id);
|
isDeleted.value = _isDeleted(note.value.id);
|
||||||
if (appearNote.value.historyId == null) {
|
if (appearNote.value.historyId == null) {
|
||||||
|
@ -574,33 +307,6 @@ watch(
|
||||||
);
|
);
|
||||||
watch(() => props.renotes?.length, recalculateRenotes);
|
watch(() => props.renotes?.length, recalculateRenotes);
|
||||||
|
|
||||||
async function translate_(noteId: string, targetLang: string) {
|
|
||||||
return await os.api("notes/translate", {
|
|
||||||
noteId,
|
|
||||||
targetLang,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function translate() {
|
|
||||||
if (translation.value != null) return;
|
|
||||||
translating.value = true;
|
|
||||||
translation.value = await translate_(
|
|
||||||
appearNote.value.id,
|
|
||||||
translateLang || lang || navigator.language,
|
|
||||||
);
|
|
||||||
|
|
||||||
// use UI language as the second translation language
|
|
||||||
if (
|
|
||||||
translateLang != null &&
|
|
||||||
lang != null &&
|
|
||||||
translateLang !== lang &&
|
|
||||||
(!translation.value ||
|
|
||||||
translation.value.sourceLang.toLowerCase() === translateLang.slice(0, 2))
|
|
||||||
)
|
|
||||||
translation.value = await translate_(appearNote.value.id, lang);
|
|
||||||
translating.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function softMuteReasonI18nSrc(what?: string) {
|
function softMuteReasonI18nSrc(what?: string) {
|
||||||
if (what === "note") return i18n.ts.userSaysSomethingReason;
|
if (what === "note") return i18n.ts.userSaysSomethingReason;
|
||||||
if (what === "reply") return i18n.ts.userSaysSomethingReasonReply;
|
if (what === "reply") return i18n.ts.userSaysSomethingReasonReply;
|
||||||
|
@ -611,152 +317,12 @@ function softMuteReasonI18nSrc(what?: string) {
|
||||||
return i18n.ts.userSaysSomething;
|
return i18n.ts.userSaysSomething;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reply(_viaKeyboard = false): void {
|
|
||||||
pleaseLogin();
|
|
||||||
os.post(
|
|
||||||
{
|
|
||||||
reply: appearNote.value,
|
|
||||||
// animation: !viaKeyboard,
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
focus();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function react(_viaKeyboard = false): void {
|
|
||||||
pleaseLogin();
|
|
||||||
blur();
|
|
||||||
reactionPicker.show(
|
|
||||||
reactButton.value!,
|
|
||||||
(reaction) => {
|
|
||||||
os.api("notes/reactions/create", {
|
|
||||||
noteId: appearNote.value.id,
|
|
||||||
reaction,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
focus();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function undoReact(note: NoteType): void {
|
|
||||||
const oldReaction = note.myReaction;
|
|
||||||
if (!oldReaction) return;
|
|
||||||
os.api("notes/reactions/delete", {
|
|
||||||
noteId: note.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onContextmenu(ev: MouseEvent): void {
|
function onContextmenu(ev: MouseEvent): void {
|
||||||
const isLink = (el: HTMLElement): boolean => {
|
showNoteContextMenu({
|
||||||
if (el.tagName === "A") return true;
|
ev,
|
||||||
// The Audio element's context menu is the browser default, such as for selecting playback speed.
|
note: appearNote.value,
|
||||||
if (el.tagName === "AUDIO") return true;
|
react: footerEl.value!.react,
|
||||||
if (el.parentElement) {
|
});
|
||||||
return isLink(el.parentElement);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
if (isLink(ev.target as HTMLElement)) return;
|
|
||||||
if (window.getSelection()?.toString() !== "") return;
|
|
||||||
|
|
||||||
if (defaultStore.state.useReactionPickerForContextMenu) {
|
|
||||||
ev.preventDefault();
|
|
||||||
react();
|
|
||||||
} else {
|
|
||||||
os.contextMenu(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
type: "label",
|
|
||||||
text: notePage(appearNote.value),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: `${icon("ph-browser")}`,
|
|
||||||
text: i18n.ts.openInWindow,
|
|
||||||
action: () => {
|
|
||||||
os.pageWindow(notePage(appearNote.value));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
notePage(appearNote.value) !== location.pathname
|
|
||||||
? {
|
|
||||||
icon: `${icon("ph-arrows-out-simple")}`,
|
|
||||||
text: i18n.ts.showInPage,
|
|
||||||
action: () => {
|
|
||||||
router.push(notePage(appearNote.value), "forcePage");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
type: "a",
|
|
||||||
icon: `${icon("ph-arrow-square-out")}`,
|
|
||||||
text: i18n.ts.openInNewTab,
|
|
||||||
href: notePage(appearNote.value),
|
|
||||||
target: "_blank",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: `${icon("ph-link-simple")}`,
|
|
||||||
text: i18n.ts.copyLink,
|
|
||||||
action: () => {
|
|
||||||
copyToClipboard(`${url}${notePage(appearNote.value)}`);
|
|
||||||
os.success();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
appearNote.value.user.host != null
|
|
||||||
? {
|
|
||||||
type: "a",
|
|
||||||
icon: `${icon("ph-arrow-square-up-right")}`,
|
|
||||||
text: i18n.ts.showOnRemote,
|
|
||||||
href: appearNote.value.url ?? appearNote.value.uri ?? "",
|
|
||||||
target: "_blank",
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
],
|
|
||||||
ev,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function menu(viaKeyboard = false): void {
|
|
||||||
os.popupMenu(
|
|
||||||
getNoteMenu({
|
|
||||||
note: note.value,
|
|
||||||
translating,
|
|
||||||
translation,
|
|
||||||
menuButton,
|
|
||||||
isDeleted,
|
|
||||||
currentClipPage,
|
|
||||||
}),
|
|
||||||
menuButton.value,
|
|
||||||
{
|
|
||||||
viaKeyboard,
|
|
||||||
},
|
|
||||||
).then(focus);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showRenoteMenu(viaKeyboard = false): void {
|
|
||||||
if (!isMyNote.value) return;
|
|
||||||
os.popupMenu(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
text: i18n.ts.unrenote,
|
|
||||||
icon: `${icon("ph-trash")}`,
|
|
||||||
danger: true,
|
|
||||||
action: () => {
|
|
||||||
os.api("notes/delete", {
|
|
||||||
noteId: note.value.id,
|
|
||||||
});
|
|
||||||
isDeleted.value = true;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
renoteTime.value,
|
|
||||||
{
|
|
||||||
viaKeyboard,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function focus() {
|
function focus() {
|
||||||
|
@ -791,13 +357,6 @@ function noteClick(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function readPromo() {
|
|
||||||
os.api("promo/read", {
|
|
||||||
noteId: appearNote.value.id,
|
|
||||||
});
|
|
||||||
isDeleted.value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPostExpanded(val: boolean) {
|
function setPostExpanded(val: boolean) {
|
||||||
postIsExpanded.value = val;
|
postIsExpanded.value = val;
|
||||||
}
|
}
|
||||||
|
@ -900,71 +459,6 @@ defineExpose({
|
||||||
> div > i {
|
> div > i {
|
||||||
margin-left: -0.5px;
|
margin-left: -0.5px;
|
||||||
}
|
}
|
||||||
> .info {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 90%;
|
|
||||||
white-space: pre;
|
|
||||||
color: #f6c177;
|
|
||||||
|
|
||||||
> i {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .hide {
|
|
||||||
margin-left: auto;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .renote {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
white-space: pre;
|
|
||||||
color: var(--renote);
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
> i {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.avatar {
|
|
||||||
width: 1.2em;
|
|
||||||
height: 1.2em;
|
|
||||||
border-radius: 2em;
|
|
||||||
overflow: hidden;
|
|
||||||
margin-right: 0.4em;
|
|
||||||
background: var(--panelHighlight);
|
|
||||||
transform: translateY(-4px);
|
|
||||||
}
|
|
||||||
|
|
||||||
> span {
|
|
||||||
overflow: hidden;
|
|
||||||
flex-shrink: 1;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
|
|
||||||
> .name {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .info {
|
|
||||||
margin-left: auto;
|
|
||||||
font-size: 0.9em;
|
|
||||||
display: flex;
|
|
||||||
|
|
||||||
> .time {
|
|
||||||
flex-shrink: 0;
|
|
||||||
color: inherit;
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
> .dropdownIcon {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.collapsedReply {
|
&.collapsedReply {
|
||||||
.line {
|
.line {
|
||||||
|
@ -1054,12 +548,6 @@ defineExpose({
|
||||||
|
|
||||||
> .body {
|
> .body {
|
||||||
margin-top: 0.7em;
|
margin-top: 0.7em;
|
||||||
> .translation {
|
|
||||||
border: solid 0.5px var(--divider);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
padding: 12px;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
> .renote {
|
> .renote {
|
||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
> * {
|
> * {
|
||||||
|
@ -1074,74 +562,6 @@ defineExpose({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
> .info {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 0.7em;
|
|
||||||
margin-top: 16px;
|
|
||||||
opacity: 0.7;
|
|
||||||
font-size: 0.9em;
|
|
||||||
}
|
|
||||||
> .footer {
|
|
||||||
position: relative;
|
|
||||||
z-index: 2;
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
margin-top: 0.4em;
|
|
||||||
> :deep(.button) {
|
|
||||||
position: relative;
|
|
||||||
margin: 0;
|
|
||||||
padding: 8px;
|
|
||||||
opacity: 0.7;
|
|
||||||
&:disabled {
|
|
||||||
opacity: 0.3 !important;
|
|
||||||
}
|
|
||||||
flex-grow: 1;
|
|
||||||
max-width: 3.5em;
|
|
||||||
width: max-content;
|
|
||||||
min-width: max-content;
|
|
||||||
height: auto;
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
&::before {
|
|
||||||
content: "";
|
|
||||||
position: absolute;
|
|
||||||
inset: 0;
|
|
||||||
bottom: 2px;
|
|
||||||
background: var(--panel);
|
|
||||||
z-index: -1;
|
|
||||||
transition: background 0.2s;
|
|
||||||
}
|
|
||||||
&:first-of-type {
|
|
||||||
margin-left: -0.5em;
|
|
||||||
&::before {
|
|
||||||
border-radius: 100px 0 0 100px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&:last-of-type {
|
|
||||||
&::before {
|
|
||||||
border-radius: 0 100px 100px 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&:hover {
|
|
||||||
color: var(--fgHighlighted);
|
|
||||||
}
|
|
||||||
|
|
||||||
> i {
|
|
||||||
display: inline !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .count {
|
|
||||||
display: inline;
|
|
||||||
margin: 0 0 0 8px;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.reacted {
|
|
||||||
color: var(--accent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ const repliesPagingComponent = ref<MkPaginationType<"notes/replies"> | null>(
|
||||||
);
|
);
|
||||||
|
|
||||||
const el = ref<HTMLElement | null>(null);
|
const el = ref<HTMLElement | null>(null);
|
||||||
const noteEl = ref();
|
const noteEl = ref<InstanceType<typeof MkNote> | null>(null);
|
||||||
const menuButton = ref<HTMLElement>();
|
const menuButton = ref<HTMLElement>();
|
||||||
const renoteButton = ref<InstanceType<typeof XRenoteButton>>();
|
const renoteButton = ref<InstanceType<typeof XRenoteButton>>();
|
||||||
const reactButton = ref<HTMLElement>();
|
const reactButton = ref<HTMLElement>();
|
||||||
|
@ -361,11 +361,11 @@ function menu(viaKeyboard = false): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
function focus() {
|
function focus() {
|
||||||
noteEl.value.focus();
|
noteEl.value?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function blur() {
|
function blur() {
|
||||||
noteEl.value.blur();
|
noteEl.value?.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
conversation.value = null;
|
conversation.value = null;
|
||||||
|
@ -418,12 +418,12 @@ document.addEventListener("wheel", () => {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
isScrolling = false;
|
isScrolling = false;
|
||||||
noteEl.value.scrollIntoView();
|
noteEl.value?.scrollIntoView();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUpdated(() => {
|
onUpdated(() => {
|
||||||
if (!isScrolling) {
|
if (!isScrolling) {
|
||||||
noteEl.value.scrollIntoView();
|
noteEl.value?.scrollIntoView();
|
||||||
if (location.hash) {
|
if (location.hash) {
|
||||||
location.replace(location.hash); // Jump to highlighted reply
|
location.replace(location.hash); // Jump to highlighted reply
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<XNoteHeader class="header" :note="note" :mini="true" />
|
<XNoteHeader class="header" :note="note" :mini="true" />
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<MkSubNoteContent class="text" :note="note" />
|
<XNoteContent class="text" :note="note" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,8 +18,8 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import XNoteHeader from "@/components/MkNoteHeader.vue";
|
import XNoteHeader from "@/components/note/MkNoteHeader.vue";
|
||||||
import MkSubNoteContent from "@/components/MkSubNoteContent.vue";
|
import XNoteContent from "@/components/note/MkNoteContent.vue";
|
||||||
import { deepClone } from "@/scripts/clone";
|
import { deepClone } from "@/scripts/clone";
|
||||||
import { useNoteCapture } from "@/scripts/use-note-capture";
|
import { useNoteCapture } from "@/scripts/use-note-capture";
|
||||||
import { isDeleted } from "@/scripts/note";
|
import { isDeleted } from "@/scripts/note";
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<XNoteHeader class="header" :note="note" :mini="true" />
|
<XNoteHeader class="header" :note="note" :mini="true" />
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<MkSubNoteContent
|
<XNoteContent
|
||||||
class="text"
|
class="text"
|
||||||
:note="note"
|
:note="note"
|
||||||
:parent-id="parentId"
|
:parent-id="parentId"
|
||||||
|
@ -38,112 +38,20 @@
|
||||||
:detailed-view="detailedView"
|
:detailed-view="detailedView"
|
||||||
@focusfooter="footerEl!.focus()"
|
@focusfooter="footerEl!.focus()"
|
||||||
/>
|
/>
|
||||||
<div v-if="translating || translation" class="translation">
|
<XNoteTranslation ref="noteTranslation" :note="note"/>
|
||||||
<MkLoading v-if="translating || translation == null" mini />
|
|
||||||
<div v-else class="translated">
|
|
||||||
<b
|
|
||||||
>{{
|
|
||||||
i18n.t("translatedFrom", {
|
|
||||||
x: translation.sourceLang,
|
|
||||||
})
|
|
||||||
}}:
|
|
||||||
</b>
|
|
||||||
<Mfm
|
|
||||||
:text="translation.text"
|
|
||||||
:author="appearNote.user"
|
|
||||||
:i="me"
|
|
||||||
:lang="targetLang"
|
|
||||||
:custom-emojis="appearNote.emojis"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<footer ref="footerEl" class="footer" tabindex="-1">
|
<XNoteFooter
|
||||||
<XReactionsViewer
|
class="footer"
|
||||||
v-if="enableEmojiReactions && !hideEmojiViewer"
|
ref="footerEl"
|
||||||
ref="reactionsViewer"
|
:note="appearNote"
|
||||||
:note="appearNote"
|
:enableEmojiReactions
|
||||||
/>
|
:hideEmojiViewer
|
||||||
<button
|
:detailedView
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.reply"
|
:note-translation="noteTranslation!"
|
||||||
class="button _button"
|
@deleted="isDeleted = true"
|
||||||
@click.stop="reply()"
|
@event:focus="focus"
|
||||||
>
|
@event:blur="blur"
|
||||||
<i :class="icon('ph-arrow-u-up-left')"></i>
|
/>
|
||||||
<template v-if="appearNote.repliesCount > 0">
|
|
||||||
<p class="count">{{ appearNote.repliesCount }}</p>
|
|
||||||
</template>
|
|
||||||
</button>
|
|
||||||
<XRenoteButton
|
|
||||||
ref="renoteButton"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
:count="appearNote.renoteCount"
|
|
||||||
/>
|
|
||||||
<XStarButtonNoEmoji
|
|
||||||
v-if="!enableEmojiReactions"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
:count="reactionCount"
|
|
||||||
:reacted="appearNote.myReaction != null"
|
|
||||||
/>
|
|
||||||
<XStarButton
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction == null
|
|
||||||
"
|
|
||||||
ref="starButton"
|
|
||||||
class="button"
|
|
||||||
:note="appearNote"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction == null
|
|
||||||
"
|
|
||||||
ref="reactButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.reaction"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="react()"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-smiley')"></i>
|
|
||||||
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">{{reactionCount}}</p>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
enableEmojiReactions &&
|
|
||||||
appearNote.myReaction != null
|
|
||||||
"
|
|
||||||
ref="reactButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.removeReaction"
|
|
||||||
class="button _button reacted"
|
|
||||||
@click.stop="undoReact(appearNote)"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-minus')"></i>
|
|
||||||
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">{{reactionCount}}</p>
|
|
||||||
</button>
|
|
||||||
<XQuoteButton class="button" :note="appearNote" />
|
|
||||||
<button
|
|
||||||
v-if="
|
|
||||||
isSignedIn(me) &&
|
|
||||||
isForeignLanguage &&
|
|
||||||
translation == null
|
|
||||||
"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.translate"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="translate"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-translate')"></i>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
ref="menuButton"
|
|
||||||
v-tooltip.noDelay.bottom="i18n.ts.more"
|
|
||||||
class="button _button"
|
|
||||||
@click.stop="menu()"
|
|
||||||
>
|
|
||||||
<i :class="icon('ph-dots-three-outline')"></i>
|
|
||||||
</button>
|
|
||||||
</footer>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<MkLoading v-if="conversationLoading" />
|
<MkLoading v-if="conversationLoading" />
|
||||||
|
@ -200,34 +108,24 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import type { Ref } from "vue";
|
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import XNoteHeader from "@/components/MkNoteHeader.vue";
|
import XNoteHeader from "@/components/note/MkNoteHeader.vue";
|
||||||
import MkSubNoteContent from "@/components/MkSubNoteContent.vue";
|
import XNoteContent from "@/components/note/MkNoteContent.vue";
|
||||||
import XReactionsViewer from "@/components/MkReactionsViewer.vue";
|
|
||||||
import XStarButton from "@/components/MkStarButton.vue";
|
|
||||||
import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
|
|
||||||
import XRenoteButton from "@/components/MkRenoteButton.vue";
|
|
||||||
import XQuoteButton from "@/components/MkQuoteButton.vue";
|
|
||||||
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
|
||||||
import { detectLanguage } from "@/scripts/language-utils";
|
|
||||||
import { url } from "@/config";
|
|
||||||
import { pleaseLogin } from "@/scripts/please-login";
|
|
||||||
import { getNoteMenu } from "@/scripts/get-note-menu";
|
|
||||||
import { getWordSoftMute } from "@/scripts/check-word-mute";
|
import { getWordSoftMute } from "@/scripts/check-word-mute";
|
||||||
import { notePage } from "@/filters/note";
|
import { notePage } from "@/filters/note";
|
||||||
import { useRouter } from "@/router";
|
import { useRouter } from "@/router";
|
||||||
import { userPage } from "@/filters/user";
|
import { userPage } from "@/filters/user";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import { reactionPicker } from "@/scripts/reaction-picker";
|
import { me } from "@/me";
|
||||||
import { isSignedIn, me } from "@/me";
|
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { useNoteCapture } from "@/scripts/use-note-capture";
|
import { useNoteCapture } from "@/scripts/use-note-capture";
|
||||||
import { defaultStore } from "@/store";
|
import { defaultStore } from "@/store";
|
||||||
import { deepClone } from "@/scripts/clone";
|
import { deepClone } from "@/scripts/clone";
|
||||||
import icon from "@/scripts/icon";
|
import icon from "@/scripts/icon";
|
||||||
import type { NoteTranslation } from "@/types/note";
|
import XNoteFooter from "./note/MkNoteFooter.vue";
|
||||||
|
import XNoteTranslation from "./note/MkNoteTranslation.vue";
|
||||||
|
import { showNoteContextMenu } from "@/scripts/show-note-context-menu";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -312,11 +210,8 @@ const isRenote =
|
||||||
note.value.poll == null;
|
note.value.poll == null;
|
||||||
|
|
||||||
const el = ref<HTMLElement | null>(null);
|
const el = ref<HTMLElement | null>(null);
|
||||||
const footerEl = ref<HTMLElement | null>(null);
|
const noteTranslation = ref<InstanceType<typeof XNoteTranslation> | null>(null);
|
||||||
const menuButton = ref<HTMLElement>();
|
const footerEl = ref<InstanceType<typeof XNoteFooter> | null>(null);
|
||||||
const starButton = ref<InstanceType<typeof XStarButton> | null>(null);
|
|
||||||
const renoteButton = ref<InstanceType<typeof XRenoteButton> | null>(null);
|
|
||||||
const reactButton = ref<HTMLElement | null>(null);
|
|
||||||
const appearNote = computed(() =>
|
const appearNote = computed(() =>
|
||||||
isRenote ? (note.value.renote as entities.Note) : note.value,
|
isRenote ? (note.value.renote as entities.Note) : note.value,
|
||||||
);
|
);
|
||||||
|
@ -329,55 +224,8 @@ const muted = ref(
|
||||||
defaultStore.state.mutedLangs,
|
defaultStore.state.mutedLangs,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const translation = ref<NoteTranslation | null>(null);
|
|
||||||
const translating = ref(false);
|
|
||||||
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
||||||
const expandOnNoteClick = defaultStore.state.expandOnNoteClick;
|
const expandOnNoteClick = defaultStore.state.expandOnNoteClick;
|
||||||
const lang = localStorage.getItem("lang");
|
|
||||||
const translateLang = localStorage.getItem("translateLang");
|
|
||||||
const targetLang = (translateLang || lang || navigator.language)?.slice(0, 2);
|
|
||||||
|
|
||||||
const reactionCount = computed(() =>
|
|
||||||
Object.values(appearNote.value.reactions).reduce(
|
|
||||||
(partialSum, val) => partialSum + val,
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const isForeignLanguage: boolean =
|
|
||||||
defaultStore.state.detectPostLanguage &&
|
|
||||||
appearNote.value.text != null &&
|
|
||||||
(() => {
|
|
||||||
const postLang = detectLanguage(appearNote.value.text);
|
|
||||||
return postLang !== "" && postLang !== targetLang;
|
|
||||||
})();
|
|
||||||
|
|
||||||
async function translate_(noteId, targetLang: string) {
|
|
||||||
return await os.api("notes/translate", {
|
|
||||||
noteId,
|
|
||||||
targetLang,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function translate() {
|
|
||||||
if (translation.value != null) return;
|
|
||||||
translating.value = true;
|
|
||||||
translation.value = await translate_(
|
|
||||||
appearNote.value.id,
|
|
||||||
translateLang || lang || navigator.language,
|
|
||||||
);
|
|
||||||
|
|
||||||
// use UI language as the second translation language
|
|
||||||
if (
|
|
||||||
translateLang != null &&
|
|
||||||
lang != null &&
|
|
||||||
translateLang !== lang &&
|
|
||||||
(!translation.value ||
|
|
||||||
translation.value.sourceLang.toLowerCase() === translateLang.slice(0, 2))
|
|
||||||
)
|
|
||||||
translation.value = await translate_(appearNote.value.id, lang);
|
|
||||||
translating.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
useNoteCapture({
|
useNoteCapture({
|
||||||
rootEl: el,
|
rootEl: el,
|
||||||
|
@ -393,129 +241,12 @@ useNoteCapture({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function reply(_viaKeyboard = false): void {
|
|
||||||
pleaseLogin();
|
|
||||||
os.post({
|
|
||||||
reply: appearNote.value,
|
|
||||||
// animation: !viaKeyboard,
|
|
||||||
}).then(() => {
|
|
||||||
focus();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function react(_viaKeyboard = false): void {
|
|
||||||
pleaseLogin();
|
|
||||||
blur();
|
|
||||||
reactionPicker.show(
|
|
||||||
reactButton.value!,
|
|
||||||
(reaction) => {
|
|
||||||
os.api("notes/reactions/create", {
|
|
||||||
noteId: appearNote.value.id,
|
|
||||||
reaction,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
focus();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function undoReact(note): void {
|
|
||||||
const oldReaction = note.myReaction;
|
|
||||||
if (!oldReaction) return;
|
|
||||||
os.api("notes/reactions/delete", {
|
|
||||||
noteId: note.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentClipPage = inject<Ref<entities.Clip> | null>(
|
|
||||||
"currentClipPage",
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
function menu(viaKeyboard = false): void {
|
|
||||||
os.popupMenu(
|
|
||||||
getNoteMenu({
|
|
||||||
note: note.value,
|
|
||||||
translating,
|
|
||||||
translation,
|
|
||||||
menuButton,
|
|
||||||
isDeleted,
|
|
||||||
currentClipPage,
|
|
||||||
}),
|
|
||||||
menuButton.value,
|
|
||||||
{
|
|
||||||
viaKeyboard,
|
|
||||||
},
|
|
||||||
).then(focus);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onContextmenu(ev: MouseEvent): void {
|
function onContextmenu(ev: MouseEvent): void {
|
||||||
const isLink = (el: HTMLElement | null) => {
|
showNoteContextMenu({
|
||||||
if (el == null) return;
|
ev,
|
||||||
if (el.tagName === "A") return true;
|
note: appearNote.value,
|
||||||
if (el.parentElement) {
|
react: footerEl.value!.react,
|
||||||
return isLink(el.parentElement);
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
if (isLink(ev.target as HTMLElement | null)) return;
|
|
||||||
if (window.getSelection()?.toString() !== "") return;
|
|
||||||
|
|
||||||
if (defaultStore.state.useReactionPickerForContextMenu) {
|
|
||||||
ev.preventDefault();
|
|
||||||
react();
|
|
||||||
} else {
|
|
||||||
os.contextMenu(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
type: "label",
|
|
||||||
text: notePage(appearNote.value),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: `${icon("ph-browser")}`,
|
|
||||||
text: i18n.ts.openInWindow,
|
|
||||||
action: () => {
|
|
||||||
os.pageWindow(notePage(appearNote.value));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
notePage(appearNote.value) !== location.pathname
|
|
||||||
? {
|
|
||||||
icon: `${icon("ph-arrows-out-simple")}`,
|
|
||||||
text: i18n.ts.showInPage,
|
|
||||||
action: () => {
|
|
||||||
router.push(notePage(appearNote.value), "forcePage");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
type: "a",
|
|
||||||
icon: `${icon("ph-arrow-square-out")}`,
|
|
||||||
text: i18n.ts.openInNewTab,
|
|
||||||
href: notePage(appearNote.value),
|
|
||||||
target: "_blank",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: `${icon("ph-link-simple")}`,
|
|
||||||
text: i18n.ts.copyLink,
|
|
||||||
action: () => {
|
|
||||||
copyToClipboard(`${url}${notePage(appearNote.value)}`);
|
|
||||||
os.success();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
note.value.user.host != null
|
|
||||||
? {
|
|
||||||
type: "a",
|
|
||||||
icon: `${icon("ph-arrow-square-up-right")}`,
|
|
||||||
text: i18n.ts.showOnRemote,
|
|
||||||
href: note.value.url ?? note.value.uri ?? "",
|
|
||||||
target: "_blank",
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
],
|
|
||||||
ev,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function focus() {
|
function focus() {
|
||||||
|
@ -580,15 +311,6 @@ function noteClick(e: MouseEvent) {
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
cursor: auto;
|
cursor: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .body {
|
|
||||||
> .translation {
|
|
||||||
border: solid 0.5px var(--divider);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
padding: 12px;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
> .footer {
|
> .footer {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
<i :class="icon('ph-warning')"></i>
|
<i :class="icon('ph-warning')"></i>
|
||||||
{{ i18n.ts.somethingHappened }}
|
{{ i18n.ts.somethingHappened }}
|
||||||
</p>
|
</p>
|
||||||
<MkButton class="button" @click="() => $emit('retry')">{{
|
<MkButton class="button" @click.stop="() => $emit('retry')">
|
||||||
i18n.ts.retry
|
{{ i18n.ts.retry }}
|
||||||
}}</MkButton>
|
</MkButton>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
tabindex: !showContent ? '-1' : undefined,
|
tabindex: !showContent ? '-1' : undefined,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<span v-if="note.deletedAt" style="opacity: 0.5"
|
<span v-if="deleted" style="opacity: 0.5"
|
||||||
>({{ i18n.ts.deleted }})</span
|
>({{ i18n.ts.deleted }})</span
|
||||||
>
|
>
|
||||||
<template v-if="!note.cw">
|
<template v-if="!note.cw">
|
||||||
|
@ -195,6 +195,7 @@ import { extractMfmWithAnimation } from "@/scripts/extract-mfm";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { defaultStore } from "@/store";
|
import { defaultStore } from "@/store";
|
||||||
import icon from "@/scripts/icon";
|
import icon from "@/scripts/icon";
|
||||||
|
import { isDeleted } from "@/scripts/note";
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -242,6 +243,8 @@ const mfms = computed(() =>
|
||||||
);
|
);
|
||||||
const hasMfm = computed(() => mfms.value && mfms.value.length > 0);
|
const hasMfm = computed(() => mfms.value && mfms.value.length > 0);
|
||||||
|
|
||||||
|
const deleted = computed(() => isDeleted(props.note.id));
|
||||||
|
|
||||||
const disableMfm = ref(defaultStore.state.animatedMfm);
|
const disableMfm = ref(defaultStore.state.animatedMfm);
|
||||||
const showContent = ref(false);
|
const showContent = ref(false);
|
||||||
const collapsed = ref(props.note.cw == null && isLong.value);
|
const collapsed = ref(props.note.cw == null && isLong.value);
|
290
packages/client/src/components/note/MkNoteFooter.vue
Normal file
290
packages/client/src/components/note/MkNoteFooter.vue
Normal file
|
@ -0,0 +1,290 @@
|
||||||
|
<template>
|
||||||
|
<footer class="footer" ref="el" tabindex="-1">
|
||||||
|
<XReactionsViewer
|
||||||
|
v-if="enableEmojiReactions && !hideEmojiViewer"
|
||||||
|
ref="reactionsViewer"
|
||||||
|
:note="note"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-tooltip.noDelay.bottom="i18n.ts.reply"
|
||||||
|
class="button _button"
|
||||||
|
@click.stop="reply()"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-arrow-u-up-left')"></i>
|
||||||
|
<template v-if="note.repliesCount > 0 && !detailedView">
|
||||||
|
<p class="count">{{ note.repliesCount }}</p>
|
||||||
|
</template>
|
||||||
|
</button>
|
||||||
|
<XRenoteButton
|
||||||
|
ref="renoteButton"
|
||||||
|
class="button"
|
||||||
|
:note="note"
|
||||||
|
:count="note.renoteCount"
|
||||||
|
:detailed-view="detailedView"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
/>
|
||||||
|
<XStarButtonNoEmoji
|
||||||
|
v-if="!enableEmojiReactions"
|
||||||
|
class="button"
|
||||||
|
:note="note"
|
||||||
|
:count="reactionCount"
|
||||||
|
:reacted="note.myReaction != null"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
/>
|
||||||
|
<XStarButton
|
||||||
|
v-if="enableEmojiReactions && note.myReaction == null"
|
||||||
|
ref="starButton"
|
||||||
|
class="button"
|
||||||
|
:note="note"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="enableEmojiReactions && note.myReaction == null"
|
||||||
|
ref="reactButton"
|
||||||
|
v-tooltip.noDelay.bottom="i18n.ts.reaction"
|
||||||
|
class="button _button"
|
||||||
|
@click.stop="react()"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-smiley')"></i>
|
||||||
|
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">
|
||||||
|
{{ reactionCount }}
|
||||||
|
</p>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="enableEmojiReactions && note.myReaction != null"
|
||||||
|
ref="reactButton"
|
||||||
|
v-tooltip.noDelay.bottom="i18n.ts.removeReaction"
|
||||||
|
class="button _button reacted"
|
||||||
|
@click.stop="undoReact(note)"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-minus')"></i>
|
||||||
|
<p v-if="reactionCount > 0 && hideEmojiViewer" class="count">
|
||||||
|
{{ reactionCount }}
|
||||||
|
</p>
|
||||||
|
</button>
|
||||||
|
<XQuoteButton
|
||||||
|
class="button"
|
||||||
|
:note="note"
|
||||||
|
:disabled="note.scheduledAt != null"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="
|
||||||
|
isSignedIn(me) &&
|
||||||
|
isForeignLanguage &&
|
||||||
|
noteTranslation.canTranslate
|
||||||
|
"
|
||||||
|
v-tooltip.noDelay.bottom="i18n.ts.translate"
|
||||||
|
class="button _button"
|
||||||
|
@click.stop="noteTranslation.translate"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-translate')"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
ref="menuButton"
|
||||||
|
v-tooltip.noDelay.bottom="i18n.ts.more"
|
||||||
|
class="button _button"
|
||||||
|
@click.stop="menu()"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-dots-three-outline')"></i>
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { i18n } from "@/i18n";
|
||||||
|
import { isSignedIn, me } from "@/me";
|
||||||
|
import icon from "@/scripts/icon";
|
||||||
|
import type { NoteType } from "@/types/note";
|
||||||
|
import { type Ref, computed, inject, ref, watch } from "vue";
|
||||||
|
import XReactionsViewer from "@/components/MkReactionsViewer.vue";
|
||||||
|
import XStarButton from "@/components/MkStarButton.vue";
|
||||||
|
import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
|
||||||
|
import XQuoteButton from "@/components/MkQuoteButton.vue";
|
||||||
|
import XRenoteButton from "@/components/MkRenoteButton.vue";
|
||||||
|
import * as os from "@/os";
|
||||||
|
import { pleaseLogin } from "@/scripts/please-login";
|
||||||
|
import { reactionPicker } from "@/scripts/reaction-picker";
|
||||||
|
import { getNoteMenu } from "@/scripts/get-note-menu";
|
||||||
|
import { defaultStore } from "@/store";
|
||||||
|
import { detectLanguage } from "@/scripts/language-utils";
|
||||||
|
import type { entities } from "firefish-js";
|
||||||
|
import type MkNoteTranslation from "./MkNoteTranslation.vue";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
note: NoteType;
|
||||||
|
enableEmojiReactions?: boolean;
|
||||||
|
hideEmojiViewer?: boolean;
|
||||||
|
detailedView?: boolean;
|
||||||
|
noteTranslation: InstanceType<typeof MkNoteTranslation>;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"event:focus": [];
|
||||||
|
"event:blur": [];
|
||||||
|
deleted: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const el = ref<HTMLElement | null>(null);
|
||||||
|
const starButton = ref<InstanceType<typeof XStarButton>>();
|
||||||
|
const renoteButton = ref<InstanceType<typeof XRenoteButton> | null>(null);
|
||||||
|
const reactButton = ref<HTMLElement | null>(null);
|
||||||
|
const menuButton = ref<HTMLElement>();
|
||||||
|
|
||||||
|
const reactionCount = computed(() =>
|
||||||
|
Object.values(props.note.reactions).reduce(
|
||||||
|
(partialSum, val) => partialSum + val,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentClipPage = inject<Ref<entities.Clip> | null>(
|
||||||
|
"currentClipPage",
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
const isForeignLanguage = computed(
|
||||||
|
() =>
|
||||||
|
defaultStore.state.detectPostLanguage &&
|
||||||
|
props.note.text != null &&
|
||||||
|
(() => {
|
||||||
|
const postLang = detectLanguage(props.note.text);
|
||||||
|
return postLang !== "" && postLang !== props.noteTranslation.targetLang;
|
||||||
|
})(),
|
||||||
|
);
|
||||||
|
|
||||||
|
function focus() {
|
||||||
|
emit("event:focus");
|
||||||
|
}
|
||||||
|
|
||||||
|
function reply(_viaKeyboard = false): void {
|
||||||
|
pleaseLogin();
|
||||||
|
os.post(
|
||||||
|
{
|
||||||
|
reply: props.note,
|
||||||
|
// animation: !viaKeyboard,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
focus();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function react(_viaKeyboard = false): void {
|
||||||
|
pleaseLogin();
|
||||||
|
emit("event:blur");
|
||||||
|
reactionPicker.show(
|
||||||
|
reactButton.value!,
|
||||||
|
(reaction) => {
|
||||||
|
os.api("notes/reactions/create", {
|
||||||
|
noteId: props.note.id,
|
||||||
|
reaction,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
focus();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function undoReact(note: NoteType): void {
|
||||||
|
const oldReaction = note.myReaction;
|
||||||
|
if (!oldReaction) return;
|
||||||
|
os.api("notes/reactions/delete", {
|
||||||
|
noteId: note.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function menu(viaKeyboard = false): void {
|
||||||
|
const isDeleted = ref(false);
|
||||||
|
watch(isDeleted, (v) => {
|
||||||
|
if (v === true) emit("deleted");
|
||||||
|
});
|
||||||
|
os.popupMenu(
|
||||||
|
getNoteMenu({
|
||||||
|
note: props.note,
|
||||||
|
menuButton,
|
||||||
|
isDeleted,
|
||||||
|
currentClipPage,
|
||||||
|
translationEl: props.noteTranslation,
|
||||||
|
}),
|
||||||
|
menuButton.value,
|
||||||
|
{
|
||||||
|
viaKeyboard,
|
||||||
|
},
|
||||||
|
).then(focus);
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
reply,
|
||||||
|
react,
|
||||||
|
undoReact,
|
||||||
|
menu,
|
||||||
|
renote: (viaKeyboard: boolean) => renoteButton.value!.renote(viaKeyboard),
|
||||||
|
focus: () => el.value?.focus(),
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.footer {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-top: 0.4em;
|
||||||
|
> :deep(.button) {
|
||||||
|
position: relative;
|
||||||
|
margin: 0;
|
||||||
|
padding: 8px;
|
||||||
|
opacity: 0.7;
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.3 !important;
|
||||||
|
}
|
||||||
|
flex-grow: 1;
|
||||||
|
max-width: 3.5em;
|
||||||
|
width: max-content;
|
||||||
|
min-width: max-content;
|
||||||
|
height: auto;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
&::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
bottom: 2px;
|
||||||
|
background: var(--panel);
|
||||||
|
z-index: -1;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
&:first-of-type {
|
||||||
|
margin-left: -0.5em;
|
||||||
|
&::before {
|
||||||
|
border-radius: 100px 0 0 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:last-of-type {
|
||||||
|
&::before {
|
||||||
|
border-radius: 0 100px 100px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
color: var(--fgHighlighted);
|
||||||
|
}
|
||||||
|
|
||||||
|
> i {
|
||||||
|
display: inline !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .count {
|
||||||
|
display: inline;
|
||||||
|
margin: 0 0 0 8px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.reacted {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
44
packages/client/src/components/note/MkNoteFooterInfo.vue
Normal file
44
packages/client/src/components/note/MkNoteFooterInfo.vue
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<template>
|
||||||
|
<div v-if="detailedView || (note.channel && !inChannel)" class="footer-info">
|
||||||
|
<MkA v-if="detailedView" class="created-at" :to="notePage(note)">
|
||||||
|
<MkTime
|
||||||
|
v-if="note.scheduledAt != null"
|
||||||
|
:time="note.scheduledAt"
|
||||||
|
/>
|
||||||
|
<MkTime v-else :time="note.createdAt" mode="absolute" />
|
||||||
|
</MkA>
|
||||||
|
<MkA
|
||||||
|
v-if="note.channel && !inChannel"
|
||||||
|
class="channel"
|
||||||
|
:to="`/channels/${note.channel.id}`"
|
||||||
|
@click.stop
|
||||||
|
><i :class="icon('ph-television', false)"></i>
|
||||||
|
{{ note.channel.name }}</MkA
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { notePage } from "@/filters/note";
|
||||||
|
import icon from "@/scripts/icon";
|
||||||
|
import type { NoteType } from "@/types/note";
|
||||||
|
import { inject } from "vue";
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
note: NoteType;
|
||||||
|
detailedView?: boolean;
|
||||||
|
}>();
|
||||||
|
const inChannel = inject("inChannel", null);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.footer-info {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.7em;
|
||||||
|
margin-top: 16px;
|
||||||
|
opacity: 0.7;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
</style>
|
71
packages/client/src/components/note/MkNoteHeaderInfo.vue
Normal file
71
packages/client/src/components/note/MkNoteHeaderInfo.vue
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<template>
|
||||||
|
<!-- _prId_ and _featuredId_ is not used now -->
|
||||||
|
<!-- TODO: remove them -->
|
||||||
|
<!-- <div v-if="appearNote._prId_" class="info">
|
||||||
|
<i :class="icon('ph-megaphone-simple-bold')"></i>
|
||||||
|
{{ i18n.ts.promotion
|
||||||
|
}}<button class="_textButton hide" @click.stop="readPromo()">
|
||||||
|
{{ i18n.ts.hideThisNote }}
|
||||||
|
<i :class="icon('ph-x')"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div v-if="appearNote._featuredId_" class="info">
|
||||||
|
<i :class="icon('ph-lightning')"></i>
|
||||||
|
{{ i18n.ts.featured }}
|
||||||
|
</div> -->
|
||||||
|
<div v-if="pinned" class="info">
|
||||||
|
<i :class="icon('ph-push-pin')"></i>{{ i18n.ts.pinnedNote }}
|
||||||
|
</div>
|
||||||
|
<div v-if="collapsedReply && appearNote.reply" class="info">
|
||||||
|
<MkAvatar class="avatar" :user="appearNote.reply.user" />
|
||||||
|
<MkUserName class="username" :user="appearNote.reply.user"></MkUserName>
|
||||||
|
<Mfm
|
||||||
|
class="summary"
|
||||||
|
:text="getNoteSummary(appearNote.reply)"
|
||||||
|
:plain="true"
|
||||||
|
:nowrap="true"
|
||||||
|
:lang="appearNote.reply.lang"
|
||||||
|
:custom-emojis="note.emojis"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { i18n } from "@/i18n";
|
||||||
|
import { getNoteSummary } from "@/scripts/get-note-summary";
|
||||||
|
import icon from "@/scripts/icon";
|
||||||
|
import type { NoteType } from "@/types/note";
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
note: NoteType;
|
||||||
|
appearNote: NoteType;
|
||||||
|
collapsedReply?: boolean;
|
||||||
|
pinned?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
// function readPromo() {
|
||||||
|
// os.api("promo/read", {
|
||||||
|
// noteId: props.appearNote.id,
|
||||||
|
// });
|
||||||
|
// isDeleted.value = true;
|
||||||
|
// }
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 90%;
|
||||||
|
white-space: pre;
|
||||||
|
color: #f6c177;
|
||||||
|
|
||||||
|
> i {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .hide {
|
||||||
|
margin-left: auto;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import XNoteMedia from "@/components/MkNoteMedia.vue";
|
import XNoteMedia from "@/components/note/MkNoteMedia.vue";
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
note: entities.Note;
|
note: entities.Note;
|
110
packages/client/src/components/note/MkNoteTranslation.vue
Normal file
110
packages/client/src/components/note/MkNoteTranslation.vue
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
<template>
|
||||||
|
<div v-if="translating || translation != null || hasError" class="translation-container">
|
||||||
|
<MkLoading v-if="translating" mini/>
|
||||||
|
<MkError v-else-if="hasError" @retry="translate"/>
|
||||||
|
<div v-else-if="translation != null" class="translated">
|
||||||
|
<b
|
||||||
|
>{{
|
||||||
|
i18n.t("translatedFrom", {
|
||||||
|
x: translation.sourceLang,
|
||||||
|
})
|
||||||
|
}}:
|
||||||
|
</b>
|
||||||
|
<Mfm
|
||||||
|
:text="translation.text"
|
||||||
|
:author="note.user"
|
||||||
|
:i="me"
|
||||||
|
:lang="targetLang"
|
||||||
|
:custom-emojis="note.emojis"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { i18n } from "@/i18n";
|
||||||
|
import { me } from "@/me";
|
||||||
|
import type { NoteTranslation, NoteType } from "@/types/note";
|
||||||
|
import { computed, ref, watch } from "vue";
|
||||||
|
import * as os from "@/os";
|
||||||
|
import { instance } from "@/instance";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
note: NoteType;
|
||||||
|
detailedView?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const translation = ref<NoteTranslation | null>(null);
|
||||||
|
const translating = ref<boolean>();
|
||||||
|
const hasError = ref<boolean>();
|
||||||
|
const canTranslate = computed(
|
||||||
|
() =>
|
||||||
|
instance.translatorAvailable &&
|
||||||
|
translation.value == null &&
|
||||||
|
translating.value !== true,
|
||||||
|
);
|
||||||
|
|
||||||
|
const lang = localStorage.getItem("lang");
|
||||||
|
const translateLang = localStorage.getItem("translateLang");
|
||||||
|
const targetLang = (translateLang || lang || navigator.language)?.slice(0, 2);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.note.id,
|
||||||
|
(o, n) => {
|
||||||
|
if (o !== n) {
|
||||||
|
translating.value = false;
|
||||||
|
translation.value = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
async function getTranslation(noteId: string, targetLang: string) {
|
||||||
|
return await os.api("notes/translate", {
|
||||||
|
noteId,
|
||||||
|
targetLang,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function translate() {
|
||||||
|
try {
|
||||||
|
if (translation.value != null) return;
|
||||||
|
translating.value = true;
|
||||||
|
translation.value = await getTranslation(
|
||||||
|
props.note.id,
|
||||||
|
translateLang || lang || navigator.language,
|
||||||
|
);
|
||||||
|
|
||||||
|
// use UI language as the second translation language
|
||||||
|
if (
|
||||||
|
translateLang != null &&
|
||||||
|
lang != null &&
|
||||||
|
translateLang !== lang &&
|
||||||
|
(!translation.value ||
|
||||||
|
translation.value.sourceLang.toLowerCase() ===
|
||||||
|
translateLang.slice(0, 2))
|
||||||
|
)
|
||||||
|
translation.value = await getTranslation(props.note.id, lang);
|
||||||
|
hasError.value = false;
|
||||||
|
} catch (err) {
|
||||||
|
hasError.value = true;
|
||||||
|
translation.value = null;
|
||||||
|
} finally {
|
||||||
|
translating.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
translate,
|
||||||
|
canTranslate,
|
||||||
|
targetLang,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.translation-container {
|
||||||
|
border: solid 0.5px var(--divider);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 12px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
165
packages/client/src/components/note/MkRenoteBar.vue
Normal file
165
packages/client/src/components/note/MkRenoteBar.vue
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="isRenote || (renotesSliced && renotesSliced.length > 0)"
|
||||||
|
class="renote"
|
||||||
|
>
|
||||||
|
<i :class="icon('ph-rocket-launch')"></i>
|
||||||
|
<I18n v-if="renotesSliced == null" :src="i18n.ts.renotedBy" tag="span">
|
||||||
|
<template #user>
|
||||||
|
<MkAvatar class="avatar" :user="note.user" />
|
||||||
|
<MkA
|
||||||
|
v-user-preview="note.userId"
|
||||||
|
class="name"
|
||||||
|
:to="userPage(note.user)"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<MkUserName :user="note.user" />
|
||||||
|
</MkA>
|
||||||
|
</template>
|
||||||
|
</I18n>
|
||||||
|
<I18n v-else :src="i18n.ts.renotedBy" tag="span">
|
||||||
|
<template #user>
|
||||||
|
<template v-for="(renote, index) in renotesSliced">
|
||||||
|
<MkAvatar class="avatar" :user="renote.user" />
|
||||||
|
<MkA
|
||||||
|
v-user-preview="renote.userId"
|
||||||
|
class="name"
|
||||||
|
:to="userPage(renote.user)"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<MkUserName :user="renote.user" />
|
||||||
|
</MkA>
|
||||||
|
{{
|
||||||
|
index !== renotesSliced.length - 1
|
||||||
|
? ", "
|
||||||
|
: renotesSliced.length < renotes!.length
|
||||||
|
? "..."
|
||||||
|
: ""
|
||||||
|
}}
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</I18n>
|
||||||
|
<div class="info">
|
||||||
|
<button
|
||||||
|
ref="renoteTime"
|
||||||
|
class="_button time"
|
||||||
|
@click.stop="showRenoteMenu()"
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
v-if="isMyNote"
|
||||||
|
:class="icon('ph-dots-three-outline dropdownIcon')"
|
||||||
|
></i>
|
||||||
|
<MkTime
|
||||||
|
v-if="renotesSliced && renotesSliced.length > 0"
|
||||||
|
:time="renotesSliced[0].createdAt"
|
||||||
|
/>
|
||||||
|
<MkTime v-else :time="note.createdAt" />
|
||||||
|
</button>
|
||||||
|
<MkVisibility :note="note" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { userPage } from "@/filters/user";
|
||||||
|
import { i18n } from "@/i18n";
|
||||||
|
import { isSignedIn, me } from "@/me";
|
||||||
|
import icon from "@/scripts/icon";
|
||||||
|
import type { NoteType } from "@/types/note";
|
||||||
|
import { computed, ref } from "vue";
|
||||||
|
import MkVisibility from "@/components/MkVisibility.vue";
|
||||||
|
import * as os from "@/os";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
note: NoteType;
|
||||||
|
appearNote: NoteType;
|
||||||
|
isRenote?: boolean;
|
||||||
|
renotes?: NoteType[];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
deleted: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const renoteTime = ref<HTMLElement>();
|
||||||
|
|
||||||
|
const renotesSliced = computed(() => props.renotes?.slice(0, 5));
|
||||||
|
|
||||||
|
const isMyNote = computed(
|
||||||
|
() => isSignedIn(me) && me.id === props.note.userId && props.renotes == null,
|
||||||
|
);
|
||||||
|
|
||||||
|
function showRenoteMenu(viaKeyboard = false): void {
|
||||||
|
if (!isMyNote.value) return;
|
||||||
|
os.popupMenu(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: i18n.ts.unrenote,
|
||||||
|
icon: `${icon("ph-trash")}`,
|
||||||
|
danger: true,
|
||||||
|
action: () => {
|
||||||
|
os.api("notes/delete", {
|
||||||
|
noteId: props.note.id,
|
||||||
|
});
|
||||||
|
emit("deleted");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
renoteTime.value,
|
||||||
|
{
|
||||||
|
viaKeyboard,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.renote {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
white-space: pre;
|
||||||
|
color: var(--renote);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
> i {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
width: 1.2em;
|
||||||
|
height: 1.2em;
|
||||||
|
border-radius: 2em;
|
||||||
|
overflow: hidden;
|
||||||
|
margin-right: 0.4em;
|
||||||
|
background: var(--panelHighlight);
|
||||||
|
transform: translateY(-4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
> span {
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 1;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
> .name {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
> .info {
|
||||||
|
margin-left: auto;
|
||||||
|
font-size: 0.9em;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
> .time {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: inherit;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
> .dropdownIcon {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -13,7 +13,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import MkNoteMediaList from "@/components/MkNoteMediaList.vue";
|
import MkNoteMediaList from "@/components/note/MkNoteMediaList.vue";
|
||||||
import MkPagination from "@/components/MkPagination.vue";
|
import MkPagination from "@/components/MkPagination.vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { defineAsyncComponent } from "vue";
|
||||||
import type { entities } from "firefish-js";
|
import type { entities } from "firefish-js";
|
||||||
import { isModerator, isSignedIn, me } from "@/me";
|
import { isModerator, isSignedIn, me } from "@/me";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { instance } from "@/instance";
|
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
||||||
import { url } from "@/config";
|
import { url } from "@/config";
|
||||||
|
@ -13,18 +12,17 @@ import { getUserMenu } from "@/scripts/get-user-menu";
|
||||||
import icon from "@/scripts/icon";
|
import icon from "@/scripts/icon";
|
||||||
import { useRouter } from "@/router";
|
import { useRouter } from "@/router";
|
||||||
import { notePage } from "@/filters/note";
|
import { notePage } from "@/filters/note";
|
||||||
import type { NoteTranslation } from "@/types/note";
|
|
||||||
import type { MenuItem } from "@/types/menu";
|
import type { MenuItem } from "@/types/menu";
|
||||||
import type { NoteDraft } from "@/types/post-form";
|
import type { NoteDraft } from "@/types/post-form";
|
||||||
|
import type MkNoteTranslation from "@/components/note/MkNoteTranslation.vue";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
export function getNoteMenu(props: {
|
export function getNoteMenu(props: {
|
||||||
note: entities.Note;
|
note: entities.Note;
|
||||||
menuButton: Ref<HTMLElement | undefined>;
|
menuButton: Ref<HTMLElement | undefined>;
|
||||||
translation: Ref<NoteTranslation | null>;
|
|
||||||
translating: Ref<boolean>;
|
|
||||||
isDeleted: Ref<boolean>;
|
isDeleted: Ref<boolean>;
|
||||||
|
translationEl: InstanceType<typeof MkNoteTranslation>;
|
||||||
currentClipPage?: Ref<entities.Clip> | null;
|
currentClipPage?: Ref<entities.Clip> | null;
|
||||||
}) {
|
}) {
|
||||||
const isRenote =
|
const isRenote =
|
||||||
|
@ -270,42 +268,11 @@ export function getNoteMenu(props: {
|
||||||
function share(): void {
|
function share(): void {
|
||||||
navigator.share({
|
navigator.share({
|
||||||
title: i18n.t("noteOf", { user: appearNote.user.name }),
|
title: i18n.t("noteOf", { user: appearNote.user.name }),
|
||||||
text: appearNote.text,
|
text: appearNote.text ?? undefined,
|
||||||
url: `${url}/notes/${appearNote.id}`,
|
url: `${url}/notes/${appearNote.id}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function translate_(noteId: number, targetLang: string) {
|
|
||||||
return await os.api("notes/translate", {
|
|
||||||
noteId,
|
|
||||||
targetLang,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function translate(): Promise<void> {
|
|
||||||
const translateLang = localStorage.getItem("translateLang");
|
|
||||||
const lang = localStorage.getItem("lang");
|
|
||||||
|
|
||||||
if (props.translation.value != null) return;
|
|
||||||
props.translating.value = true;
|
|
||||||
props.translation.value = await translate_(
|
|
||||||
appearNote.id,
|
|
||||||
translateLang || lang || navigator.language,
|
|
||||||
);
|
|
||||||
|
|
||||||
// use UI language as the second translation target
|
|
||||||
if (
|
|
||||||
translateLang != null &&
|
|
||||||
lang != null &&
|
|
||||||
translateLang !== lang &&
|
|
||||||
(!props.translation.value ||
|
|
||||||
props.translation.value.sourceLang.toLowerCase() ===
|
|
||||||
translateLang.slice(0, 2))
|
|
||||||
)
|
|
||||||
props.translation.value = await translate_(appearNote.id, lang);
|
|
||||||
props.translating.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let menu: MenuItem[];
|
let menu: MenuItem[];
|
||||||
if (isSignedIn(me)) {
|
if (isSignedIn(me)) {
|
||||||
const statePromise = os.api("notes/state", {
|
const statePromise = os.api("notes/state", {
|
||||||
|
@ -394,11 +361,11 @@ export function getNoteMenu(props: {
|
||||||
action: () => showEditHistory(),
|
action: () => showEditHistory(),
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
instance.translatorAvailable
|
props.translationEl.canTranslate
|
||||||
? {
|
? {
|
||||||
icon: `${icon("ph-translate")}`,
|
icon: `${icon("ph-translate")}`,
|
||||||
text: i18n.ts.translate,
|
text: i18n.ts.translate,
|
||||||
action: translate,
|
action: props.translationEl.translate,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
appearNote.url || appearNote.uri
|
appearNote.url || appearNote.uri
|
||||||
|
|
89
packages/client/src/scripts/show-note-context-menu.ts
Normal file
89
packages/client/src/scripts/show-note-context-menu.ts
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
import { notePage } from "@/filters/note";
|
||||||
|
import * as os from "@/os";
|
||||||
|
import { defaultStore } from "@/store";
|
||||||
|
import type { NoteType } from "@/types/note";
|
||||||
|
import icon from "./icon";
|
||||||
|
import { i18n } from "@/i18n";
|
||||||
|
import copyToClipboard from "./copy-to-clipboard";
|
||||||
|
import { useRouter } from "@/router";
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
import { url } from "@/config";
|
||||||
|
|
||||||
|
export function showNoteContextMenu({
|
||||||
|
ev,
|
||||||
|
note,
|
||||||
|
react,
|
||||||
|
}: {
|
||||||
|
ev: MouseEvent;
|
||||||
|
note: NoteType;
|
||||||
|
react: () => void;
|
||||||
|
}): void {
|
||||||
|
const isLink = (el: HTMLElement): boolean => {
|
||||||
|
if (el.tagName === "A") return true;
|
||||||
|
// The Audio element's context menu is the browser default, such as for selecting playback speed.
|
||||||
|
if (el.tagName === "AUDIO") return true;
|
||||||
|
if (el.parentElement) {
|
||||||
|
return isLink(el.parentElement);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if (isLink(ev.target as HTMLElement)) return;
|
||||||
|
if (window.getSelection()?.toString() !== "") return;
|
||||||
|
|
||||||
|
if (defaultStore.state.useReactionPickerForContextMenu) {
|
||||||
|
ev.preventDefault();
|
||||||
|
react();
|
||||||
|
} else {
|
||||||
|
os.contextMenu(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: "label",
|
||||||
|
text: notePage(note),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: `${icon("ph-browser")}`,
|
||||||
|
text: i18n.ts.openInWindow,
|
||||||
|
action: () => {
|
||||||
|
os.pageWindow(notePage(note));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notePage(note) !== location.pathname
|
||||||
|
? {
|
||||||
|
icon: `${icon("ph-arrows-out-simple")}`,
|
||||||
|
text: i18n.ts.showInPage,
|
||||||
|
action: () => {
|
||||||
|
router.push(notePage(note), "forcePage");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
type: "a",
|
||||||
|
icon: `${icon("ph-arrow-square-out")}`,
|
||||||
|
text: i18n.ts.openInNewTab,
|
||||||
|
href: notePage(note),
|
||||||
|
target: "_blank",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: `${icon("ph-link-simple")}`,
|
||||||
|
text: i18n.ts.copyLink,
|
||||||
|
action: () => {
|
||||||
|
copyToClipboard(`${url}${notePage(note)}`);
|
||||||
|
os.success();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
note.user.host != null
|
||||||
|
? {
|
||||||
|
type: "a",
|
||||||
|
icon: `${icon("ph-arrow-square-up-right")}`,
|
||||||
|
text: i18n.ts.showOnRemote,
|
||||||
|
href: note.url ?? note.uri ?? "",
|
||||||
|
target: "_blank",
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
],
|
||||||
|
ev,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue