Skip to content

Commit

Permalink
feat(publish): support search for language list
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 2, 2023
1 parent bb4fd74 commit 296a7b6
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions components/publish/PublishWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 type { Draft } from '~/types'
type FileUploadError = [filename: string, message: string]
Expand Down Expand Up @@ -185,6 +186,29 @@ 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: '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?.()
Expand Down Expand Up @@ -336,24 +360,24 @@ defineExpose({
</button>
<template #popper>
<div min-w-80>
<!-- TODO search lang -->
<!-- <input
<div min-w-80 p3>
<input
v-model="languageKeyword"
placeholder="Search"
p2 mb2 border-rounded w-full bg-transparent
outline-none border="~ base"
> -->
>
<div max-h-40vh overflow-auto>
<CommonDropdownItem
v-for="code in [null, ...ISO6391.getAllCodes()]"
v-for="{ code, nativeName, name } in languages"
:key="code"
:checked="code === (draft.params.language || null)"
@click="chooseLanguage(code)"
>
{{ code ? ISO6391.getNativeName(code) : 'None' }}
{{ nativeName }}
<template #description>
<template v-if="code">
{{ ISO6391.getName(code) }}
<template v-if="name">
{{ name }}
</template>
</template>
</CommonDropdownItem>
Expand Down

0 comments on commit 296a7b6

Please sign in to comment.