Skip to content
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

refactor(watch): move down resources list to a suspended RSC #55

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/watch/components/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IoClose } from 'react-icons/io5'
import { useDebounce } from 'use-debounce'
import { useEventListener } from 'usehooks-ts'

import WatchResource from '@/app/watch/watchResource'
import WatchResource from '@/app/watch/components/watchResource/watchResource'
import Spinner from '@/components/spinner/Spinner'
import { Input } from '@headlessui/react'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { tv } from 'tailwind-variants'
import Badge from '@/components/badge/Badge'
import Meteors from '@/components/cards/Meteors'

import type { WatchResource } from './types'
import type { WatchResource } from '../../types'

const VariantMapping = {
Article: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { FC, useState } from 'react'
import Spinner from '@/components/spinner/Spinner'
import { fetchWatchPages } from '@/lib/notion'

import { transformWatchResourceToDTO } from './dto/watchResource.dto'
import { groupWatchResourcesByDate, groupWatchResourcesByMonth } from './utils'
import { transformWatchResourceToDTO } from '../../dto/watchResource.dto'
import {
groupWatchResourcesByDate,
groupWatchResourcesByMonth,
} from '../../utils'

import WatchResource from './watchResource'

type Props = {
Expand Down
24 changes: 14 additions & 10 deletions src/app/watch/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Suspense } from 'react'

import ArrowIcon from '@/components/icons/ArrowIcon'
import { fetchWatchPages } from '@/lib/notion'
import Spinner from '@/components/spinner/Spinner'

import IntroAlert from './components/introAlert/IntroAlert'
import Search from './components/search/Search'
import { transformWatchResourceToDTO } from './dto/watchResource.dto'
import WatchResources from './watchResources'
import WatchResourcesList from './watchResourcesList'

export const revalidate = 3600

export default async function Page() {
const firstPage = await fetchWatchPages()
const initialResources = firstPage.results.map(transformWatchResourceToDTO)

return (
<div className="flex h-full flex-col justify-center px-8 py-32">
{/* Title */}
Expand All @@ -33,10 +31,16 @@ export default async function Page() {
<Search />

{/* Resources */}
<WatchResources
initialResources={initialResources}
initialNextPage={firstPage.next_cursor}
/>
<Suspense
fallback={
<div className="mt-24 flex items-center justify-center text-gray-600 dark:text-white">
<Spinner className="mr-2 [&>svg]:size-6" />
Loading...
</div>
}
>
<WatchResourcesList />
</Suspense>
</div>
)
}
16 changes: 16 additions & 0 deletions src/app/watch/watchResourcesList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fetchWatchPages } from '@/lib/notion'

import WatchResources from './components/watchResource/watchResources'
import { transformWatchResourceToDTO } from './dto/watchResource.dto'

export default async function WatchResourcesList() {
const firstPage = await fetchWatchPages()
const initialResources = firstPage.results.map(transformWatchResourceToDTO)

return (
<WatchResources
initialResources={initialResources}
initialNextPage={firstPage.next_cursor}
/>
)
}