Add in edit buttons

This commit is contained in:
Kaity A 2023-05-07 20:48:55 +10:00
parent fa9a28d230
commit 80897d0a3c

View File

@ -1,6 +1,5 @@
import { defineAsyncComponent, Ref, inject } from "vue"; import { defineAsyncComponent, Ref, inject } from "vue";
import * as misskey from "calckey-js"; import * as misskey from "calckey-js";
import { pleaseLogin } from "./please-login";
import { $i } from "@/account"; import { $i } from "@/account";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { instance } from "@/instance"; import { instance } from "@/instance";
@ -12,7 +11,7 @@ import { shareAvailable } from "@/scripts/share-available";
export function getNoteMenu(props: { export function getNoteMenu(props: {
note: misskey.entities.Note; note: misskey.entities.Note;
menuButton: Ref<HTMLElement>; menuButton: Ref<HTMLElement | undefined>;
translation: Ref<any>; translation: Ref<any>;
translating: Ref<boolean>; translating: Ref<boolean>;
isDeleted: 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 { function toggleFavorite(favorite: boolean): void {
os.apiWithDialog( os.apiWithDialog(
favorite ? "notes/favorites/create" : "notes/favorites/delete", favorite ? "notes/favorites/create" : "notes/favorites/delete",
@ -251,6 +283,9 @@ export function getNoteMenu(props: {
noteId: appearNote.id, noteId: appearNote.id,
}); });
const isAppearAuthor = appearNote.userId === $i.id;
const isModerator = $i.isAdmin || $i.isModerator;
menu = [ menu = [
...(props.currentClipPage?.value.userId === $i.id ...(props.currentClipPage?.value.userId === $i.id
? [ ? [
@ -320,7 +355,7 @@ export function getNoteMenu(props: {
text: i18n.ts.clip, text: i18n.ts.clip,
action: () => clip(), action: () => clip(),
}, },
appearNote.userId !== $i.id !isAppearAuthor
? statePromise.then((state) => ? statePromise.then((state) =>
state.isWatching state.isWatching
? { ? {
@ -348,7 +383,7 @@ export function getNoteMenu(props: {
action: () => toggleThreadMute(true), action: () => toggleThreadMute(true),
}, },
), ),
appearNote.userId === $i.id isAppearAuthor
? ($i.pinnedNoteIds || []).includes(appearNote.id) ? ($i.pinnedNoteIds || []).includes(appearNote.id)
? { ? {
icon: "ph-push-pin ph-bold ph-lg", icon: "ph-push-pin ph-bold ph-lg",
@ -371,7 +406,7 @@ export function getNoteMenu(props: {
}] }]
: [] : []
),*/ ),*/
...(appearNote.userId !== $i.id ...(!isAppearAuthor
? [ ? [
null, null,
{ {
@ -397,24 +432,41 @@ export function getNoteMenu(props: {
}, },
] ]
: []), : []),
...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin
? [ null,
null,
appearNote.userId === $i.id isAppearAuthor
? { ? {
icon: "ph-eraser ph-bold ph-lg", icon: "ph-pencil-line ph-bold ph-lg",
text: i18n.ts.deleteAndEdit, text: i18n.ts.edit,
action: delEdit, textStyle: "color: var(--accent)",
} action: edit,
: undefined, }
{ : undefined,
icon: "ph-trash ph-bold ph-lg",
text: i18n.ts.delete, {
danger: true, icon: "ph-copy ph-bold ph-lg",
action: del, 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,
].filter((x) => x !== undefined); ].filter((x) => x !== undefined);
} else { } else {
menu = [ menu = [