From b8243c94488944f5f3f4901e64d67162973ae9e0 Mon Sep 17 00:00:00 2001 From: FineArchs Date: Sun, 9 Jun 2024 20:39:43 +0900 Subject: [PATCH] refactor --- packages/frontend/src/components/MkNote.vue | 6 +- .../src/components/MkSubNoteContent.vue | 80 ++++++++++++------- .../frontend/src/pages/settings/general.vue | 6 +- packages/frontend/src/store.ts | 2 +- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 2c19667224..64e542d578 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -289,11 +289,7 @@ const renoteCollapsed = ref( // oversized note collapsing const collapsibleArea = ref(null); -const collapseSize = ({ - small: 9, - medium: 13.5, - large: 18, -})[defaultStore.state.collapsingNoteSize] ?? 13.5; +const collapseSize = defaultStore.state.collapsingNoteSize; const isLong = ref(true); switch (collapsingNoteCondition) { case 'detailedCalculation': diff --git a/packages/frontend/src/components/MkSubNoteContent.vue b/packages/frontend/src/components/MkSubNoteContent.vue index 3b47c831c2..dae949c841 100644 --- a/packages/frontend/src/components/MkSubNoteContent.vue +++ b/packages/frontend/src/components/MkSubNoteContent.vue @@ -4,28 +4,30 @@ SPDX-License-Identifier: AGPL-3.0-only --> @@ -36,7 +38,8 @@ import * as mfm from 'mfm-js'; import MkMediaList from '@/components/MkMediaList.vue'; import MkPoll from '@/components/MkPoll.vue'; import { i18n } from '@/i18n.js'; -import { shouldCollapsed } from '@/scripts/collapsed.js'; +import { defaultStore } from '@/store.js'; +import { shouldCollapseLegacy, shouldCollapse } from '@/scripts/collapsed.js'; const props = defineProps<{ note: Misskey.entities.Note; @@ -44,10 +47,34 @@ const props = defineProps<{ const ast = computed(() => props.note.text ? mfm.parse(props.note.text) : []); -// eslint-disable-next-line vue/no-setup-props-destructure -const isLong = shouldCollapsed(props.note, ast.value); - -const collapsed = ref(isLong); +// oversized note collapsing +const collapsingNoteCondition = defaultStore.state.collapsingNoteCondition; +const collapseSize = defaultStore.state.collapsingNoteSize; +const collapsibleArea = ref(null); +if (collapsingNoteCondition === 'seeRenderedSize') { + onMounted(() => { + const current = collapsibleArea.value.clientHeight; + const limit = collapseSize * parseFloat(getComputedStyle(collapsibleArea.value).fontSize); + isLong.value = current > limit; + collapsed.value &&= isLong.value; + }) +} +const isLong = ref(true); +switch (collapsingNoteCondition) { + case 'detailedCalculation': + // eslint-disable-next-line vue/no-setup-props-destructure + isLong.value = shouldCollapse(props.note, collapseSize, ast.value); + break; + case 'seeRenderedSize': + break; + // fail safe + case 'legacyCalculation': + default: + // eslint-disable-next-line vue/no-setup-props-destructure + isLong.value = shouldCollapseLegacy(props.note, []); + break; +} +const collapsed = ref(isLong.value);