Skip to content

Commit 53a1776

Browse files
MBP16Copilot
andauthored
feat: add update page based on notion (#112)
* feat: add update page based on notion * style: update asynchronous pattern Co-authored-by: Copilot <[email protected]> * refactor: UpdatePage to use constants for default IDs --------- Co-authored-by: Copilot <[email protected]>
1 parent 9e9ffde commit 53a1776

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"react-slick": "^0.29.0",
4646
"redux": "^4.0.0",
4747
"slick-carousel": "^1.8.1",
48-
"zabo-embed": "^0.0.7"
48+
"zabo-embed": "^0.0.7",
49+
"react-notion": "^0.10.0"
4950
},
5051
"devDependencies": {
5152
"@babel/plugin-proposal-decorators": "^7.24.1",

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import ko from '@/translations/translation.ko.json';
3838

3939
import 'slick-carousel/slick/slick.css';
4040
import 'slick-carousel/slick/slick-theme.css';
41+
import UpdatePage from '@/pages/UpdatePage';
4142

4243
declare global {
4344
interface Window {
@@ -177,6 +178,7 @@ const router = createBrowserRouter([
177178
{ path: 'error/:message', element: <ErrorPage /> },
178179
{ path: 'login/success', element: <LoginSuccessHandler /> },
179180
{ path: 'developer-login', element: <DeveloperLoginPage /> },
181+
{ path: 'update', element: <UpdatePage /> },
180182
{ path: '*', element: <Navigate to="/" /> },
181183
],
182184
},

src/pages/UpdatePage.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { NotionRenderer } from 'react-notion';
2+
3+
import { useEffect, useState } from 'react';
4+
5+
import 'react-notion/src/styles.css';
6+
import 'prismjs/themes/prism-tomorrow.css';
7+
import { appBoundClassNames as classNames } from '@/common/boundClassNames';
8+
9+
const DEFAULT_PAGE_ID = '23ac25603b0b80f8b343d2324a7e2131';
10+
const OFFICIAL_SPACE_ID = 'ca8b3bc6-6b17-4a1f-8f57-2dd4b58a84f7';
11+
12+
const UpdatePage = () => {
13+
const [blockMap, setBlockMap] = useState(null);
14+
const query = new URLSearchParams(window.location.search);
15+
const pageId = query.get('pageId') || DEFAULT_PAGE_ID;
16+
const [spaceId, setSpaceId] = useState('');
17+
18+
useEffect(() => {
19+
const fetchNotionData = async () => {
20+
const res = await fetch(`https://notion-api.splitbee.io/v1/page/${pageId}`);
21+
const json = await res.json();
22+
Object.keys(json).forEach((key) => {
23+
if (json[key].role === 'none') {
24+
delete json[key];
25+
} else {
26+
setSpaceId(json[key].value.space_id);
27+
}
28+
});
29+
setBlockMap(json);
30+
};
31+
fetchNotionData();
32+
}, []);
33+
useEffect(() => {
34+
if (spaceId !== '' && spaceId !== OFFICIAL_SPACE_ID) {
35+
window.location.href = '/update';
36+
}
37+
}, [spaceId]);
38+
39+
return (
40+
<section className={classNames('content', 'content--no-scroll')}>
41+
{blockMap !== null && spaceId === OFFICIAL_SPACE_ID && (
42+
<NotionRenderer
43+
blockMap={blockMap}
44+
fullPage={true}
45+
hideHeader={true}
46+
mapPageUrl={(pageId) => {
47+
return '/update?' + new URLSearchParams({ pageId: pageId });
48+
}}
49+
/>
50+
)}
51+
</section>
52+
);
53+
};
54+
55+
export default UpdatePage;

yarn.lock

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,7 @@ inflight@^1.0.4:
42024202

42034203
inherits@2:
42044204
version "2.0.4"
4205-
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz"
4205+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
42064206
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
42074207

42084208
@@ -5479,7 +5479,7 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
54795479

54805480
minimist@^1.2.0, minimist@^1.2.6:
54815481
version "1.2.8"
5482-
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz"
5482+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
54835483
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
54845484

54855485
moment@^2.29.2:
@@ -5639,7 +5639,7 @@ object.values@^1.1.6:
56395639

56405640
once@^1.3.0:
56415641
version "1.4.0"
5642-
resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz"
5642+
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
56435643
integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==
56445644
dependencies:
56455645
wrappy "1"
@@ -5923,6 +5923,11 @@ pretty-format@^29.0.0, pretty-format@^29.7.0:
59235923
ansi-styles "^5.0.0"
59245924
react-is "^18.0.0"
59255925

5926+
prismjs@^1.21.0:
5927+
version "1.30.0"
5928+
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.30.0.tgz#d9709969d9d4e16403f6f348c63553b19f0975a9"
5929+
integrity sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw==
5930+
59265931
prompts@^2.0.1:
59275932
version "2.4.2"
59285933
resolved "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz"
@@ -6063,6 +6068,13 @@ react-markdown@^7.1.0:
60636068
unist-util-visit "^4.0.0"
60646069
vfile "^5.0.0"
60656070

6071+
react-notion@^0.10.0:
6072+
version "0.10.0"
6073+
resolved "https://registry.yarnpkg.com/react-notion/-/react-notion-0.10.0.tgz#d30876b681b09d91dc671b04c7f604adb4e2499e"
6074+
integrity sha512-i5lVAxzSs7GnTpIbKtivPQWxGZiKCO5xmCmMJyn6F91y8X1IIJqnypkK+31F2acb1l1Qd8Yv0ktuvXwz9g49NQ==
6075+
dependencies:
6076+
prismjs "^1.21.0"
6077+
60666078
react-redux@^7.2.1:
60676079
version "7.2.9"
60686080
resolved "https://registry.npmjs.org/react-redux/-/react-redux-7.2.9.tgz"

0 commit comments

Comments
 (0)