From b0d6f310a8a91c6f0248aca0d54e41e82d9e6419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Wed, 4 Jan 2023 17:56:10 +0800 Subject: [PATCH] feat(publish): hoist selected language and none --- components/publish/PublishLanguagePicker.vue | 72 ++++++++++++++++++++ components/publish/PublishWidget.vue | 51 +------------- 2 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 components/publish/PublishLanguagePicker.vue diff --git a/components/publish/PublishLanguagePicker.vue b/components/publish/PublishLanguagePicker.vue new file mode 100644 index 000000000..57e1a7a32 --- /dev/null +++ b/components/publish/PublishLanguagePicker.vue @@ -0,0 +1,72 @@ + + + diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index 2eeb909fa..4d35d5814 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -3,8 +3,6 @@ import type { Attachment, CreateStatusParams, Status, StatusVisibility } from 'm import { fileOpen } from 'browser-fs-access' import { useDropZone } from '@vueuse/core' import { EditorContent } from '@tiptap/vue-3' -import ISO6391 from 'iso-639-1' -import Fuse from 'fuse.js' import { statusVisibilities } from '~/composables/masto/icons' import type { Draft } from '~/types' @@ -138,10 +136,6 @@ function chooseVisibility(visibility: StatusVisibility) { draft.params.visibility = visibility } -function chooseLanguage(language: string | null) { - draft.params.language = language -} - async function publish() { const payload = { ...draft.params, @@ -188,29 +182,6 @@ async function onDrop(files: File[] | null) { const { isOverDropZone } = useDropZone(dropZoneRef, onDrop) -const languageKeyword = $ref('') -const languageList: { - code: string | null - nativeName: string - name?: string -}[] = [{ - code: null, - nativeName: t('language.none'), -}, ...ISO6391.getAllCodes().map(code => ({ - code, - nativeName: ISO6391.getNativeName(code), - name: ISO6391.getName(code), -}))] -const fuse = new Fuse(languageList, { - keys: ['code', 'nativeName', 'name'], - shouldSort: true, -}) -const languages = $computed(() => - languageKeyword.trim() - ? fuse.search(languageKeyword).map(r => r.item) - : languageList, -) - defineExpose({ focusEditor: () => { editor.value?.commands?.focus?.() @@ -363,27 +334,7 @@ defineExpose({