Skip to content

Commit 995b04f

Browse files
committed
feat: add media info
Signed-off-by: Innei <[email protected]>
1 parent a28db6e commit 995b04f

File tree

6 files changed

+53
-27
lines changed

6 files changed

+53
-27
lines changed

public/apps/cmusic.png

42.1 KB
Loading

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ export default async (props: NextPageParams<PageParams>) => {
119119
{isCN ? (
120120
<NotSupport />
121121
) : (
122-
<CommentAreaRoot
123-
refId={data.id}
124-
allowComment={data.allowComment ?? true}
125-
/>
122+
<CommentAreaRoot refId={data.id} allowComment={data.allowComment} />
126123
)}
127124
</BottomToUpSoftScaleTransitionView>
128125
</>

src/app/layout.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '../styles/index.css'
22

33
import { Analytics } from '@vercel/analytics/react'
44
import { ToastContainer } from 'react-toastify'
5+
import type { AggregateRoot } from '@mx-space/api-client'
56

67
import { ClerkProvider } from '@clerk/nextjs'
78

@@ -20,8 +21,11 @@ import { init } from './init'
2021

2122
init()
2223

24+
let aggregationData: AggregateRoot | null = null
2325
export const generateMetadata = defineMetadata(async (_, getData) => {
24-
const { seo, url, user } = await getData()
26+
const fetchedData = aggregationData ?? (await getData())
27+
aggregationData = fetchedData
28+
const { seo, url, user } = fetchedData
2529

2630
return {
2731
metadataBase: new URL(url.webUrl),
@@ -93,6 +97,8 @@ export default async function RootLayout(props: Props) {
9397
...queries.aggregation.root(),
9498
})
9599

100+
aggregationData = data
101+
96102
return (
97103
// <ClerkProvider localization={ClerkZhCN}>
98104
<ClerkProvider>

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ export default async (props: NextPageParams<PageParams>) => {
8989
<div className="relative flex min-h-[120px] grid-cols-[auto,200px] lg:grid">
9090
<BottomToUpTransitionView className="min-w-0">
9191
{props.children}
92+
93+
<BottomToUpSoftScaleTransitionView delay={500}>
94+
{isCN ? (
95+
<NotSupport />
96+
) : (
97+
<CommentAreaRoot
98+
refId={data.id}
99+
allowComment={data.allowComment}
100+
/>
101+
)}
102+
</BottomToUpSoftScaleTransitionView>
92103
</BottomToUpTransitionView>
93104

94105
<LayoutRightSideProvider className="relative hidden lg:block" />
95-
96-
<BottomToUpSoftScaleTransitionView delay={500}>
97-
{isCN ? (
98-
<NotSupport />
99-
) : (
100-
<CommentAreaRoot
101-
refId={data.id}
102-
allowComment={data.allowComment ?? true}
103-
/>
104-
)}
105-
</BottomToUpSoftScaleTransitionView>
106106
</div>
107107
</>
108108
)

src/components/layout/header/internal/Activity.tsx

+29-8
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@ const appLabels: { [app: string]: string } = {
3434
NeteaseMusic: 'netease',
3535
iTerm2: 'iterm2',
3636
Xcode: 'xcode',
37+
38+
cmusic: 'cmusic',
3739
}
3840
// autocorrect: true
3941
export function Activity() {
4042
const [isEnabled, setIsEnabled] = useState(true)
4143

42-
const { data: processName } = useQuery(
44+
const { data } = useQuery(
4345
['activity'],
4446
async () => {
4547
return await apiClient.proxy.fn.ps.update
46-
.post<string>()
47-
.then((res) => res as string)
48+
.post<{
49+
processName: string
50+
mediaInfo?: {
51+
title: string
52+
artist: string
53+
}
54+
}>()
55+
.then((res) => res)
4856
.catch((err: RequestError) => {
4957
err.status === 404 && setIsEnabled(false)
50-
return ''
58+
return { processName: '', mediaInfo: undefined }
5159
})
5260
},
5361
{
@@ -58,19 +66,32 @@ export function Activity() {
5866
)
5967
const ownerName = useAggregationSelector((data) => data.user.name)
6068
const memoProcessName = useMemo(
61-
() => ({ processName: processName! }),
62-
[processName],
69+
() => ({ processName: data?.processName || '' }),
70+
[data?.processName],
6371
)
64-
if (!processName) {
72+
if (!data) {
6573
return null
6674
}
75+
const { processName, mediaInfo: media } = data
6776
if (!appLabels[processName]) {
6877
console.log('Not collected process name: ', processName)
6978
return null
7079
}
7180

7281
return (
7382
<AnimatePresence>
83+
{!!media && (
84+
<m.div className="absolute bottom-0 left-[-30px] top-0 flex items-center">
85+
<FloatPopover
86+
TriggerComponent={TriggerComponent}
87+
triggerComponentProps={cMusicProps}
88+
type="tooltip"
89+
>
90+
{ownerName} 正在听 {media.title} - {media.artist}
91+
</FloatPopover>
92+
</m.div>
93+
)}
94+
7495
<m.div
7596
key={processName}
7697
className="pointer-events-auto relative bottom-0 right-[-25px] top-0 z-[10] flex items-center overflow-hidden md:absolute"
@@ -95,7 +116,7 @@ export function Activity() {
95116
</AnimatePresence>
96117
)
97118
}
98-
119+
const cMusicProps = { processName: 'cmusic' }
99120
const TriggerComponent = memo<{
100121
processName: string
101122
}>(({ processName }) => {

src/components/widgets/comment/CommentRoot.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const CommentAreaRoot: FC<
1313
allowComment: boolean
1414
}
1515
> = (props) => {
16-
if (!props.allowComment) {
16+
const { allowComment, refId } = props
17+
// 兜下后端的数据,默认开
18+
if (allowComment && typeof allowComment !== 'undefined') {
1719
return (
1820
<p className="mt-[100px] text-center text-xl font-medium">评论已关闭</p>
1921
)
@@ -22,10 +24,10 @@ export const CommentAreaRoot: FC<
2224
return (
2325
<LazyLoad placeholder={LoadingElement}>
2426
<div className="relative mt-12">
25-
<CommentBoxRoot refId={props.refId} />
27+
<CommentBoxRoot refId={refId} />
2628

2729
<div className="h-12" />
28-
<Comments refId={props.refId} />
30+
<Comments refId={refId} />
2931
</div>
3032
</LazyLoad>
3133
)

0 commit comments

Comments
 (0)