From 92cf8ea2c70f56324ea62ecfc076306336358345 Mon Sep 17 00:00:00 2001 From: sinsong Date: Mon, 3 Jul 2023 22:15:28 +0800 Subject: [PATCH] refactor index page table implementation - using new index.json without huge number network request and without huge number of reflow - move style to stylesheet - remove PackageListItem.vue --- frontend/src/api.js | 5 ++ frontend/src/components/Index/PackageList.vue | 54 +++++++++---------- .../src/components/Index/PackageListItem.vue | 33 ------------ frontend/src/style/main.scss | 28 +++++++++- frontend/src/views/Index.vue | 27 +++------- 5 files changed, 66 insertions(+), 81 deletions(-) delete mode 100644 frontend/src/components/Index/PackageListItem.vue diff --git a/frontend/src/api.js b/frontend/src/api.js index c76f0c4..436af27 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -3,6 +3,11 @@ async function requestPackageList () { return await (await fetch(`${__API_BASE__}/api/pkglist.json`)).json() } +export +async function requestPackageIndex () { + return await (await fetch(`${__API_BASE__}/api/index.json`)).json() +} + export async function requestPackageInfo (pkg) { return await (await fetch(`${__API_BASE__}/api/${pkg}.json`)).json() diff --git a/frontend/src/components/Index/PackageList.vue b/frontend/src/components/Index/PackageList.vue index 765ad40..2e4fb64 100644 --- a/frontend/src/components/Index/PackageList.vue +++ b/frontend/src/components/Index/PackageList.vue @@ -1,10 +1,14 @@ - - diff --git a/frontend/src/style/main.scss b/frontend/src/style/main.scss index c2b4d9f..eb52170 100644 --- a/frontend/src/style/main.scss +++ b/frontend/src/style/main.scss @@ -18,14 +18,38 @@ table { margin: .5em 0; } +// search bar +.search { + width: 100%; + + margin: 15px 0; + + font-size: 15px; + padding: .5em .5em; +} + .box { border: 1px solid #bcd; padding: .5em; background: var(--box-bg); } -table#index-table thead { - border-bottom: 1px solid var(--index-thead-border); +.table-scroll-wrapper { + overflow-x: auto; +} + +table#index-table { + width: 100%; + + thead { + border-bottom: 1px solid var(--index-thead-border); + } + + tbody { + td { + white-space: nowrap; + } + } } tr.index-item:hover { diff --git a/frontend/src/views/Index.vue b/frontend/src/views/Index.vue index f36fdf7..75dc116 100644 --- a/frontend/src/views/Index.vue +++ b/frontend/src/views/Index.vue @@ -4,37 +4,37 @@ import PackageList from '@/components/Index/PackageList.vue' import Index from 'flexsearch/dist/module/index' -import { requestPackageInfo, requestPackageList } from '../api' +import { requestPackageIndex } from '../api' import { displayPackages } from '@/state' -let packageList = null +let packageIndex = null const searchIndex = new Index({ tokenize: 'forward' }) let searchInput = ref("") function updateSearchIndex(pkglist) { pkglist.forEach((content, index) => { - searchIndex.add(index, content) + searchIndex.add(index, content.name) }) } -requestPackageList() +requestPackageIndex() .then((obj) => { - packageList = obj + packageIndex = obj displayPackages.value = obj updateSearchIndex(obj) }) watch(searchInput, async(newVal, oldVal) => { if (searchInput.value.length === 0) { - displayPackages.value = packageList + displayPackages.value = packageIndex } else { const searchResult = searchIndex.search(searchInput.value) const finalResult = [] - searchResult.forEach((elem) => { - finalResult.push(packageList[elem]) + searchResult.forEach((idx) => { + finalResult.push(packageIndex[idx]) }) displayPackages.value = finalResult } @@ -49,14 +49,3 @@ watch(searchInput, async(newVal, oldVal) => { - -