From 5b7595d9d7e313271c692a849fc915e73fcea108 Mon Sep 17 00:00:00 2001 From: futchitwo <74236683+futchitwo@users.noreply.github.com> Date: Sat, 18 Jun 2022 18:27:09 +0900 Subject: 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 --- packages/client/src/scripts/get-note-menu.ts | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'packages/client/src/scripts/get-note-menu.ts') 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; translation: Ref; translating: Ref; + isDeleted: Ref; + cullentClipPage?: Ref; }) { 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 { + os.apiWithDialog('clips/remove-note', { clipId: props.cullentClipPage.value.id, noteId: appearNote.id }); + props.isDeleted.value = true; + } + async function promote(): Promise { 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 -- cgit v1.2.3-freya From 802a35d4b6f438f9f931eb5cd791e950deaa445b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 18 Jun 2022 18:27:47 +0900 Subject: fix typo --- packages/client/src/components/note.vue | 6 +++--- packages/client/src/pages/clip.vue | 2 +- packages/client/src/scripts/get-note-menu.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'packages/client/src/scripts/get-note-menu.ts') diff --git a/packages/client/src/components/note.vue b/packages/client/src/components/note.vue index b06f4edd0a..9ec1e53c1e 100644 --- a/packages/client/src/components/note.vue +++ b/packages/client/src/components/note.vue @@ -225,7 +225,7 @@ function undoReact(note): void { }); } -const cullentClipPage = inject>('cullentClipPage'); +const currentClipPage = inject>('currentClipPage'); function onContextmenu(ev: MouseEvent): void { const isLink = (el: HTMLElement) => { @@ -241,12 +241,12 @@ function onContextmenu(ev: MouseEvent): void { ev.preventDefault(); react(); } else { - os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, cullentClipPage }), ev).then(focus); + os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, currentClipPage }), ev).then(focus); } } function menu(viaKeyboard = false): void { - os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, cullentClipPage }), menuButton.value, { + os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted, currentClipPage }), menuButton.value, { viaKeyboard, }).then(focus); } diff --git a/packages/client/src/pages/clip.vue b/packages/client/src/pages/clip.vue index bfe1578b13..163384337e 100644 --- a/packages/client/src/pages/clip.vue +++ b/packages/client/src/pages/clip.vue @@ -47,7 +47,7 @@ watch(() => props.clipId, async () => { immediate: true, }); -provide('cullentClipPage', $$(clip)); +provide('currentClipPage', $$(clip)); defineExpose({ [symbols.PAGE_INFO]: computed(() => clip ? { diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index e56d519493..283c90362c 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -15,7 +15,7 @@ export function getNoteMenu(props: { translation: Ref; translating: Ref; isDeleted: Ref; - cullentClipPage?: Ref; + currentClipPage?: Ref; }) { const isRenote = ( props.note.renote != null && @@ -138,7 +138,7 @@ export function getNoteMenu(props: { }); 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; + if (props.currentClipPage?.value.id === clip.id) props.isDeleted.value = true; } } else { os.alert({ @@ -154,7 +154,7 @@ export function getNoteMenu(props: { } async function unclip(): Promise { - os.apiWithDialog('clips/remove-note', { clipId: props.cullentClipPage.value.id, noteId: appearNote.id }); + os.apiWithDialog('clips/remove-note', { clipId: props.currentClipPage.value.id, noteId: appearNote.id }); props.isDeleted.value = true; } @@ -198,7 +198,7 @@ export function getNoteMenu(props: { menu = [ ...( - props.cullentClipPage?.value.userId === $i.id ? [{ + props.currentClipPage?.value.userId === $i.id ? [{ icon: 'fas fa-circle-minus', text: i18n.ts.unclip, danger: true, -- cgit v1.2.3-freya From bffe6fb9bfa1fe61eab4f03bd318c010644d7afb Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 30 Jun 2022 10:53:40 +0900 Subject: tweak client --- locales/ja-JP.yml | 2 + packages/client/src/components/form/group.vue | 36 --- packages/client/src/components/form/range.vue | 17 +- .../client/src/components/global/router-view.vue | 3 +- packages/client/src/menu.ts | 2 + packages/client/src/pages/admin/object-storage.vue | 1 - packages/client/src/pages/gallery/edit.vue | 7 +- packages/client/src/pages/settings/deck.vue | 6 +- packages/client/src/pages/settings/general.vue | 12 +- packages/client/src/scripts/get-note-menu.ts | 248 ++++++++++----------- packages/client/src/store.ts | 4 + packages/client/src/widgets/instance-cloud.vue | 2 +- 12 files changed, 156 insertions(+), 184 deletions(-) delete mode 100644 packages/client/src/components/form/group.vue (limited to 'packages/client/src/scripts/get-note-menu.ts') diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 9de5b99d17..17de04ebc8 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -858,6 +858,8 @@ isSystemAccount: "システムにより自動で作成・管理されている typeToConfirm: "この操作を行うには {x} と入力してください" deleteAccount: "アカウント削除" document: "ドキュメント" +numberOfPageCache: "ページキャッシュ数" +numberOfPageCacheDescription: "多くすると利便性が向上しますが、負荷とメモリ使用量が増えます。" _emailUnavailable: used: "既に使用されています" diff --git a/packages/client/src/components/form/group.vue b/packages/client/src/components/form/group.vue deleted file mode 100644 index 1e8376ca44..0000000000 --- a/packages/client/src/components/form/group.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - - - diff --git a/packages/client/src/components/form/range.vue b/packages/client/src/components/form/range.vue index ac4a781e32..9bb0164a2e 100644 --- a/packages/client/src/components/form/range.vue +++ b/packages/client/src/components/form/range.vue @@ -4,7 +4,7 @@
-
+
@@ -12,6 +12,7 @@
+
@@ -62,7 +63,7 @@ export default defineComponent({ const thumbEl = ref(); const rawValue = ref((props.modelValue - props.min) / (props.max - props.min)); - const steppedValue = computed(() => { + const steppedRawValue = computed(() => { if (props.step) { const step = props.step / (props.max - props.min); return (step * Math.round(rawValue.value / step)); @@ -71,7 +72,11 @@ export default defineComponent({ } }); const finalValue = computed(() => { - return (steppedValue.value * (props.max - props.min)) + props.min; + if (Number.isInteger(props.step)) { + return Math.round((steppedRawValue.value * (props.max - props.min)) + props.min); + } else { + return (steppedRawValue.value * (props.max - props.min)) + props.min; + } }); watch(finalValue, () => { context.emit('update:modelValue', finalValue.value); @@ -86,10 +91,10 @@ export default defineComponent({ if (containerEl.value == null) { thumbPosition.value = 0; } else { - thumbPosition.value = (containerEl.value.offsetWidth - thumbWidth.value) * steppedValue.value; + thumbPosition.value = (containerEl.value.offsetWidth - thumbWidth.value) * steppedRawValue.value; } }; - watch([steppedValue, containerEl], calcThumbPosition); + watch([steppedRawValue, containerEl], calcThumbPosition); let ro: ResizeObserver | undefined; @@ -154,7 +159,7 @@ export default defineComponent({ return { rawValue, finalValue, - steppedValue, + steppedRawValue, onMousedown, containerEl, thumbEl, diff --git a/packages/client/src/components/global/router-view.vue b/packages/client/src/components/global/router-view.vue index 56b53e0127..7138faaa9d 100644 --- a/packages/client/src/components/global/router-view.vue +++ b/packages/client/src/components/global/router-view.vue @@ -1,5 +1,5 @@ @@ -7,6 +7,7 @@