From b80ec1fa3ff556761d25b7ad63a52555b12289a2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 1 Mar 2022 21:36:20 +0900 Subject: [PATCH] refactor --- .../client/src/components/autocomplete.vue | 26 ++++++------ packages/client/src/components/captcha.vue | 2 +- .../src/components/date-separated-list.vue | 4 +- packages/client/src/components/mfm.ts | 2 +- .../src/components/notification-toast.vue | 41 ++++++++----------- packages/client/src/components/toast.vue | 4 +- .../client/src/components/url-preview.vue | 2 +- packages/client/src/os.ts | 2 +- packages/client/src/pages/settings/theme.vue | 4 +- 9 files changed, 40 insertions(+), 47 deletions(-) diff --git a/packages/client/src/components/autocomplete.vue b/packages/client/src/components/autocomplete.vue index 91a50ffa5..d5bca25c5 100644 --- a/packages/client/src/components/autocomplete.vue +++ b/packages/client/src/components/autocomplete.vue @@ -57,7 +57,7 @@ const lib = emojilist.filter(x => x.category !== 'flags'); const char2file = (char: string) => { let codes = Array.from(char).map(x => x.codePointAt(0)?.toString(16)); - if (!codes.includes('200d')) codes = codes.filter(x => x != 'fe0f'); + if (!codes.includes('200d')) codes = codes.filter(x => x !== 'fe0f'); return codes.filter(x => x && x.length).join('-'); }; @@ -208,7 +208,7 @@ function exec() { }); } } else if (props.type === 'hashtag') { - if (!props.q || props.q == '') { + if (!props.q || props.q === '') { hashtags.value = JSON.parse(localStorage.getItem('hashtags') || '[]'); fetching.value = false; } else { @@ -231,7 +231,7 @@ function exec() { } } } else if (props.type === 'emoji') { - if (!props.q || props.q == '') { + if (!props.q || props.q === '') { // 最近使った絵文字をサジェスト emojis.value = defaultStore.state.recentlyUsedEmojis.map(emoji => emojiDb.find(e => e.emoji == emoji)).filter(x => x) as EmojiDef[]; return; @@ -241,37 +241,37 @@ function exec() { const max = 30; emojiDb.some(x => { - if (x.name.startsWith(props.q || '') && !x.aliasOf && !matched.some(y => y.emoji == x.emoji)) matched.push(x); - return matched.length == max; + if (x.name.startsWith(props.q ?? '') && !x.aliasOf && !matched.some(y => y.emoji === x.emoji)) matched.push(x); + return matched.length === max; }); if (matched.length < max) { emojiDb.some(x => { - if (x.name.startsWith(props.q || '') && !matched.some(y => y.emoji == x.emoji)) matched.push(x); - return matched.length == max; + if (x.name.startsWith(props.q ?? '') && !matched.some(y => y.emoji === x.emoji)) matched.push(x); + return matched.length === max; }); } if (matched.length < max) { emojiDb.some(x => { - if (x.name.includes(props.q || '') && !matched.some(y => y.emoji == x.emoji)) matched.push(x); - return matched.length == max; + if (x.name.includes(props.q ?? '') && !matched.some(y => y.emoji === x.emoji)) matched.push(x); + return matched.length === max; }); } emojis.value = matched; } else if (props.type === 'mfmTag') { - if (!props.q || props.q == '') { + if (!props.q || props.q === '') { mfmTags.value = MFM_TAGS; return; } - mfmTags.value = MFM_TAGS.filter(tag => tag.startsWith(props.q || '')); + mfmTags.value = MFM_TAGS.filter(tag => tag.startsWith(props.q ?? '')); } } function onMousedown(e: Event) { - if (!contains(rootEl.value, e.target) && (rootEl.value != e.target)) props.close(); + if (!contains(rootEl.value, e.target) && (rootEl.value !== e.target)) props.close(); } function onKeydown(e: KeyboardEvent) { @@ -348,7 +348,7 @@ function chooseUser() { onUpdated(() => { setPosition(); - items.value = suggests.value?.children || []; + items.value = suggests.value?.children ?? []; }); onMounted(() => { diff --git a/packages/client/src/components/captcha.vue b/packages/client/src/components/captcha.vue index 963ae25f8..ccd8880df 100644 --- a/packages/client/src/components/captcha.vue +++ b/packages/client/src/components/captcha.vue @@ -93,7 +93,7 @@ function requestRender() { } function callback(response?: string) { - emit('update:modelValue', typeof response == 'string' ? response : null); + emit('update:modelValue', typeof response === 'string' ? response : null); } onMounted(() => { diff --git a/packages/client/src/components/date-separated-list.vue b/packages/client/src/components/date-separated-list.vue index c85a0a6ff..085ef871e 100644 --- a/packages/client/src/components/date-separated-list.vue +++ b/packages/client/src/components/date-separated-list.vue @@ -53,8 +53,8 @@ export default defineComponent({ if (el.key == null && item.id) el.key = item.id; if ( - i != props.items.length - 1 && - new Date(item.createdAt).getDate() != new Date(props.items[i + 1].createdAt).getDate() + i !== props.items.length - 1 && + new Date(item.createdAt).getDate() !== new Date(props.items[i + 1].createdAt).getDate() ) { const separator = h('div', { class: 'separator', diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index 2e6d26476..37076652f 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -45,7 +45,7 @@ export default defineComponent({ }, render() { - if (this.text == null || this.text == '') return; + if (this.text == null || this.text === '') return; const ast = (this.plain ? mfm.parsePlain : mfm.parse)(this.text, { fnNameList: MFM_TAGS }); diff --git a/packages/client/src/components/notification-toast.vue b/packages/client/src/components/notification-toast.vue index b2ab1029a..4c5783e52 100644 --- a/packages/client/src/components/notification-toast.vue +++ b/packages/client/src/components/notification-toast.vue @@ -6,33 +6,26 @@ - diff --git a/packages/client/src/components/toast.vue b/packages/client/src/components/toast.vue index c11437971..99933f384 100644 --- a/packages/client/src/components/toast.vue +++ b/packages/client/src/components/toast.vue @@ -22,12 +22,12 @@ const emit = defineEmits<{ (e: 'closed'): void; }>(); -const showing = ref(true); const zIndex = os.claimZIndex('high'); +let showing = $ref(true); onMounted(() => { window.setTimeout(() => { - showing.value = false; + showing = false; }, 4000); }); diff --git a/packages/client/src/components/url-preview.vue b/packages/client/src/components/url-preview.vue index 6c5795761..c7bbd1fbd 100644 --- a/packages/client/src/components/url-preview.vue +++ b/packages/client/src/components/url-preview.vue @@ -67,7 +67,7 @@ let tweetHeight = $ref(150); const requestUrl = new URL(props.url); -if (requestUrl.hostname == 'twitter.com') { +if (requestUrl.hostname === 'twitter.com') { const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/); if (m) tweetId = m[1]; } diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index 95b4e87a1..5f1fb1ef9 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -544,7 +544,7 @@ export const uploads = ref<{ }[]>([]); export function upload(file: File, folder?: any, name?: string, keepOriginal: boolean = defaultStore.state.keepOriginalUploading): Promise { - if (folder && typeof folder == 'object') folder = folder.id; + if (folder && typeof folder === 'object') folder = folder.id; return new Promise((resolve, reject) => { const id = Math.random().toString(); diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue index 3e4ec1b2a..72b7e6917 100644 --- a/packages/client/src/pages/settings/theme.vue +++ b/packages/client/src/pages/settings/theme.vue @@ -123,8 +123,8 @@ export default defineComponent({ const installedThemes = ref(getThemes()); const themes = computed(() => builtinThemes.concat(installedThemes.value)); - const darkThemes = computed(() => themes.value.filter(t => t.base == 'dark' || t.kind == 'dark')); - const lightThemes = computed(() => themes.value.filter(t => t.base == 'light' || t.kind == 'light')); + const darkThemes = computed(() => themes.value.filter(t => t.base === 'dark' || t.kind === 'dark')); + const lightThemes = computed(() => themes.value.filter(t => t.base === 'light' || t.kind === 'light')); const darkTheme = ColdDeviceStorage.ref('darkTheme'); const darkThemeId = computed({ get() {