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 * create better types * attempt to use fresh append partial * partialsssssss * fmt * rollback some changes * fmt * add partial-mode param * bump deco * fmt * refactor * some fixes to work in another integrations * fmt
- Loading branch information
Showing
11 changed files
with
228 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"imports": { | ||
"$store/": "./", | ||
"deco/": "https://denopkg.com/deco-cx/deco@1.55.0/", | ||
"apps/": "https://denopkg.com/deco-cx/apps@0.34.6/", | ||
"$fresh/": "https://deno.land/x/[email protected].3/", | ||
"deco/": "https://denopkg.com/deco-cx/deco@1.57.2/", | ||
"apps/": "https://denopkg.com/deco-cx/apps@0.35.2/", | ||
"$fresh/": "https://deno.land/x/[email protected].5/", | ||
"preact": "https://esm.sh/[email protected]", | ||
"preact/": "https://esm.sh/[email protected]/", | ||
"preact-render-to-string": "https://esm.sh/*[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,57 @@ | ||
import { useEffect, useMemo } from "preact/hooks"; | ||
import type { ComponentChildren } from "preact"; | ||
import { useShowMore } from "$store/sdk/useShowMore.ts"; | ||
import { PageInfo } from "apps/commerce/types.ts"; | ||
|
||
export interface Props { | ||
children: ComponentChildren; | ||
pageInfo: PageInfo; | ||
} | ||
|
||
export default function ShowMore( | ||
{ children, pageInfo }: Props, | ||
) { | ||
const { currentPage, loading } = useShowMore(); | ||
|
||
const loadedPage = pageInfo.currentPage; | ||
const isFirstPage = !pageInfo.previousPage; | ||
const isAtPage = useMemo(() => currentPage.value === loadedPage, [ | ||
currentPage.value, | ||
]); | ||
|
||
useEffect(() => { | ||
if (!isFirstPage) { | ||
loading.value = false; | ||
} | ||
currentPage.value = loadedPage; | ||
}, []); | ||
|
||
return ( | ||
<div | ||
class={(isAtPage && pageInfo.nextPage) | ||
? "flex justify-center col-span-full" | ||
: "hidden"} | ||
> | ||
{children} | ||
<button | ||
class={`btn cursor-pointer absolute ${loading.value ? "hidden" : ""}`} | ||
onClick={() => { | ||
loading.value = true; | ||
const element = document.getElementById( | ||
`show-more-button-${loadedPage}`, | ||
); | ||
if (element) { | ||
element.click(); | ||
} | ||
if (pageInfo.nextPage) { | ||
const url = new URL(pageInfo.nextPage, window.location.href); | ||
url.searchParams.delete("partial"); | ||
window.history.replaceState({}, "", url.toString()); | ||
} | ||
}} | ||
> | ||
Show More | ||
</button> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.