Skip to content

Commit 5c940f7

Browse files
committed
move story view page to app directory
1 parent fe2da1c commit 5c940f7

File tree

8 files changed

+92
-86
lines changed

8 files changed

+92
-86
lines changed

app/story/[id]/page.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use client'
2+
3+
import dynamic from 'next/dynamic'
4+
import { headers } from 'next/headers'
5+
import { useRouter } from 'next/router'
6+
import {
7+
Environment,
8+
graphql,
9+
RelayEnvironmentProvider,
10+
usePreloadedQuery,
11+
} from 'react-relay'
12+
import { getCurrentEnvironment } from 'src/relay/environment'
13+
import loadSerializableQuery from 'src/relay/loadSerializableQuery'
14+
import useSerializablePreloadedQuery from 'src/relay/useSerializablePreloadedQuery'
15+
import Comments from 'src/components/comment/Comments'
16+
import Layout from 'src/components/Layout'
17+
import UserDetails from 'src/components/UserDetails/UserDetails'
18+
import Id_StoryQueryNode, {
19+
Id_StoryQuery,
20+
} from '__generated__/Id_StoryQuery.graphql'
21+
22+
const Editor = dynamic(() => import('src/components/story/StoryEditor'), {
23+
ssr: false,
24+
})
25+
26+
const StoryQuery = graphql`
27+
query Id_StoryQuery($id: ID!) {
28+
node(id: $id) {
29+
... on Story {
30+
id
31+
contentJson
32+
createdBy {
33+
...UserDetails_user
34+
}
35+
...Comments_story
36+
}
37+
}
38+
}
39+
`
40+
export default async function Story() {
41+
const requestCookie = headers().get('cookie')
42+
const environment = getCurrentEnvironment(requestCookie ?? '')
43+
const router = useRouter()
44+
const { id } = router.query
45+
const preloadedQuery = await loadSerializableQuery<
46+
typeof Id_StoryQueryNode,
47+
Id_StoryQuery
48+
>(Id_StoryQueryNode.params, { id: (id as string) ?? '' }, requestCookie ?? '')
49+
const queryRef = useSerializablePreloadedQuery(environment, preloadedQuery)
50+
const data = usePreloadedQuery(StoryQuery, queryRef)
51+
return (
52+
<RelayEnvironmentProvider environment={environment as Environment}>
53+
<div>
54+
<Layout
55+
sidebarContentRight={<div>Promoted</div>}
56+
sidebarContentLeft={
57+
<div>
58+
{data.node?.createdBy && (
59+
<UserDetails user={data?.node?.createdBy} />
60+
)}
61+
</div>
62+
}
63+
>
64+
<Editor body={data?.node?.contentJson} editable={false} />
65+
<Comments story={data.node} />
66+
</Layout>
67+
</div>
68+
</RelayEnvironmentProvider>
69+
)
70+
}

src/components/comment/Comment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dayjs from 'dayjs'
22
import relativeTime from 'dayjs/plugin/relativeTime'
33
import { graphql, useFragment } from 'react-relay'
4-
import { Comment_node$key } from '../../queries/__generated__/Comment_node.graphql'
4+
import { Comment_node$key } from '__generated__/Comment_node.graphql'
55

66
type CommentProps = {
77
comment: Comment_node$key

src/components/feed/Feed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { graphql, usePaginationFragment } from 'react-relay'
22
import { Virtuoso } from 'react-virtuoso'
3-
import { FeedsQuery$key } from '../../queries/__generated__/FeedsQuery.graphql'
3+
import { FeedsQuery$key } from '__generated__/FeedsQuery.graphql'
44
import StoryPreview from './StoryPreview'
55

66
type FeedProps = {

src/components/feed/MyStories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { graphql, usePaginationFragment } from 'react-relay'
2-
import { MyStories__Query$key } from '../../queries/__generated__/MyStories__Query.graphql'
2+
import { MyStories__Query$key } from '__generated__/MyStories__Query.graphql'
33
import StoryPreview from './StoryPreview'
44

55
type MyStoriesProps = {

src/components/feed/StoryPreview.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { graphql, useFragment } from 'react-relay'
2-
import { StoryPreview_node$key } from '../../queries/__generated__/StoryPreview_node.graphql'
2+
import { StoryPreview_node$key } from '__generated__/StoryPreview_node.graphql'
33
import StoryPreviewFooter from './StoryPreviewFooter'
44
import UserSnippet from './UserSnippet'
55
import { GoKebabVertical } from '@react-icons/all-files/go/GoKebabVertical'
@@ -34,25 +34,23 @@ const StoryPreview = ({ story }: StoryPreviewProps) => {
3434
<ErrorBoundary FallbackComponent={ErrorFallback}>
3535
<div className="my-8 mr-2 flex flex-col bg-white dark:bg-dark-700 rounded-md">
3636
<Link href={`/story/${data.id}___${data.urlSuffix}`}>
37-
<a>
38-
<div>
39-
{data.thumbnail ? (
40-
<img className="cover-image" src={data.thumbnail} alt="" />
41-
) : (
42-
<div className="image-placeholder bg-gray-100 dark:bg-dark-500"></div>
43-
)}
37+
<div>
38+
{data.thumbnail ? (
39+
<img className="cover-image" src={data.thumbnail} alt="" />
40+
) : (
41+
<div className="image-placeholder bg-gray-100 dark:bg-dark-500"></div>
42+
)}
43+
</div>
44+
<div className="px-4 pb-4">
45+
<div className="flex flex-row justify-between">
46+
<UserSnippet user={data.createdBy} />
47+
<GoKebabVertical className="mt-4" />
4448
</div>
45-
<div className="px-4 pb-4">
46-
<div className="flex flex-row justify-between">
47-
<UserSnippet user={data.createdBy} />
48-
<GoKebabVertical className="mt-4" />
49-
</div>
50-
<div className="prose dark:text-gray-100">
51-
<h3 className="dark:text-gray-200">{data.title}</h3>
52-
<p className="abstract-content">{data.abstractContent}</p>
53-
</div>
49+
<div className="prose dark:text-gray-100">
50+
<h3 className="dark:text-gray-200">{data.title}</h3>
51+
<p className="abstract-content">{data.abstractContent}</p>
5452
</div>
55-
</a>
53+
</div>
5654
</Link>
5755
<StoryPreviewFooter story={data} />
5856
<style jsx>

src/components/feed/StoryPreviewFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RiHeart3Fill } from '@react-icons/all-files/ri/RiHeart3Fill'
22
import { RiHeartLine } from '@react-icons/all-files/ri/RiHeartLine'
33
import { graphql, useMutation, useRefetchableFragment } from 'react-relay'
4-
import { StoryPreviewFooter_story$key } from '../../queries/__generated__/StoryPreviewFooter_story.graphql'
4+
import { StoryPreviewFooter_story$key } from '__generated__/StoryPreviewFooter_story.graphql'
55

66
type StoryPreviewFooterProps = {
77
story: StoryPreviewFooter_story$key

src/components/feed/UserSnippet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Link from 'next/link'
22
import { graphql, useFragment } from 'react-relay'
3-
import { UserSnippet_user$key } from '../../queries/__generated__/UserSnippet_user.graphql'
4-
import { getCompactNumber } from '../../utils/formatNumber'
3+
import { UserSnippet_user$key } from '__generated__/UserSnippet_user.graphql'
4+
import { getCompactNumber } from 'src/utils/formatNumber'
55

66
type UserSnippetProps = {
77
user: UserSnippet_user$key

src/pages/story/[id].tsx

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)