Skip to content

Commit

Permalink
feat: start category
Browse files Browse the repository at this point in the history
  • Loading branch information
gsbenevides2 committed Nov 7, 2024
1 parent b3a4435 commit b22a6f8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
14 changes: 11 additions & 3 deletions .deco/blocks/PLP%20Loader.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"data": {
"__resolveType": "shopify/loaders/ProductListingPage.ts",
"count": 12
"__resolveType": "vtex/loaders/intelligentSearch/productListingPage.ts",
"count": 28,
"sort": "release:desc",
"fuzzy": "automatic",
"pageOffset": 1,
"selectedFacets": []
},
"extensions": [],
"extensions": [
{
"__resolveType": "vtex/loaders/product/extensions/listingPage.ts"
}
],
"__resolveType": "commerce/loaders/product/extensions/listingPage.ts"
}
80 changes: 44 additions & 36 deletions components/search/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export interface Props {
/** @hidden */
partial?: "hideMore" | "hideLess";
}
function NotFound() {
return (
<div class="w-full flex justify-center items-center py-10">
<span>Not Found!</span>
</div>
);
}

export const loader = (props: Props, req: Request) => {
return {
...props,
url: req.url,
};
};

const useUrlRebased = (overrides: string | undefined, base: string) => {
let url: string | undefined = undefined;
if (overrides) {
Expand All @@ -48,6 +49,39 @@ const useUrlRebased = (overrides: string | undefined, base: string) => {
}
return url;
};

const setPageQuerystring = (page: string, id: string) => {
const element = document.getElementById(id)?.querySelector(
"[data-product-list]",
);
if (!element) {
return;
}
new IntersectionObserver((entries) => {
const url = new URL(location.href);
const prevPage = url.searchParams.get("page");
for (let it = 0; it < entries.length; it++) {
if (entries[it].isIntersecting) {
url.searchParams.set("page", page);
} else if (
typeof history.state?.prevPage === "string" &&
history.state?.prevPage !== page
) {
url.searchParams.set("page", history.state.prevPage);
}
}
history.replaceState({ prevPage }, "", url.href);
}).observe(element);
};

function NotFound() {
return (
<div class="w-full flex justify-center items-center py-10">
<span>Not Found!</span>
</div>
);
}

function PageResult(props: SectionProps<typeof loader>) {
const { layout, startingPage = 0, url, partial } = props;
const page = props.page!;
Expand Down Expand Up @@ -152,29 +186,7 @@ function PageResult(props: SectionProps<typeof loader>) {
</div>
);
}
const setPageQuerystring = (page: string, id: string) => {
const element = document.getElementById(id)?.querySelector(
"[data-product-list]",
);
if (!element) {
return;
}
new IntersectionObserver((entries) => {
const url = new URL(location.href);
const prevPage = url.searchParams.get("page");
for (let it = 0; it < entries.length; it++) {
if (entries[it].isIntersecting) {
url.searchParams.set("page", page);
} else if (
typeof history.state?.prevPage === "string" &&
history.state?.prevPage !== page
) {
url.searchParams.set("page", history.state.prevPage);
}
}
history.replaceState({ prevPage }, "", url.href);
}).observe(element);
};

function Result(props: SectionProps<typeof loader>) {
const container = useId();
const controls = useId();
Expand Down Expand Up @@ -212,6 +224,7 @@ function Result(props: SectionProps<typeof loader>) {
const sortBy = sortOptions.length > 0 && (
<Sort sortOptions={sortOptions} url={url} />
);

return (
<>
<div id={container} {...viewItemListEvent} class="w-full">
Expand Down Expand Up @@ -297,10 +310,5 @@ function SearchResult({ page, ...props }: SectionProps<typeof loader>) {
}
return <Result {...props} page={page} />;
}
export const loader = (props: Props, req: Request) => {
return {
...props,
url: req.url,
};
};

export default SearchResult;
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export const WISHLIST_FORM_ID = "wishlist-form";

export const HEADER_HEIGHT_MOBILE = "110px";
export const NAVBAR_HEIGHT_MOBILE = "80px";
export const HEADER_HEIGHT_DESKTOP = "110px";
export const HEADER_HEIGHT_DESKTOP = "141px";
export const NAVBAR_HEIGHT_DESKTOP = "80px";

0 comments on commit b22a6f8

Please sign in to comment.