Add in edit buttons

This commit is contained in:
Kaity A 2023-05-07 20:48:55 +10:00
parent 8e4d38cb45
commit 1b5d2084d8
No known key found for this signature in database
GPG Key ID: 5A797B97C2A490AD
1 changed files with 75 additions and 23 deletions

View File

@ -1,6 +1,5 @@
import { defineAsyncComponent, Ref, inject } from "vue";
import * as misskey from "calckey-js";
import { pleaseLogin } from "./please-login";
import { $i } from "@/account";
import { i18n } from "@/i18n";
import { instance } from "@/instance";
@ -12,7 +11,7 @@ import { shareAvailable } from "@/scripts/share-available";
export function getNoteMenu(props: {
note: misskey.entities.Note;
menuButton: Ref<HTMLElement>;
menuButton: Ref<HTMLElement | undefined>;
translation: Ref<any>;
translating: Ref<boolean>;
isDeleted: Ref<boolean>;
@ -61,6 +60,39 @@ export function getNoteMenu(props: {
});
}
function edit(): void {
os.confirm({
type: "info",
text: "This feature is experimental, please be careful and report bugs if you find them to @supakaity@blahaj.zone.",
}).then(({ canceled }) => {
if (canceled) return;
os.post({
initialNote: appearNote,
renote: appearNote.renote,
reply: appearNote.reply,
channel: appearNote.channel,
editId: appearNote.id,
});
});
}
function duplicate(): void {
os.confirm({
type: "info",
text: "This feature is experimental, please be careful and report bugs if you find them to @supakaity@blahaj.zone.",
}).then(({ canceled }) => {
if (canceled) return;
os.post({
initialNote: appearNote,
renote: appearNote.renote,
reply: appearNote.reply,
channel: appearNote.channel,
});
});
}
function toggleFavorite(favorite: boolean): void {
os.apiWithDialog(
favorite ? "notes/favorites/create" : "notes/favorites/delete",
@ -251,6 +283,9 @@ export function getNoteMenu(props: {
noteId: appearNote.id,
});
const isAppearAuthor = appearNote.userId === $i.id;
const isModerator = $i.isAdmin || $i.isModerator;
menu = [
...(props.currentClipPage?.value.userId === $i.id
? [
@ -320,7 +355,7 @@ export function getNoteMenu(props: {
text: i18n.ts.clip,
action: () => clip(),
},
appearNote.userId !== $i.id
!isAppearAuthor
? statePromise.then((state) =>
state.isWatching
? {
@ -348,7 +383,7 @@ export function getNoteMenu(props: {
action: () => toggleThreadMute(true),
},
),
appearNote.userId === $i.id
isAppearAuthor
? ($i.pinnedNoteIds || []).includes(appearNote.id)
? {
icon: "ph-push-pin ph-bold ph-lg",
@ -371,7 +406,7 @@ export function getNoteMenu(props: {
}]
: []
),*/
...(appearNote.userId !== $i.id
...(!isAppearAuthor
? [
null,
{
@ -397,24 +432,41 @@ export function getNoteMenu(props: {
},
]
: []),
...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin
? [
null,
appearNote.userId === $i.id
isAppearAuthor
? {
icon: "ph-pencil-line ph-bold ph-lg",
text: i18n.ts.edit,
textStyle: "color: var(--accent)",
action: edit,
}
: undefined,
{
icon: "ph-copy ph-bold ph-lg",
text: i18n.ts.duplicate,
textStyle: "color: var(--accent)",
action: duplicate,
},
isAppearAuthor || isModerator
? {
icon: "ph-trash ph-bold ph-lg",
text: i18n.ts.delete,
danger: true,
action: del,
}
: undefined,
isAppearAuthor
? {
icon: "ph-eraser ph-bold ph-lg",
text: i18n.ts.deleteAndEdit,
action: delEdit,
}
: undefined,
{
icon: "ph-trash ph-bold ph-lg",
text: i18n.ts.delete,
danger: true,
action: del,
},
]
: []),
].filter((x) => x !== undefined);
} else {
menu = [