summaryrefslogtreecommitdiff
path: root/packages/client/src
diff options
context:
space:
mode:
authorfutchitwo <74236683+futchitwo@users.noreply.github.com>2022-06-18 18:27:09 +0900
committerGitHub <noreply@github.com>2022-06-18 18:27:09 +0900
commit5b7595d9d7e313271c692a849fc915e73fcea108 (patch)
tree2e20578ce771986d813bba100004469f37c65b24 /packages/client/src
parentRefactor clip page to Composition API (#8822) (diff)
downloadsharkey-5b7595d9d7e313271c692a849fc915e73fcea108.tar.gz
sharkey-5b7595d9d7e313271c692a849fc915e73fcea108.tar.bz2
sharkey-5b7595d9d7e313271c692a849fc915e73fcea108.zip
Improve: unclip (#8823)
* Refactor clip page to use Composition API * Refactor clip page * Refactor clip page * Refactor clip page * Improve: unclip * Fix unclip * Fix unclip * chore: better type and name * Fix * Fix clipPage vue provider Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/client/src')
-rw-r--r--packages/client/src/components/note-detailed.vue4
-rw-r--r--packages/client/src/components/note.vue8
-rw-r--r--packages/client/src/pages/clip.vue4
-rw-r--r--packages/client/src/scripts/get-note-menu.ts42
4 files changed, 49 insertions, 9 deletions
diff --git a/packages/client/src/components/note-detailed.vue b/packages/client/src/components/note-detailed.vue
index 6234b710d2..ba47bfcd4a 100644
--- a/packages/client/src/components/note-detailed.vue
+++ b/packages/client/src/components/note-detailed.vue
@@ -251,12 +251,12 @@ function onContextmenu(ev: MouseEvent): void {
ev.preventDefault();
react();
} else {
- os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton }), ev).then(focus);
+ os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted }), ev).then(focus);
}
}
function menu(viaKeyboard = false): void {
- os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton }), menuButton.value, {
+ os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted }), menuButton.value, {
viaKeyboard,
}).then(focus);
}
diff --git a/packages/client/src/components/note.vue b/packages/client/src/components/note.vue
index e5744d1ce9..b06f4edd0a 100644
--- a/packages/client/src/components/note.vue
+++ b/packages/client/src/components/note.vue
@@ -105,7 +105,7 @@
</template>
<script lang="ts" setup>
-import { computed, inject, onMounted, onUnmounted, reactive, ref } from 'vue';
+import { computed, inject, onMounted, onUnmounted, reactive, ref, Ref } from 'vue';
import * as mfm from 'mfm-js';
import * as misskey from 'misskey-js';
import MkNoteSub from './MkNoteSub.vue';
@@ -225,6 +225,8 @@ function undoReact(note): void {
});
}
+const cullentClipPage = inject<Ref<misskey.entities.Clip>>('cullentClipPage');
+
function onContextmenu(ev: MouseEvent): void {
const isLink = (el: HTMLElement) => {
if (el.tagName === 'A') return true;
@@ -239,12 +241,12 @@ function onContextmenu(ev: MouseEvent): void {
ev.preventDefault();
react();
} else {
- os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton }), ev).then(focus);
+ os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, cullentClipPage }), ev).then(focus);
}
}
function menu(viaKeyboard = false): void {
- os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton }), menuButton.value, {
+ os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, cullentClipPage }), menuButton.value, {
viaKeyboard,
}).then(focus);
}
diff --git a/packages/client/src/pages/clip.vue b/packages/client/src/pages/clip.vue
index cfe11efd1c..bfe1578b13 100644
--- a/packages/client/src/pages/clip.vue
+++ b/packages/client/src/pages/clip.vue
@@ -16,7 +16,7 @@
</template>
<script lang="ts" setup>
-import { computed, watch } from 'vue';
+import { computed, watch, provide } from 'vue';
import * as misskey from 'misskey-js';
import XNotes from '@/components/notes.vue';
import { $i } from '@/account';
@@ -47,6 +47,8 @@ watch(() => props.clipId, async () => {
immediate: true,
});
+provide('cullentClipPage', $$(clip));
+
defineExpose({
[symbols.PAGE_INFO]: computed(() => clip ? {
title: clip.name,
diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts
index 78749ad6bb..e56d519493 100644
--- a/packages/client/src/scripts/get-note-menu.ts
+++ b/packages/client/src/scripts/get-note-menu.ts
@@ -1,4 +1,4 @@
-import { defineAsyncComponent, Ref } from 'vue';
+import { defineAsyncComponent, Ref, inject } from 'vue';
import * as misskey from 'misskey-js';
import { $i } from '@/account';
import { i18n } from '@/i18n';
@@ -14,6 +14,8 @@ export function getNoteMenu(props: {
menuButton: Ref<HTMLElement>;
translation: Ref<any>;
translating: Ref<boolean>;
+ isDeleted: Ref<boolean>;
+ cullentClipPage?: Ref<misskey.entities.Clip>;
}) {
const isRenote = (
props.note.renote != null &&
@@ -125,12 +127,37 @@ export function getNoteMenu(props: {
}, null, ...clips.map(clip => ({
text: clip.name,
action: () => {
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: appearNote.id });
+ os.promiseDialog(
+ os.api('clips/add-note', { clipId: clip.id, noteId: appearNote.id }),
+ null,
+ async (err) => {
+ if (err.id === '734806c4-542c-463a-9311-15c512803965') {
+ const confirm = await os.confirm({
+ type: 'warning',
+ text: i18n.t('confirmToUnclipAlreadyClippedNote', { name: clip.name }),
+ });
+ if (!confirm.canceled) {
+ os.apiWithDialog('clips/remove-note', { clipId: clip.id, noteId: appearNote.id });
+ if (props.cullentClipPage?.value.id === clip.id) props.isDeleted.value = true;
+ }
+ } else {
+ os.alert({
+ type: 'error',
+ text: err.message + '\n' + err.id,
+ });
+ }
+ }
+ );
}
}))], props.menuButton.value, {
}).then(focus);
}
+ async function unclip(): Promise<void> {
+ os.apiWithDialog('clips/remove-note', { clipId: props.cullentClipPage.value.id, noteId: appearNote.id });
+ props.isDeleted.value = true;
+ }
+
async function promote(): Promise<void> {
const { canceled, result: days } = await os.inputNumber({
title: i18n.ts.numberOfDays,
@@ -169,7 +196,16 @@ export function getNoteMenu(props: {
noteId: appearNote.id
});
- menu = [{
+ menu = [
+ ...(
+ props.cullentClipPage?.value.userId === $i.id ? [{
+ icon: 'fas fa-circle-minus',
+ text: i18n.ts.unclip,
+ danger: true,
+ action: unclip,
+ }, null] : []
+ ),
+ {
icon: 'fas fa-copy',
text: i18n.ts.copyContent,
action: copyContent