Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device page bugs #118

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pages/type/[type].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
>
Expand Down
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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Loading