-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove htmx pagination & add inlince css & add widget query * add ids * change error message * add tailwind prefix * add cache control header * create next widget * create theme option * remove hbs * rename var * remove unused page args * improve changelog props type * update README * remove unnecessary package * fix next peerDependencies version * publish version 0.0.1 * fix peerDependencies versions * add changelog * add sample app * add keywords * change IDs to demo changelog
- Loading branch information
1 parent
4187f07
commit 017bcbb
Showing
64 changed files
with
11,266 additions
and
314 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 +1,74 @@ | ||
package components | ||
|
||
templ ChangelogContainer() { | ||
<main class="mx-4 mt-8 sm:mx-0 sm:mt-10 md:mt-20"> | ||
import "html/template" | ||
|
||
type ChangelogContainerArgs struct { | ||
CurrentURL string | ||
HasMoreArticle bool | ||
} | ||
|
||
// Contains the article list and footer | ||
templ ChangelogContainer(args ChangelogContainerArgs) { | ||
<main id="changelog-container" class="o-mx-4 sm:o-mx-0"> | ||
{ children... } | ||
<div id="skeleton" class="o-hidden"> | ||
<div class="o-animate-pulse o-w-full o-space-y-4 o-mt-12"> | ||
<div class="o-w-3/4 o-h-9 o-rounded o-bg-black/10 dark:o-bg-white/10"></div> | ||
<div class="o-w-full o-h-5 o-rounded o-bg-black/10 dark:o-bg-white/10"></div> | ||
<div class="o-w-full o-h-32 o-rounded o-bg-black/10 dark:o-bg-white/10"></div> | ||
</div> | ||
</div> | ||
</main> | ||
if args.HasMoreArticle { | ||
@templ.FromGoHTML(infiniteScrollTemplate, args.CurrentURL) | ||
} | ||
} | ||
|
||
var infiniteScrollTemplate = template.Must(template.New("infiniteScrollTemplate").Parse(` | ||
<script> | ||
const skeleton = document.getElementById("skeleton") | ||
const container = document.getElementById("changelog-container") | ||
const currentPageURL = new URL("{{ . }}") | ||
const params = currentPageURL.searchParams; | ||
let isLoadingNextPage = false | ||
let hasMore = true | ||
function loadStarted() { | ||
isLoadingNextPage = true | ||
skeleton.style.display = "block" | ||
} | ||
function loadEnded() { | ||
isLoadingNextPage = false | ||
skeleton.style.display = "none" | ||
} | ||
async function loadNextPage(url) { | ||
try { | ||
loadStarted() | ||
const currentPage = parseInt(params.get('page')) || 1; | ||
params.set('page', currentPage + 1); | ||
// don't load full html page, only articles list | ||
params.set('articles', "true"); | ||
const res = await fetch(currentPageURL) | ||
if (!res.ok || res.status === 204) { | ||
hasMore = false | ||
} | ||
const newArticles = await res.text() | ||
skeleton.insertAdjacentHTML('beforebegin', newArticles) | ||
} finally { | ||
loadEnded() | ||
} | ||
} | ||
window.addEventListener("scroll", () => { | ||
const bufferPx = 100 // start loading before reaching end of container | ||
const endReached = window.scrollY + window.innerHeight + bufferPx >= container.scrollHeight | ||
if(endReached && !isLoadingNextPage && hasMore){ | ||
loadNextPage() | ||
} | ||
}) | ||
</script> | ||
`, | ||
)) |
Oops, something went wrong.