|
1 | 1 | import "./styles/index.css"; |
2 | | -import React, { useEffect } from "react"; |
| 2 | +import React from "react"; |
3 | 3 |
|
4 | 4 | import { Page } from "@/models/generated"; |
5 | | -import { loadPage } from "@/serialization/loader"; |
6 | 5 |
|
7 | 6 | import { BlockRenderer } from "./components/BlockRenderer"; |
8 | | -import { PageDelimiter } from "./components/PageDelimiter"; |
9 | | -import { JsonViewPanel } from "./components/dev/JsonViewPanel"; |
10 | | -import { RendererProvider } from "./context/RendererContext"; |
11 | | -import { HighlightNavigation } from "./components/HighlightNavigation"; |
12 | | -import { useHighlights } from "./hooks/useHighlights"; |
| 7 | +import { RendererContainer } from "./components/RendererContainer"; |
13 | 8 | import { Backref } from "./utils/highlightUtils"; |
14 | 9 | import { GlobalErrorBoundary } from "./components/ErrorBoundary"; |
15 | 10 |
|
@@ -40,101 +35,22 @@ export const JsonDocRenderer = ({ |
40 | 35 | backrefs = [], |
41 | 36 | onError, |
42 | 37 | }: JsonDocRendererProps) => { |
43 | | - // Use the modular hooks for highlight management |
44 | | - const { highlightCount, currentActiveIndex, navigateToHighlight } = |
45 | | - useHighlights({ |
46 | | - backrefs, |
47 | | - }); |
48 | | - |
49 | | - useEffect(() => { |
50 | | - try { |
51 | | - //TODO: this is not throwing for invalid page object (one that doesn't follow schema) |
52 | | - loadPage(page); |
53 | | - } catch (_) { |
54 | | - // console.log("error ", error); |
55 | | - } |
56 | | - }, [page]); |
57 | | - |
58 | | - // return null; |
59 | | - const renderedContent = ( |
60 | | - <div className="json-doc-page"> |
61 | | - {/* Page icon */} |
62 | | - {page.icon && ( |
63 | | - <div className="json-doc-page-icon"> |
64 | | - {page.icon.type === "emoji" && page.icon.emoji} |
65 | | - </div> |
66 | | - )} |
67 | | - {/* Page title */} |
68 | | - {page.properties?.title && ( |
69 | | - <h1 className="json-doc-page-title" data-page-id={page.id}> |
70 | | - {page.properties.title.title?.[0]?.plain_text || "Untitled"} |
71 | | - </h1> |
72 | | - )} |
73 | | - {/* Page children blocks */} |
74 | | - {page.children && page.children.length > 0 && ( |
75 | | - <div className="json-doc-page-content"> |
76 | | - {page.children.map((block: any, index: number) => { |
77 | | - const currentPageNum = block.metadata?.origin?.page_num; |
78 | | - const nextPageNum = |
79 | | - index < page.children.length - 1 |
80 | | - ? (page.children[index + 1]?.metadata as any)?.origin?.page_num |
81 | | - : null; |
82 | | - |
83 | | - // Show delimiter after the last block of each page |
84 | | - const showPageDelimiter = |
85 | | - currentPageNum && |
86 | | - (nextPageNum !== currentPageNum || |
87 | | - index === page.children.length - 1); |
88 | | - |
89 | | - return ( |
90 | | - <React.Fragment key={block.id || index}> |
91 | | - <BlockRenderer |
92 | | - block={block} |
93 | | - depth={0} |
94 | | - components={components} |
95 | | - /> |
96 | | - |
97 | | - {showPageDelimiter && !components?.page_delimiter && ( |
98 | | - <PageDelimiter pageNumber={currentPageNum} /> |
99 | | - )} |
100 | | - {showPageDelimiter && components?.page_delimiter && ( |
101 | | - <components.page_delimiter pageNumber={currentPageNum} /> |
102 | | - )} |
103 | | - </React.Fragment> |
104 | | - ); |
105 | | - })} |
106 | | - </div> |
107 | | - )} |
108 | | - </div> |
109 | | - ); |
110 | | - |
| 38 | + console.log("theme: ", theme); |
111 | 39 | return ( |
112 | 40 | <div |
113 | 41 | className={`jsondoc-theme-${theme}`} |
114 | 42 | data-testid="jsondoc-renderer-root" |
115 | 43 | > |
116 | 44 | <GlobalErrorBoundary onError={onError}> |
117 | | - <RendererProvider value={{ devMode, resolveImageUrl }}> |
118 | | - <div |
119 | | - className={`json-doc-renderer${className ? " " + className : ""}`} |
120 | | - > |
121 | | - {viewJson ? ( |
122 | | - <div className="flex h-screen"> |
123 | | - <JsonViewPanel data={page} /> |
124 | | - </div> |
125 | | - ) : ( |
126 | | - renderedContent |
127 | | - )} |
128 | | - {/* Show highlight navigation when there are highlights */} |
129 | | - {highlightCount > 0 && ( |
130 | | - <HighlightNavigation |
131 | | - highlightCount={highlightCount} |
132 | | - onNavigate={navigateToHighlight} |
133 | | - currentIndex={currentActiveIndex} |
134 | | - /> |
135 | | - )} |
136 | | - </div> |
137 | | - </RendererProvider> |
| 45 | + <RendererContainer |
| 46 | + page={page} |
| 47 | + className={className} |
| 48 | + components={components} |
| 49 | + devMode={devMode} |
| 50 | + resolveImageUrl={resolveImageUrl} |
| 51 | + viewJson={viewJson} |
| 52 | + backrefs={backrefs} |
| 53 | + /> |
138 | 54 | </GlobalErrorBoundary> |
139 | 55 | </div> |
140 | 56 | ); |
|
0 commit comments