diff options
| author | Mistivia <i@mistivia.com> | 2025-02-20 13:26:43 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-02-20 13:26:43 +0800 |
| commit | 2ebdfe109bbff27b35a5e9ae208dabddd266191e (patch) | |
| tree | ed63233177008c7bef134606fbf0254754e91fb2 /src/control/search.js | |
| parent | a7488d695b3f647d657f6b3482d5333e1e869771 (diff) | |
change project layout
Diffstat (limited to 'src/control/search.js')
| -rw-r--r-- | src/control/search.js | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/src/control/search.js b/src/control/search.js deleted file mode 100644 index 5927950..0000000 --- a/src/control/search.js +++ /dev/null @@ -1,79 +0,0 @@ -import { writable } from 'svelte/store'; -import { getCardDb} from '../data/cardDb'; - -let showingCards = writable([]); -let resultCards = []; - -let curVer = 0; -let curPage = 0; - -function showCards() { - showingCards.set(resultCards.slice(curPage * 10, curPage * 10 + 10)); -} - -function changeInput(query) { - curVer += 1; - query = query.split(' '); - setTimeout(()=>{doSearch(curVer, query)}, 0); -} - -function doSearch(ver, query) { - let cardDb = getCardDb(); - let result = []; - for (let key in cardDb) { - if (ver !== curVer) { - return; - } - let hit = true; - for (let word of query) { - let matched = false; - for (let name of cardDb[key].names) { - if (name.toLowerCase().includes(word.toLowerCase())) { - matched = true; - break; - } - } - if (!matched) { - hit = false; - break; - } - } - if (hit) { - result.push({"id": key, "name": cardDb[key].names[0]}) - } - } - if (ver !== curVer) return; - result.sort((a, b) => { - return cardDb[a.id].cid - cardDb[b.id].cid; - }); - resultCards = result; - curPage = 0; - showCards(); -} - -function initSearch() { - doSearch(curVer, ""); -} - -function onPrevPage() { - if (curPage > 0) { - curPage -= 1; - showCards(); - } -} - -function onNextPage() { - if (curPage < Math.floor((resultCards.length - 1) / 10)) { - curPage += 1; - showCards(); - } -} - - -export { - changeInput, - onPrevPage, - onNextPage, - showingCards, - initSearch, -}; |
