diff options
| author | zyoshoka <107108195+zyoshoka@users.noreply.github.com> | 2023-12-07 14:42:09 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-07 14:42:09 +0900 |
| commit | 406b4bdbe79b5b0b68fcdcb3c4b6e419460a0258 (patch) | |
| tree | a1af1cc6102d2db40a687bc848c07cce35bd414f /packages/frontend/src/components/global | |
| parent | feat: Roleに関するSchemaを追加 (#12572) (diff) | |
| download | misskey-406b4bdbe79b5b0b68fcdcb3c4b6e419460a0258.tar.gz misskey-406b4bdbe79b5b0b68fcdcb3c4b6e419460a0258.tar.bz2 misskey-406b4bdbe79b5b0b68fcdcb3c4b6e419460a0258.zip | |
refactor(frontend): 非推奨となったReactivity Transformを使わないように (#12539)
* refactor(frontend): 非推奨となったReactivity Transformを使わないように
* refactor: 不要な括弧を除去
* fix: 不要なアノテーションを除去
* fix: Refの配列をrefしている部分の対応
* refactor: 不要な括弧を除去
* fix: lint
* refactor: Ref、ShallowRef、ComputedRefの変数の宣言をletからconstに置換
* fix: type error
* chore: drop reactivity transform from eslint configuration
* refactor: remove unnecessary import
* fix: 対応漏れ
Diffstat (limited to 'packages/frontend/src/components/global')
8 files changed, 86 insertions, 85 deletions
diff --git a/packages/frontend/src/components/global/MkA.vue b/packages/frontend/src/components/global/MkA.vue index 2c50511b8b..008d10f8eb 100644 --- a/packages/frontend/src/components/global/MkA.vue +++ b/packages/frontend/src/components/global/MkA.vue @@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> +import { computed } from 'vue'; import * as os from '@/os.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import { url } from '@/config.js'; @@ -28,7 +29,7 @@ const props = withDefaults(defineProps<{ const router = useRouter(); -const active = $computed(() => { +const active = computed(() => { if (props.activeClass == null) return false; const resolved = router.resolve(props.to); if (resolved == null) return false; diff --git a/packages/frontend/src/components/global/MkAd.vue b/packages/frontend/src/components/global/MkAd.vue index 421fe99127..3ef5db3fe3 100644 --- a/packages/frontend/src/components/global/MkAd.vue +++ b/packages/frontend/src/components/global/MkAd.vue @@ -96,7 +96,7 @@ const choseAd = (): Ad | null => { }; const chosen = ref(choseAd()); -const shouldHide = $ref(!defaultStore.state.forceShowAds && $i && $i.policies.canHideAds && (props.specify == null)); +const shouldHide = ref(!defaultStore.state.forceShowAds && $i && $i.policies.canHideAds && (props.specify == null)); function reduceFrequency(): void { if (chosen.value == null) return; diff --git a/packages/frontend/src/components/global/MkAvatar.vue b/packages/frontend/src/components/global/MkAvatar.vue index 51a454b2cc..c7e50e275a 100644 --- a/packages/frontend/src/components/global/MkAvatar.vue +++ b/packages/frontend/src/components/global/MkAvatar.vue @@ -37,7 +37,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { watch } from 'vue'; +import { watch, ref, computed } from 'vue'; import * as Misskey from 'misskey-js'; import MkImgWithBlurhash from '../MkImgWithBlurhash.vue'; import MkA from './MkA.vue'; @@ -47,9 +47,9 @@ import { acct, userPage } from '@/filters/user.js'; import MkUserOnlineIndicator from '@/components/MkUserOnlineIndicator.vue'; import { defaultStore } from '@/store.js'; -const animation = $ref(defaultStore.state.animation); -const squareAvatars = $ref(defaultStore.state.squareAvatars); -const useBlurEffect = $ref(defaultStore.state.useBlurEffect); +const animation = ref(defaultStore.state.animation); +const squareAvatars = ref(defaultStore.state.squareAvatars); +const useBlurEffect = ref(defaultStore.state.useBlurEffect); const props = withDefaults(defineProps<{ user: Misskey.entities.User; @@ -79,11 +79,11 @@ const emit = defineEmits<{ const showDecoration = props.forceShowDecoration || defaultStore.state.showAvatarDecorations; -const bound = $computed(() => props.link +const bound = computed(() => props.link ? { to: userPage(props.user), target: props.target } : {}); -const url = $computed(() => (defaultStore.state.disableShowingAnimatedImages || defaultStore.state.dataSaver.avatar) +const url = computed(() => (defaultStore.state.disableShowingAnimatedImages || defaultStore.state.dataSaver.avatar) ? getStaticImageUrl(props.user.avatarUrl) : props.user.avatarUrl); @@ -116,10 +116,10 @@ function getDecorationScale() { return scaleX === 1 ? undefined : `${scaleX} 1`; } -let color = $ref<string | undefined>(); +const color = ref<string | undefined>(); watch(() => props.user.avatarBlurhash, () => { - color = extractAvgColorFromBlurhash(props.user.avatarBlurhash); + color.value = extractAvgColorFromBlurhash(props.user.avatarBlurhash); }, { immediate: true, }); diff --git a/packages/frontend/src/components/global/MkCustomEmoji.vue b/packages/frontend/src/components/global/MkCustomEmoji.vue index 1e17bab849..a092497307 100644 --- a/packages/frontend/src/components/global/MkCustomEmoji.vue +++ b/packages/frontend/src/components/global/MkCustomEmoji.vue @@ -19,7 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { computed, inject } from 'vue'; +import { computed, inject, ref } from 'vue'; import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js'; import { defaultStore } from '@/store.js'; import { customEmojisMap } from '@/custom-emojis.js'; @@ -71,7 +71,7 @@ const url = computed(() => { }); const alt = computed(() => `:${customEmojiName.value}:`); -let errored = $ref(url.value == null); +const errored = ref(url.value == null); function onClick(ev: MouseEvent) { if (props.menu) { diff --git a/packages/frontend/src/components/global/MkPageHeader.vue b/packages/frontend/src/components/global/MkPageHeader.vue index 935ca33eb5..301e691fa0 100644 --- a/packages/frontend/src/components/global/MkPageHeader.vue +++ b/packages/frontend/src/components/global/MkPageHeader.vue @@ -41,7 +41,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { onMounted, onUnmounted, ref, inject } from 'vue'; +import { onMounted, onUnmounted, ref, inject, shallowRef, computed } from 'vue'; import tinycolor from 'tinycolor2'; import XTabs, { Tab } from './MkPageHeader.tabs.vue'; import { scrollToTop } from '@/scripts/scroll.js'; @@ -69,13 +69,13 @@ const metadata = injectPageMetadata(); const hideTitle = inject('shouldOmitHeaderTitle', false); const thin_ = props.thin || inject('shouldHeaderThin', false); -let el = $shallowRef<HTMLElement | undefined>(undefined); +const el = shallowRef<HTMLElement | undefined>(undefined); const bg = ref<string | undefined>(undefined); -let narrow = $ref(false); -const hasTabs = $computed(() => props.tabs.length > 0); -const hasActions = $computed(() => props.actions && props.actions.length > 0); -const show = $computed(() => { - return !hideTitle || hasTabs || hasActions; +const narrow = ref(false); +const hasTabs = computed(() => props.tabs.length > 0); +const hasActions = computed(() => props.actions && props.actions.length > 0); +const show = computed(() => { + return !hideTitle || hasTabs.value || hasActions.value; }); const preventDrag = (ev: TouchEvent) => { @@ -83,8 +83,8 @@ const preventDrag = (ev: TouchEvent) => { }; const top = () => { - if (el) { - scrollToTop(el as HTMLElement, { behavior: 'smooth' }); + if (el.value) { + scrollToTop(el.value as HTMLElement, { behavior: 'smooth' }); } }; @@ -111,14 +111,14 @@ onMounted(() => { calcBg(); globalEvents.on('themeChanged', calcBg); - if (el && el.parentElement) { - narrow = el.parentElement.offsetWidth < 500; + if (el.value && el.value.parentElement) { + narrow.value = el.value.parentElement.offsetWidth < 500; ro = new ResizeObserver((entries, observer) => { - if (el && el.parentElement && document.body.contains(el as HTMLElement)) { - narrow = el.parentElement.offsetWidth < 500; + if (el.value && el.value.parentElement && document.body.contains(el.value as HTMLElement)) { + narrow.value = el.value.parentElement.offsetWidth < 500; } }); - ro.observe(el.parentElement as HTMLElement); + ro.observe(el.value.parentElement as HTMLElement); } }); diff --git a/packages/frontend/src/components/global/MkStickyContainer.vue b/packages/frontend/src/components/global/MkStickyContainer.vue index 8e9bff11d1..1d707af2d1 100644 --- a/packages/frontend/src/components/global/MkStickyContainer.vue +++ b/packages/frontend/src/components/global/MkStickyContainer.vue @@ -18,36 +18,36 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { onMounted, onUnmounted, provide, inject, Ref, ref, watch } from 'vue'; -import { $$ } from 'vue/macros'; +import { onMounted, onUnmounted, provide, inject, Ref, ref, watch, shallowRef } from 'vue'; + import { CURRENT_STICKY_BOTTOM, CURRENT_STICKY_TOP } from '@/const'; -const rootEl = $shallowRef<HTMLElement>(); -const headerEl = $shallowRef<HTMLElement>(); -const footerEl = $shallowRef<HTMLElement>(); -const bodyEl = $shallowRef<HTMLElement>(); +const rootEl = shallowRef<HTMLElement>(); +const headerEl = shallowRef<HTMLElement>(); +const footerEl = shallowRef<HTMLElement>(); +const bodyEl = shallowRef<HTMLElement>(); -let headerHeight = $ref<string | undefined>(); -let childStickyTop = $ref(0); +const headerHeight = ref<string | undefined>(); +const childStickyTop = ref(0); const parentStickyTop = inject<Ref<number>>(CURRENT_STICKY_TOP, ref(0)); -provide(CURRENT_STICKY_TOP, $$(childStickyTop)); +provide(CURRENT_STICKY_TOP, childStickyTop); -let footerHeight = $ref<string | undefined>(); -let childStickyBottom = $ref(0); +const footerHeight = ref<string | undefined>(); +const childStickyBottom = ref(0); const parentStickyBottom = inject<Ref<number>>(CURRENT_STICKY_BOTTOM, ref(0)); -provide(CURRENT_STICKY_BOTTOM, $$(childStickyBottom)); +provide(CURRENT_STICKY_BOTTOM, childStickyBottom); const calc = () => { // コンポーネントが表示されてないけどKeepAliveで残ってる場合などは null になる - if (headerEl != null) { - childStickyTop = parentStickyTop.value + headerEl.offsetHeight; - headerHeight = headerEl.offsetHeight.toString(); + if (headerEl.value != null) { + childStickyTop.value = parentStickyTop.value + headerEl.value.offsetHeight; + headerHeight.value = headerEl.value.offsetHeight.toString(); } // コンポーネントが表示されてないけどKeepAliveで残ってる場合などは null になる - if (footerEl != null) { - childStickyBottom = parentStickyBottom.value + footerEl.offsetHeight; - footerHeight = footerEl.offsetHeight.toString(); + if (footerEl.value != null) { + childStickyBottom.value = parentStickyBottom.value + footerEl.value.offsetHeight; + footerHeight.value = footerEl.value.offsetHeight.toString(); } }; @@ -62,28 +62,28 @@ onMounted(() => { watch([parentStickyTop, parentStickyBottom], calc); - watch($$(childStickyTop), () => { - bodyEl.style.setProperty('--stickyTop', `${childStickyTop}px`); + watch(childStickyTop, () => { + bodyEl.value.style.setProperty('--stickyTop', `${childStickyTop.value}px`); }, { immediate: true, }); - watch($$(childStickyBottom), () => { - bodyEl.style.setProperty('--stickyBottom', `${childStickyBottom}px`); + watch(childStickyBottom, () => { + bodyEl.value.style.setProperty('--stickyBottom', `${childStickyBottom.value}px`); }, { immediate: true, }); - headerEl.style.position = 'sticky'; - headerEl.style.top = 'var(--stickyTop, 0)'; - headerEl.style.zIndex = '1000'; + headerEl.value.style.position = 'sticky'; + headerEl.value.style.top = 'var(--stickyTop, 0)'; + headerEl.value.style.zIndex = '1000'; - footerEl.style.position = 'sticky'; - footerEl.style.bottom = 'var(--stickyBottom, 0)'; - footerEl.style.zIndex = '1000'; + footerEl.value.style.position = 'sticky'; + footerEl.value.style.bottom = 'var(--stickyBottom, 0)'; + footerEl.value.style.zIndex = '1000'; - observer.observe(headerEl); - observer.observe(footerEl); + observer.observe(headerEl.value); + observer.observe(footerEl.value); }); onUnmounted(() => { @@ -91,6 +91,6 @@ onUnmounted(() => { }); defineExpose({ - rootEl: $$(rootEl), + rootEl: rootEl, }); </script> diff --git a/packages/frontend/src/components/global/MkTime.vue b/packages/frontend/src/components/global/MkTime.vue index 2eeab4d284..e11db9dc31 100644 --- a/packages/frontend/src/components/global/MkTime.vue +++ b/packages/frontend/src/components/global/MkTime.vue @@ -14,7 +14,7 @@ SPDX-License-Identifier: AGPL-3.0-only <script lang="ts" setup> import isChromatic from 'chromatic/isChromatic'; -import { onMounted, onUnmounted } from 'vue'; +import { onMounted, onUnmounted, ref, computed } from 'vue'; import { i18n } from '@/i18n.js'; import { dateTimeFormat } from '@/scripts/intl-const.js'; @@ -47,29 +47,29 @@ const invalid = Number.isNaN(_time); const absolute = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid; // eslint-disable-next-line vue/no-setup-props-destructure -let now = $ref((props.origin ?? new Date()).getTime()); -const ago = $computed(() => (now - _time) / 1000/*ms*/); +const now = ref((props.origin ?? new Date()).getTime()); +const ago = computed(() => (now.value - _time) / 1000/*ms*/); -const relative = $computed<string>(() => { +const relative = computed<string>(() => { if (props.mode === 'absolute') return ''; // absoluteではrelativeを使わないので計算しない if (invalid) return i18n.ts._ago.invalid; return ( - ago >= 31536000 ? i18n.t('_ago.yearsAgo', { n: Math.round(ago / 31536000).toString() }) : - ago >= 2592000 ? i18n.t('_ago.monthsAgo', { n: Math.round(ago / 2592000).toString() }) : - ago >= 604800 ? i18n.t('_ago.weeksAgo', { n: Math.round(ago / 604800).toString() }) : - ago >= 86400 ? i18n.t('_ago.daysAgo', { n: Math.round(ago / 86400).toString() }) : - ago >= 3600 ? i18n.t('_ago.hoursAgo', { n: Math.round(ago / 3600).toString() }) : - ago >= 60 ? i18n.t('_ago.minutesAgo', { n: (~~(ago / 60)).toString() }) : - ago >= 10 ? i18n.t('_ago.secondsAgo', { n: (~~(ago % 60)).toString() }) : - ago >= -3 ? i18n.ts._ago.justNow : - ago < -31536000 ? i18n.t('_timeIn.years', { n: Math.round(-ago / 31536000).toString() }) : - ago < -2592000 ? i18n.t('_timeIn.months', { n: Math.round(-ago / 2592000).toString() }) : - ago < -604800 ? i18n.t('_timeIn.weeks', { n: Math.round(-ago / 604800).toString() }) : - ago < -86400 ? i18n.t('_timeIn.days', { n: Math.round(-ago / 86400).toString() }) : - ago < -3600 ? i18n.t('_timeIn.hours', { n: Math.round(-ago / 3600).toString() }) : - ago < -60 ? i18n.t('_timeIn.minutes', { n: (~~(-ago / 60)).toString() }) : - i18n.t('_timeIn.seconds', { n: (~~(-ago % 60)).toString() }) + ago.value >= 31536000 ? i18n.t('_ago.yearsAgo', { n: Math.round(ago.value / 31536000).toString() }) : + ago.value >= 2592000 ? i18n.t('_ago.monthsAgo', { n: Math.round(ago.value / 2592000).toString() }) : + ago.value >= 604800 ? i18n.t('_ago.weeksAgo', { n: Math.round(ago.value / 604800).toString() }) : + ago.value >= 86400 ? i18n.t('_ago.daysAgo', { n: Math.round(ago.value / 86400).toString() }) : + ago.value >= 3600 ? i18n.t('_ago.hoursAgo', { n: Math.round(ago.value / 3600).toString() }) : + ago.value >= 60 ? i18n.t('_ago.minutesAgo', { n: (~~(ago.value / 60)).toString() }) : + ago.value >= 10 ? i18n.t('_ago.secondsAgo', { n: (~~(ago.value % 60)).toString() }) : + ago.value >= -3 ? i18n.ts._ago.justNow : + ago.value < -31536000 ? i18n.t('_timeIn.years', { n: Math.round(-ago.value / 31536000).toString() }) : + ago.value < -2592000 ? i18n.t('_timeIn.months', { n: Math.round(-ago.value / 2592000).toString() }) : + ago.value < -604800 ? i18n.t('_timeIn.weeks', { n: Math.round(-ago.value / 604800).toString() }) : + ago.value < -86400 ? i18n.t('_timeIn.days', { n: Math.round(-ago.value / 86400).toString() }) : + ago.value < -3600 ? i18n.t('_timeIn.hours', { n: Math.round(-ago.value / 3600).toString() }) : + ago.value < -60 ? i18n.t('_timeIn.minutes', { n: (~~(-ago.value / 60)).toString() }) : + i18n.t('_timeIn.seconds', { n: (~~(-ago.value % 60)).toString() }) ); }); @@ -77,8 +77,8 @@ let tickId: number; let currentInterval: number; function tick() { - now = (new Date()).getTime(); - const nextInterval = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000; + now.value = (new Date()).getTime(); + const nextInterval = ago.value < 60 ? 10000 : ago.value < 3600 ? 60000 : 180000; if (currentInterval !== nextInterval) { if (tickId) window.clearInterval(tickId); diff --git a/packages/frontend/src/components/global/RouterView.vue b/packages/frontend/src/components/global/RouterView.vue index 99f42f4fcb..9da8f8c379 100644 --- a/packages/frontend/src/components/global/RouterView.vue +++ b/packages/frontend/src/components/global/RouterView.vue @@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts" setup> -import { inject, onBeforeUnmount, provide } from 'vue'; +import { inject, onBeforeUnmount, provide, shallowRef, ref } from 'vue'; import { Resolved, Router } from '@/nirax'; import { defaultStore } from '@/store.js'; @@ -46,16 +46,16 @@ function resolveNested(current: Resolved, d = 0): Resolved | null { } const current = resolveNested(router.current)!; -let currentPageComponent = $shallowRef(current.route.component); -let currentPageProps = $ref(current.props); -let key = $ref(current.route.path + JSON.stringify(Object.fromEntries(current.props))); +const currentPageComponent = shallowRef(current.route.component); +const currentPageProps = ref(current.props); +const key = ref(current.route.path + JSON.stringify(Object.fromEntries(current.props))); function onChange({ resolved, key: newKey }) { const current = resolveNested(resolved); if (current == null) return; - currentPageComponent = current.route.component; - currentPageProps = current.props; - key = current.route.path + JSON.stringify(Object.fromEntries(current.props)); + currentPageComponent.value = current.route.component; + currentPageProps.value = current.props; + key.value = current.route.path + JSON.stringify(Object.fromEntries(current.props)); } router.addListener('change', onChange); |