Skip to content

Commit 726c9cd

Browse files
committed
chore: 将notes根组件改善为rsc
1 parent 3c4de64 commit 726c9cd

File tree

4 files changed

+79
-71
lines changed

4 files changed

+79
-71
lines changed

src/app/(app)/notes/[nid]/page.tsx

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
'use client';
2-
3-
import { m } from 'framer-motion';
4-
import { PropsWithChildren, useEffect, useRef } from 'react';
5-
6-
import { NoteTitle, NoteDateMeta, IndentArticleContainer, NoteMarkdown } from './pageExtra';
7-
8-
import { cn } from '@/lib/helper';
9-
10-
export default function Page({ params }: { params: Record<string, any> }) {
1+
'use server';
2+
3+
import {
4+
NoteTitle,
5+
NoteDateMeta,
6+
IndentArticleContainer,
7+
NoteMarkdown,
8+
PaperLayout,
9+
PageTransition,
10+
} from './pageExtra';
11+
12+
export default async function Page({ params }: { params: Record<string, any> }) {
1113
const { nid } = params;
1214
console.log('id', nid);
1315

@@ -20,59 +22,6 @@ export default function Page({ params }: { params: Record<string, any> }) {
2022
);
2123
}
2224

23-
const PageTransition = ({ children }: PropsWithChildren) => {
24-
return (
25-
<m.div
26-
initial={{ y: 80, opacity: 0.001 }}
27-
animate={{
28-
y: 0,
29-
opacity: 1,
30-
transition: { duration: 0.5, type: 'spring', damping: 20, stiffness: 200 },
31-
}}
32-
className=" min-w-0"
33-
>
34-
{children}
35-
</m.div>
36-
);
37-
};
38-
39-
const PaperLayout = ({ children, className }: PropsWithChildren<{ className?: string }>) => {
40-
const paperLayoutRef = useRef<HTMLDivElement>(null);
41-
useEffect(() => {
42-
if (!paperLayoutRef.current) return;
43-
//侧边可能需要
44-
45-
const mainHeight = paperLayoutRef.current.offsetHeight;
46-
console.log(mainHeight);
47-
48-
const ob = new ResizeObserver((entries) => {
49-
const mainHeight = (entries[0].target as HTMLElement).offsetHeight;
50-
if (mainHeight) console.log(mainHeight);
51-
});
52-
ob.observe(paperLayoutRef.current);
53-
54-
return () => {
55-
ob.disconnect();
56-
};
57-
}, []);
58-
59-
return (
60-
<main
61-
ref={paperLayoutRef}
62-
className={cn(
63-
'relative bg-white dark:bg-zinc-900 md:col-start-1 lg:col-auto',
64-
'-m-4 p-[2rem_1rem] md:m-0 lg:p-[30px_45px]',
65-
'rounded-[0_6px_6px_0] border-zinc-200/70 shadow-sm dark:border-neutral-800 dark:shadow-[#333] lg:border',
66-
'note-layout-main',
67-
'min-w-0',
68-
className,
69-
)}
70-
>
71-
{children}
72-
</main>
73-
);
74-
};
75-
7625
const PageInner = () => (
7726
<>
7827
<div>

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import React, { PropsWithChildren } from 'react';
1+
'use client';
2+
3+
import React, { PropsWithChildren, useEffect, useRef } from 'react';
4+
import { m } from 'framer-motion';
25

36
import text from './test.md';
47

@@ -50,3 +53,56 @@ const MarkdownRenderers: Record<string, any> = {
5053
export const NoteMarkdown = () => {
5154
return <MainMarkdown className="mt-10" allowsScript renderers={MarkdownRenderers} value={text} />;
5255
};
56+
57+
export const PaperLayout = ({ children, className }: PropsWithChildren<{ className?: string }>) => {
58+
const paperLayoutRef = useRef<HTMLDivElement>(null);
59+
useEffect(() => {
60+
if (!paperLayoutRef.current) return;
61+
//侧边可能需要
62+
63+
const mainHeight = paperLayoutRef.current.offsetHeight;
64+
console.log(mainHeight);
65+
66+
const ob = new ResizeObserver((entries) => {
67+
const mainHeight = (entries[0].target as HTMLElement).offsetHeight;
68+
if (mainHeight) console.log(mainHeight);
69+
});
70+
ob.observe(paperLayoutRef.current);
71+
72+
return () => {
73+
ob.disconnect();
74+
};
75+
}, []);
76+
77+
return (
78+
<main
79+
ref={paperLayoutRef}
80+
className={cn(
81+
'relative bg-white dark:bg-zinc-900 md:col-start-1 lg:col-auto',
82+
'-m-4 p-[2rem_1rem] md:m-0 lg:p-[30px_45px]',
83+
'rounded-[0_6px_6px_0] border-zinc-200/70 shadow-sm dark:border-neutral-800 dark:shadow-[#333] lg:border',
84+
'note-layout-main',
85+
'min-w-0',
86+
className,
87+
)}
88+
>
89+
{children}
90+
</main>
91+
);
92+
};
93+
94+
export const PageTransition = ({ children }: PropsWithChildren) => {
95+
return (
96+
<m.div
97+
initial={{ y: 80, opacity: 0.001 }}
98+
animate={{
99+
y: 0,
100+
opacity: 1,
101+
transition: { duration: 0.5, type: 'spring', damping: 20, stiffness: 200 },
102+
}}
103+
className=" min-w-0"
104+
>
105+
{children}
106+
</m.div>
107+
);
108+
};

src/app/(app)/notes/[nid]/test.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
整个博客,不仅仅由 yyblog 组成,还有 ybg-cli 脚手架,用于自动创建删除文章以及编译文章。
66
![Minion](https://octodex.github.com/images/minion.png)
7+
78
```javascript
8-
console.log("Hello, world!");console.log("Hello, world!");
9-
console.log("Hello, world!");console.log("Hello, world!");
10-
console.log("Hello, world!");console.log("Hello, world!");
9+
console.log('Hello, world!');
10+
console.log('Hello, world!');
11+
console.log('Hello, world!');
12+
console.log('Hello, world!');
13+
console.log('Hello, world!');
14+
console.log('Hello, world!');
1115
```
1216

1317
- **yyblog**

src/styles/md.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,14 @@
132132
}
133133
}
134134

135-
.prose :where(code):not(:where([class~="not-prose"], [class~="not-prose"] *)) {
135+
.prose :where(code):not(:where([class~='not-prose'], [class~='not-prose'] *)) {
136136
opacity: 0.7;
137137
font-weight: 600 !important;
138138
font-size: 0.875em !important;
139139
}
140140

141-
.prose :where(code):not(:where([class~="not-prose"] *, pre *)) {
141+
.prose :where(code):not(:where([class~='not-prose'] *, pre *)) {
142142
padding: 1px 8px;
143-
border-radius: .0625rem;
143+
border-radius: 0.0625rem;
144144
color: var(--accent-color) !important;
145145
}
146-

0 commit comments

Comments
 (0)