generated from deco-sites/fashion
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add show more button * improve showmore component * fmt * remove console log * use pageHref instead * remove showMore * fix type errors * back to use ctx.invoke * use app version * remove fashion photos * create better types
- Loading branch information
Showing
15 changed files
with
216 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"imports": { | ||
"$store/": "./", | ||
"deco/": "https://denopkg.com/deco-cx/[email protected]/", | ||
"deco/": "https://denopkg.com/deco-cx/[email protected]/", | ||
"apps/": "https://denopkg.com/deco-cx/[email protected]/", | ||
"$fresh/": "https://deno.land/x/[email protected]/", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useSignal } from "@preact/signals"; | ||
import { invoke } from "$store/runtime.ts"; | ||
import { PageInfo, Product, ProductListingPage } from "apps/commerce/types.ts"; | ||
import ProductCard from "$store/components/product/ProductCard.tsx"; | ||
import { Layout as CardLayout } from "$store/components/product/ProductCard.tsx"; | ||
import { Columns } from "$store/components/product/ProductGallery.tsx"; | ||
import Spinner from "$store/components/ui/Spinner.tsx"; | ||
import { usePlatform } from "$store/sdk/usePlatform.tsx"; | ||
import { Resolved } from "deco/engine/core/resolver.ts"; | ||
|
||
export interface Props { | ||
pageInfo: PageInfo; | ||
layout?: { | ||
card?: CardLayout; | ||
columns?: Columns; | ||
}; | ||
platform: ReturnType<typeof usePlatform>; | ||
loaderProps: Resolved<ProductListingPage | null>; | ||
} | ||
|
||
export default function ShowMore( | ||
{ pageInfo, layout, platform, loaderProps }: Props, | ||
) { | ||
const products = useSignal<Array<Product | null>>([]); | ||
const nextPage = useSignal(pageInfo.nextPage); | ||
const loading = useSignal(false); | ||
|
||
const handleLoadMore = async () => { | ||
loading.value = true; | ||
|
||
const url = new URL( | ||
window.location.origin + window.location.pathname + nextPage.value, | ||
); | ||
|
||
// Figure out a better way to type this loader | ||
// deno-lint-ignore no-explicit-any | ||
const invokePayload: any = { | ||
key: loaderProps.__resolveType, | ||
props: { | ||
...loaderProps, | ||
__resolveType: undefined, | ||
pageHref: url.href, | ||
}, | ||
}; | ||
|
||
const page = await invoke(invokePayload) as ProductListingPage | null; | ||
|
||
loading.value = false; | ||
|
||
if (page) { | ||
window.history.pushState({}, "", nextPage.value); | ||
nextPage.value = page.pageInfo.nextPage; | ||
products.value = [...products.value, ...page.products]; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{products.value.map((product, index) => { | ||
if (!product) return null; | ||
return ( | ||
<ProductCard | ||
product={product} | ||
preload={index === 0} | ||
layout={layout?.card} | ||
platform={platform} | ||
/> | ||
); | ||
})} | ||
{nextPage.value && ( | ||
<button | ||
onClick={handleLoadMore} | ||
class="btn w-auto mx-auto col-span-full" | ||
> | ||
{loading.value ? <Spinner /> : "Show More"} | ||
</button> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.