generated from deco-sites/storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ba8ac0
commit f811821
Showing
8 changed files
with
216 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { PageInfo } from "apps/commerce/types.ts"; | ||
import type { ComponentChildren } from "preact"; | ||
import { useEffect, useMemo } from "preact/hooks"; | ||
import { useShowMore } from "../sdk/useShowMore.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()); | ||
} | ||
}} | ||
> | ||
Mostrar mais | ||
</button> | ||
</div> | ||
); | ||
} |
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,11 @@ | ||
import { signal } from "@preact/signals"; | ||
|
||
const currentPage = signal(1); | ||
const loading = signal(false); | ||
|
||
export const useShowMore = () => { | ||
return { | ||
currentPage, | ||
loading, | ||
}; | ||
}; |
Oops, something went wrong.