Skip to content

Commit

Permalink
improve safety
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Jul 7, 2023
1 parent 63f7606 commit e6de7ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scripts/gen-hljs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const files = readdirSync('./node_modules/highlight.js/es/languages').filter(fil
;(async () => {
await Promise.all (files.map(async (file) => {
const mod = await import(`highlight.js/lib/languages/${file}`)
const { aliases } = mod.default(highlight)
const { aliases } = mod.default(highlight.newInstance())
const language = file
hljs[language] = language
if (!aliases) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/T/modal.client.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Callback } from '~/composables/useZoomModal'
import type { Callback } from '~/composables/useZoomModal'
const emits = defineEmits<{
(e: 'cancel', v: Event): void
Expand Down
15 changes: 10 additions & 5 deletions src/composables/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const includes = shallowReactive({
users: true,
})
const searchMode = computed(() => ((includes.beatmaps || includes.beatmapsets) && !includes.users) ? 'beatmap' : 'all')
const autoResultSize = computed(() => searchMode.value === 'all' ? 5 : 10)

export async function useSearchResult() {
if (process.server) {
throw new Error('only useable in client.')
}
const app = useNuxtApp()

const {
Expand All @@ -56,7 +58,7 @@ export async function useSearchResult() {
}
return await app.$client.search.searchUser.query({
keyword: keyword.value,
limit: autoResultSize.value,
limit: autoResultSize(),
})
})

Expand All @@ -71,7 +73,7 @@ export async function useSearchResult() {
return await app.$client.search.searchBeatmap.query({
keyword: keyword.value,
filters: tags.value,
limit: autoResultSize.value,
limit: autoResultSize(),
})
})

Expand All @@ -86,7 +88,7 @@ export async function useSearchResult() {
return await app.$client.search.searchBeatmapset.query({
keyword: keyword.value,
filters: tags.value,
limit: autoResultSize.value,
limit: autoResultSize(),
})
})

Expand All @@ -111,7 +113,7 @@ export async function useSearchResult() {

const search = useDebounceFn(raw, 500)

watch(tags, () => raw(), { deep: true })
watch(tags, raw.bind(null, undefined), { deep: true })

const searchablePages = useSearchablePages()

Expand Down Expand Up @@ -240,3 +242,6 @@ function extract(force = false) {
extractQueries(force)
}
}
function autoResultSize() {
return searchMode.value === 'all' ? 5 : 10
}

0 comments on commit e6de7ee

Please sign in to comment.