-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(app): add questions pagination #403
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
961ca12
Updates
typeofweb fcd77a4
Refactor questions page
typeofweb 65f01f1
Update page.tsx
AdiPol1359 1ae9324
feat(app): add questions pagination
AdiPol1359 9ab50bf
feat(app): add dark mode to page item
AdiPol1359 5b33509
refactor(app): remove activeHref from props
AdiPol1359 1501ef0
feat(app): add redirect to first category page
AdiPol1359 2b67957
feat(app): add current page technology
AdiPol1359 fec851b
fix(app): conflicts
AdiPol1359 0be0864
Merge branch 'develop' of https://github.com/typeofweb/devfaq into 35…
AdiPol1359 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 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,40 @@ | ||
import { redirect } from "next/navigation"; | ||
import { QuestionItem } from "../../../../components/QuestionItem/QuestionItem"; | ||
import { QuestionsPagination } from "../../../../components/QuestionsPagination"; | ||
import { PAGE_SIZE } from "../../../../lib/constants"; | ||
import { technologies } from "../../../../lib/technologies"; | ||
import { getAllQuestions } from "../../../../services/questions.service"; | ||
|
||
export default async function QuestionsPage({ | ||
params, | ||
}: { | ||
params: { technology: string; page: string }; | ||
}) { | ||
const page = parseInt(params.page); | ||
|
||
if (!technologies.includes(params.technology) || isNaN(page)) { | ||
return redirect("/"); | ||
} | ||
|
||
const { data } = await getAllQuestions({ | ||
category: params.technology, | ||
limit: PAGE_SIZE, | ||
offset: (page - 1) * PAGE_SIZE, | ||
}); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-10"> | ||
{data.data.map(({ id, question, _levelId, acceptedAt, votesCount }) => ( | ||
<QuestionItem | ||
key={id} | ||
title={question} | ||
level={_levelId} | ||
creationDate={new Date(acceptedAt || "")} | ||
votes={votesCount} | ||
voted={id % 2 === 0} | ||
/> | ||
))} | ||
<QuestionsPagination technology={params.technology} total={data.meta.total} /> | ||
</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 |
---|---|---|
@@ -1,27 +1,5 @@ | ||
import { redirect } from "next/navigation"; | ||
import { QuestionItem } from "../../../components/QuestionItem/QuestionItem"; | ||
import { technologies } from "../../../lib/technologies"; | ||
import { getAllQuestions } from "../../../services/questions.service"; | ||
|
||
export default async function QuestionsPage({ params }: { params: { technology: string } }) { | ||
if (!technologies.includes(params.technology)) { | ||
return redirect("/"); | ||
} | ||
|
||
const { data } = await getAllQuestions({ category: params.technology, limit: 20 }); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-10"> | ||
{data.data.map(({ id, question, _levelId, acceptedAt, votesCount }) => ( | ||
<QuestionItem | ||
key={id} | ||
title={question} | ||
level={_levelId} | ||
creationDate={new Date(acceptedAt || "")} | ||
votes={votesCount} | ||
voted={id % 2 === 0} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
export default function TechnologyPage({ params }: { params: { technology: string } }) { | ||
return redirect(`/questions/${params.technology}/1`); | ||
} |
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,5 +1,5 @@ | ||
import { redirect } from "next/navigation"; | ||
|
||
export default function QuestionsPage() { | ||
return redirect("/questions/js"); | ||
return redirect("/questions/js/1"); | ||
} |
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,26 @@ | ||
import { PAGE_SIZE } from "../lib/constants"; | ||
import { ActiveLink } from "./ActiveLink"; | ||
|
||
type QuestionsPaginationProps = Readonly<{ | ||
technology: string; | ||
total: number; | ||
}>; | ||
|
||
export const QuestionsPagination = ({ technology, total }: QuestionsPaginationProps) => { | ||
const pages = Math.ceil(total / PAGE_SIZE); | ||
|
||
return ( | ||
<div className="flex justify-center gap-x-3"> | ||
{Array.from({ length: pages }).map((_, i) => ( | ||
<ActiveLink | ||
key={i} | ||
href={`/questions/${technology}/${i + 1}`} | ||
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border-2 border-primary text-primary transition-colors duration-300 hover:bg-violet-100 dark:text-white dark:hover:bg-violet-800" | ||
activeClassName="bg-primary text-white" | ||
> | ||
{i + 1} | ||
</ActiveLink> | ||
))} | ||
</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 @@ | ||
export const PAGE_SIZE = 20; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.