-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add pagination and more button at the bottom
- Loading branch information
Guillaume FORTAINE
committed
Nov 14, 2022
1 parent
6e3128e
commit c79488c
Showing
11 changed files
with
105 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Server Components | ||
import SystemInfo from '../../components/server-info' | ||
|
||
// Client Components | ||
import Stories from '../../components/stories' | ||
import Footer from '../../components/footer' | ||
|
||
// Utils | ||
import fetchData from '../../lib/fetch-data' | ||
|
||
export default async function RSCPage({ searchParams }) { | ||
const { p: page = 1 } = searchParams | ||
const storyIds = await fetchData('topstories') | ||
|
||
return ( | ||
<> | ||
<Stories page={page} storyIds={storyIds} /> | ||
<Footer /> | ||
<SystemInfo /> | ||
</> | ||
) | ||
} | ||
|
||
export const revalidate = 0 |
This file was deleted.
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
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,22 +1,34 @@ | ||
import Story from './story' | ||
import Link from 'next/link' | ||
import Story from './story' | ||
|
||
import fetchData from '../lib/fetch-data' | ||
import { transform } from '../lib/get-item' | ||
|
||
import styles from './stories.module.css' | ||
|
||
export default ({ stories, page = 1, offset = null }) => ( | ||
<div> | ||
{stories.map((story, i) => ( | ||
<div key={story.id} className={styles.item}> | ||
{null != offset ? ( | ||
<span className={styles.count}>{i + offset + 1}</span> | ||
) : null} | ||
<div className={styles.story}> | ||
<Story {...story} /> | ||
async function StoryWithData({ id }) { | ||
const data = await fetchData(`item/${id}`) | ||
const story = transform(data) | ||
return <Story {...story} /> | ||
} | ||
|
||
export default async function Stories({ storyIds, page = 1 }) { | ||
const limit = 30 | ||
const offset = (page - 1) * limit | ||
|
||
return ( | ||
<div> | ||
{storyIds.slice(offset, offset + limit).map((id, i) => ( | ||
<div key={id} className={styles.item}> | ||
{null != offset ? ( | ||
<span className={styles.count}>{i + offset + 1}</span> | ||
) : null} | ||
<StoryWithData id={id} key={id} /> | ||
</div> | ||
))} | ||
<div className={styles.footer}> | ||
<Link href={`/news?p=${+page + 1}`}>More</Link> | ||
</div> | ||
))} | ||
<footer className={styles.footer}> | ||
<Link href={`/news?p=${page + 1}`}>More</Link> | ||
</footer> | ||
</div> | ||
) | ||
</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
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,5 +1,13 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
appDir: true | ||
}, | ||
}; | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: '/', | ||
destination: '/news' | ||
} | ||
] | ||
} | ||
} |