Skip to content

Commit abe2460

Browse files
committed
feat: support realtime page reader presence (#288)
* eat: init Signed-off-by: Innei <[email protected]> * feat: init Signed-off-by: Innei <[email protected]> * update Signed-off-by: Innei <[email protected]> * feat: impl it Signed-off-by: Innei <[email protected]> * update Signed-off-by: Innei <[email protected]> * feat: reading duration Signed-off-by: Innei <[email protected]> * fix: tooltip Signed-off-by: Innei <[email protected]> * fix: style Signed-off-by: Innei <[email protected]> * update tooltip Signed-off-by: Innei <[email protected]> * fix: clerk id Signed-off-by: Innei <[email protected]> * fix: comment box style Signed-off-by: Innei <[email protected]> --------- Signed-off-by: Innei <[email protected]>
1 parent b465230 commit abe2460

File tree

89 files changed

+1092
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1092
-228
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@milkdown/react": "7.3.3",
5555
"@milkdown/transformer": "7.3.3",
5656
"@milkdown/utils": "7.3.3",
57-
"@mx-space/api-client": "1.7.2",
57+
"@mx-space/api-client": "1.8.0-alpha.4",
5858
"@prosemirror-adapter/react": "0.2.6",
5959
"@radix-ui/react-dialog": "1.0.5",
6060
"@radix-ui/react-label": "2.0.2",
@@ -93,6 +93,7 @@
9393
"marked": "12.0.0",
9494
"medium-zoom": "1.1.0",
9595
"mermaid": "10.8.0",
96+
"nanoid": "*",
9697
"next": "14.1.0",
9798
"next-themes": "0.2.1",
9899
"openai": "4.27.0",

pnpm-lock.yaml

+7-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(app)/(page-detail)/[slug]/layout.tsx

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react'
22
import type { Metadata } from 'next'
33

4+
import {
5+
buildRoomName,
6+
Presence,
7+
RoomProvider,
8+
} from '~/components/modules/activity'
49
import { CommentAreaRootLazy } from '~/components/modules/comment'
510
import { TocFAB } from '~/components/modules/toc/TocFAB'
611
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
@@ -13,6 +18,7 @@ import { getQueryClient } from '~/lib/query-client.server'
1318
import { requestErrorHandler } from '~/lib/request.server'
1419
import { CurrentPageDataProvider } from '~/providers/page/CurrentPageDataProvider'
1520
import { LayoutRightSideProvider } from '~/providers/shared/LayoutRightSideProvider'
21+
import { WrappedElementProvider } from '~/providers/shared/WrappedElementProvider'
1622
import { queries } from '~/queries/definition'
1723

1824
import {
@@ -81,20 +87,33 @@ export default async (props: NextPageParams<PageParams>) => {
8187
<PageLoading>
8288
<div className="relative w-full min-w-0">
8389
<HeaderMetaInfoSetting />
84-
<article className="prose">
85-
<header className="mb-8">
86-
<BottomToUpSoftScaleTransitionView lcpOptimization delay={0}>
87-
<PageTitle />
88-
</BottomToUpSoftScaleTransitionView>
8990

90-
<BottomToUpSoftScaleTransitionView lcpOptimization delay={200}>
91-
<PageSubTitle />
92-
</BottomToUpSoftScaleTransitionView>
93-
</header>
94-
<BottomToUpTransitionView lcpOptimization delay={600}>
95-
{props.children}
96-
</BottomToUpTransitionView>
97-
</article>
91+
<RoomProvider roomName={buildRoomName(data.id)}>
92+
<WrappedElementProvider>
93+
<article className="prose">
94+
<header className="mb-8">
95+
<BottomToUpSoftScaleTransitionView
96+
lcpOptimization
97+
delay={0}
98+
>
99+
<PageTitle />
100+
</BottomToUpSoftScaleTransitionView>
101+
102+
<BottomToUpSoftScaleTransitionView
103+
lcpOptimization
104+
delay={200}
105+
>
106+
<PageSubTitle />
107+
</BottomToUpSoftScaleTransitionView>
108+
</header>
109+
<BottomToUpTransitionView lcpOptimization delay={600}>
110+
{props.children}
111+
</BottomToUpTransitionView>
112+
113+
<Presence />
114+
</article>
115+
</WrappedElementProvider>
116+
</RoomProvider>
98117

99118
<BottomToUpSoftScaleTransitionView delay={1000}>
100119
<PagePaginator />

src/app/(app)/notes/[id]/layout.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { headers } from 'next/dist/client/components/headers'
22
import type { Metadata } from 'next'
33

4+
import { buildRoomName, RoomProvider } from '~/components/modules/activity'
45
import { CommentAreaRootLazy } from '~/components/modules/comment'
56
import { NoteFontSettingFab } from '~/components/modules/note/NoteFontFab'
67
import { NoteMainContainer } from '~/components/modules/note/NoteMainContainer'
@@ -91,18 +92,19 @@ export default async (
9192
<CurrentNoteNidProvider nid={nid} />
9293
<CurrentNoteDataProvider data={data} />
9394
<SyncNoteDataAfterLoggedIn />
94-
95-
<Transition className="min-w-0" lcpOptimization>
96-
<Paper key={nid} as={NoteMainContainer}>
97-
<NotePage {...data.data} />
98-
</Paper>
99-
<BottomToUpSoftScaleTransitionView delay={500}>
100-
<CommentAreaRootLazy
101-
refId={noteObjectId}
102-
allowComment={allowComment}
103-
/>
104-
</BottomToUpSoftScaleTransitionView>
105-
</Transition>
95+
<RoomProvider roomName={buildRoomName(data.data.id)}>
96+
<Transition className="min-w-0" lcpOptimization>
97+
<Paper key={nid} as={NoteMainContainer}>
98+
<NotePage {...data.data} />
99+
</Paper>
100+
<BottomToUpSoftScaleTransitionView delay={500}>
101+
<CommentAreaRootLazy
102+
refId={noteObjectId}
103+
allowComment={allowComment}
104+
/>
105+
</BottomToUpSoftScaleTransitionView>
106+
</Transition>
107+
</RoomProvider>
106108

107109
<NoteFontSettingFab />
108110

src/app/(app)/notes/[id]/pageExtra.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const NoteTitle = () => {
5959

6060
export const NoteDateMeta = () => {
6161
const created = useCurrentNoteDataSelector((data) => data?.data.created)
62+
6263
if (!created) return null
6364
const dateFormat = dayjs(created)
6465
.locale('zh-cn')

src/app/(app)/notes/[id]/pageImpl.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import type { NoteModel } from '@mx-space/api-client'
55

66
import { AckRead } from '~/components/common/AckRead'
77
import { ClientOnly } from '~/components/common/ClientOnly'
8+
import { Presence } from '~/components/modules/activity'
89
import {
910
NoteActionAside,
1011
NoteBottomBarAction,
1112
NoteFooterNavigationBarForMobile,
13+
NoteMetaBar,
14+
NoteMetaReadingCount,
1215
NoteTopic,
1316
} from '~/components/modules/note'
1417
import { NoteRootBanner } from '~/components/modules/note/NoteBanner'
@@ -22,7 +25,6 @@ import { WrappedElementProvider } from '~/providers/shared/WrappedElementProvide
2225

2326
import { NoteHeadCover } from '../../../../components/modules/note/NoteHeadCover'
2427
import { NoteHideIfSecret } from '../../../../components/modules/note/NoteHideIfSecret'
25-
import { NoteMetaBar } from '../../../../components/modules/note/NoteMetaBar'
2628
import {
2729
IndentArticleContainer,
2830
MarkdownSelection,
@@ -48,6 +50,7 @@ const NotePage = function (props: NoteModel) {
4850

4951
<ClientOnly>
5052
<NoteMetaBar />
53+
<NoteMetaReadingCount />
5154
</ClientOnly>
5255
</span>
5356
<NoteRootBanner />
@@ -56,6 +59,7 @@ const NotePage = function (props: NoteModel) {
5659
<NoteHideIfSecret>
5760
<SummarySwitcher data={props} />
5861
<WrappedElementProvider>
62+
<Presence />
5963
<ReadIndicatorForMobile />
6064
<NoteMarkdownImageRecordProvider>
6165
<BanCopyWrapper>

src/app/(app)/posts/(post-detail)/[category]/[slug]/layout.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import type { Metadata } from 'next'
33

4+
import { buildRoomName, RoomProvider } from '~/components/modules/activity'
45
import { CommentAreaRootLazy } from '~/components/modules/comment'
56
import { TocFAB } from '~/components/modules/toc/TocFAB'
67
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
@@ -79,7 +80,9 @@ export default async (props: NextPageParams<PageParams>) => {
7980
<CurrentPostDataProvider data={data} />
8081
<div className="relative flex min-h-[120px] grid-cols-[auto,200px] lg:grid">
8182
<BottomToUpTransitionView lcpOptimization className="min-w-0">
82-
<PostPage {...data} />
83+
<RoomProvider roomName={buildRoomName(data.id)}>
84+
<PostPage {...data} />
85+
</RoomProvider>
8386

8487
<BottomToUpSoftScaleTransitionView delay={500}>
8588
<CommentAreaRootLazy

src/app/(app)/posts/(post-detail)/[category]/[slug]/pageExtra.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { PropsWithChildren } from 'react'
77

88
import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks'
99
import { PostMetaBar } from '~/components/modules/post/PostMetaBar'
10+
import { CurrentReadingCountingMetaBarItem } from '~/components/modules/shared/MetaBar'
1011
import { WithArticleSelectionAction } from '~/components/modules/shared/WithArticleSelectionAction'
1112
import { MainMarkdown } from '~/components/ui/markdown'
1213
import { noopArr } from '~/lib/noop'
@@ -91,5 +92,9 @@ export const PostMetaBarInternal: Component = ({ className }) => {
9192
}
9293
})
9394
if (!meta) return null
94-
return <PostMetaBar meta={meta} className={className} />
95+
return (
96+
<PostMetaBar meta={meta} className={className}>
97+
<CurrentReadingCountingMetaBarItem />
98+
</PostMetaBar>
99+
)
95100
}

src/app/(app)/posts/(post-detail)/[category]/[slug]/pageImpl.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { PostModel } from '@mx-space/api-client'
22

33
import { AckRead } from '~/components/common/AckRead'
44
import { ClientOnly } from '~/components/common/ClientOnly'
5+
import { Presence } from '~/components/modules/activity'
56
import {
67
PostActionAside,
78
PostBottomBarAction,
@@ -51,6 +52,7 @@ const PostPage = (props: PostModel) => {
5152
</header>
5253
<WrappedElementProvider>
5354
<ReadIndicatorForMobile />
55+
<Presence />
5456
<PostMarkdownImageRecordProvider>
5557
<MarkdownSelection>
5658
<PostMarkdown />

src/app/(app)/says/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Markdown from 'markdown-to-jsx'
77
import type { SayModel } from '@mx-space/api-client'
88
import type { MarkdownToJSX } from 'markdown-to-jsx'
99

10-
import { useIsMobile } from '~/atoms'
10+
import { useIsMobile } from '~/atoms/hooks'
1111
import { LoadMoreIndicator } from '~/components/modules/shared/LoadMoreIndicator'
1212
import { NothingFound } from '~/components/modules/shared/NothingFound'
1313
import { Loading } from '~/components/ui/loading'
@@ -89,7 +89,7 @@ const SaySkeleton = memo(() => {
8989
<div className="relative mb-4 border-l-[3px] border-l-slate-500 bg-slate-200/50 px-4 py-3 dark:bg-neutral-800">
9090
<div className="mb-2 h-6 w-full rounded bg-slate-300/80 dark:bg-neutral-700" />
9191
<div className="flex text-sm text-base-content/60 md:justify-between">
92-
<div className="mb-2 h-4 w-14 rounded bg-slate-300/80 md:mb-0 dark:bg-neutral-700" />
92+
<div className="mb-2 h-4 w-14 rounded bg-slate-300/80 dark:bg-neutral-700 md:mb-0" />
9393
<div className="ml-auto text-right">
9494
<div className="h-4 w-1/4 rounded bg-slate-300/80 dark:bg-neutral-700" />
9595
</div>

src/app/(app)/thinking/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
RecentlyAttitudeResultEnum,
1515
} from '@mx-space/api-client'
1616

17-
import { useIsLogged } from '~/atoms'
17+
import { useIsLogged } from '~/atoms/hooks'
1818
import { TiltedSendIcon } from '~/components/icons/TiltedSendIcon'
1919
import { CommentBoxRootLazy, CommentsLazy } from '~/components/modules/comment'
2020
import { PeekLink } from '~/components/modules/peek/PeekLink'

src/app/(app)/web-dev/layout.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const metadata = {
2+
title: 'dev',
3+
}
4+
5+
export default function RootLayout({
6+
children,
7+
}: {
8+
children: React.ReactNode
9+
}) {
10+
return (
11+
<>
12+
<>{children}</>
13+
</>
14+
)
15+
}

0 commit comments

Comments
 (0)