Skip to content

Commit

Permalink
Fix device page bugs
Browse files Browse the repository at this point in the history
YayunHuang committed Aug 27, 2024
1 parent e1e93bf commit 986af78
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pages/type/[type].astro
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ const brandList: Array<BrandEnum | "all"> = ["all", ...nonEmptyBrands];
name="description"
content="MockUPhone supports devices including iPhone mockup, iPad mockup, Android mockup and TV mockup. You can check out the whole device list via this page."
/>
<script type="text/javascript" src="./_device.js"></script>
<script src="./_device.js"></script>
<script
define:vars={{ thumbnailList, brandThumbnailList, modelItems, brandItems }}
>
28 changes: 15 additions & 13 deletions src/pages/type/_device.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import * as autocompletePluginRecentSearchesPkg from "@algolia/autocomplete-plugin-recent-searches";
const { createLocalStorageRecentSearchesPlugin } =
autocompletePluginRecentSearchesPkg;
import * as autocompleteJsPkg from "@algolia/autocomplete-js";
const { autocomplete } = autocompleteJsPkg;

const isDebug = false;
const NUM_DEFAULT_MODEL_ITEMS_TO_DISPLAY = 0;
const NUM_DEFAULT_BRAND_ITEMS_TO_DISPLAY = 0;
const MAX_SEARCH_HISTORY_ITEM = 5;
const ALGOLIA_SEARCH_HISTORY_KEY = "brandModelSearch";
const LOCAL_STORAGE_KEY = `AUTOCOMPLETE_RECENT_SEARCHES:${ALGOLIA_SEARCH_HISTORY_KEY}`;

function ready(fn) {
if (document.readyState != "loading") {
fn();
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
ready(main);

class RootViewModel {
submittedQuery = "";
selectedBrand = "all";
@@ -177,10 +174,6 @@ function moveOldHistoryToTop(oldHistoryItem) {
}

function initializeSearch(viewModel, containerId) {
const { autocomplete } = window["@algolia/autocomplete-js"];
const { createLocalStorageRecentSearchesPlugin } =
window["@algolia/autocomplete-plugin-recent-searches"];

const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({
key: ALGOLIA_SEARCH_HISTORY_KEY,
MAX_SEARCH_HISTORY_ITEM,
@@ -464,3 +457,12 @@ function main() {
handleBrandSearchParams(viewModel);
handleQuerySearchParams(viewModel);
}

function ready(fn) {
if (document.readyState != "loading") {
fn();
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
ready(main);

0 comments on commit 986af78

Please sign in to comment.