-
Notifications
You must be signed in to change notification settings - Fork 100
add pagination #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ij5
wants to merge
16
commits into
denoland:main
Choose a base branch
from
ij5:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add pagination #73
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b041c3d
implemented pagination
ij5 9b861ef
fixed arrow color
ij5 f22dc0a
fixed arrow is showing at index 0
ij5 f5e19d4
merge filterPosts to getPostPage
ij5 e5188bf
fixed tags pagination bug
ij5 e1afe16
fixed pagination bug when includes tag
ij5 5bf53c6
Merge branch 'denoland:main' into main
ij5 1bec7fc
fixed formatting
ij5 20695b4
Merge branch 'main' of github.com:ij5/deno_blog
ij5 7866e99
fixed sort by published date bug in pagination
ij5 16fe4eb
update formatting
ij5 1d28638
merged duplicate code
ij5 51d7829
use tag instead of searchParams
ij5 5aa4f69
Changed getPostsPage to getPostsByPage
ij5 cc79a5e
fixed fmt
ij5 62d2086
Merge branch 'denoland:main' into main
ij5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -17,19 +17,71 @@ const socialAppIcons = new Map([ | |
["linkedin.com", IconLinkedin], | ||
]); | ||
|
||
interface PaginationProps { | ||
index: number; | ||
type: "forward" | "backward" | "both"; | ||
tag: string | null; | ||
} | ||
function Pagination({ index, type, tag }: PaginationProps) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the UI is not good, i will add a mockup later |
||
let t; | ||
if (tag) t = "&tag=" + tag; | ||
else t = ""; | ||
const page = ( | ||
<div class="mt-3 flex gap-2 items-center justify-center"> | ||
{(type === "backward" || type === "both") | ||
? ( | ||
<a | ||
href={`/?page=${index - 1}${t}`} | ||
class="relative flex items-center justify-center w-8 h-8 rounded-full bg-gray-600/10 dark:bg-gray-400/10 text-gray-700 dark:text-gray-400 hover:bg-gray-600/15 dark:hover:bg-gray-400/15 hover:text-black dark:hover:text-white transition-colors group" | ||
> | ||
<IconPrevious /> | ||
</a> | ||
) | ||
: ""} | ||
{(type === "forward" || type === "both") | ||
? ( | ||
<a | ||
href={`/?page=${index + 1}${t}`} | ||
class="relative flex items-center justify-center w-8 h-8 rounded-full bg-gray-600/10 dark:bg-gray-400/10 text-gray-700 dark:text-gray-400 hover:bg-gray-600/15 dark:hover:bg-gray-400/15 hover:text-black dark:hover:text-white transition-colors group" | ||
> | ||
<IconNext /> | ||
</a> | ||
) | ||
: ""} | ||
</div> | ||
); | ||
return page; | ||
} | ||
|
||
interface IndexProps { | ||
state: BlogState; | ||
posts: Map<string, Post>; | ||
index: number; | ||
postsLength: number; | ||
tag: URLSearchParams; | ||
} | ||
|
||
export function Index({ state, posts }: IndexProps) { | ||
export function Index( | ||
{ state, posts, index, postsLength, tag }: IndexProps, | ||
) { | ||
const postIndex = []; | ||
for (const [_key, post] of posts.entries()) { | ||
postIndex.push(post); | ||
} | ||
postIndex.sort( | ||
(a, b) => (b.publishDate?.getTime() ?? 0) - (a.publishDate?.getTime() ?? 0), | ||
); | ||
let page; | ||
const t = tag.get("tag"); | ||
if ((index + 1) * 10 >= postsLength && index !== 0) { | ||
page = <Pagination tag={t} index={index} type={"backward"} />; | ||
} else if (index === 0 && (index + 1) * 10 >= postsLength) { | ||
page = ""; | ||
} else if (index === 0) { | ||
page = <Pagination tag={t} index={index} type={"forward"} />; | ||
} else { | ||
page = <Pagination tag={t} index={index} type={"both"} />; | ||
} | ||
|
||
return ( | ||
<div class="home"> | ||
|
@@ -114,6 +166,7 @@ export function Index({ state, posts }: IndexProps) { | |
/> | ||
))} | ||
</div> | ||
{page} | ||
|
||
{state.footer || <Footer author={state.author} />} | ||
</div> | ||
|
@@ -356,6 +409,38 @@ function IconExternalLink() { | |
); | ||
} | ||
|
||
function IconPrevious() { | ||
return ( | ||
<svg | ||
className="inline-block w-5 h-5" | ||
viewBox="0 0 512 512" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
fill="currentColor" | ||
d="M257.5 445.1l-22.2 22.2c-9.4 9.4-24.6 9.4-33.9 0L7 273c-9.4-9.4-9.4-24.6 0-33.9L201.4 44.7c9.4-9.4 24.6-9.4 33.9 0l22.2 22.2c9.5 9.5 9.3 25-.4 34.3L136.6 216H424c13.3 0 24 10.7 24 24v32c0 13.3-10.7 24-24 24H136.6l120.5 114.8c9.8 9.3 10 24.8.4 34.3z" | ||
/> | ||
</svg> | ||
); | ||
} | ||
|
||
function IconNext() { | ||
return ( | ||
<svg | ||
className="inline-block w-5 h-5" | ||
viewBox="0 0 512 512" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
fill="currentColor" | ||
d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z" | ||
/> | ||
</svg> | ||
); | ||
} | ||
|
||
function IconGithub() { | ||
return ( | ||
<svg | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.