@@ -31,6 +31,7 @@ import { IBookmark } from 'types/bookmark';
3131import { fmtDateTime , unix2date } from 'utils/util' ;
3232import CitationDialog from '../chat/CitationDialog' ;
3333import useMermaid from '../../../hooks/useMermaid' ;
34+ import useECharts from 'hooks/useECharts' ;
3435
3536const ArrowLeftIcon = bundleIcon ( ArrowLeft16Filled , ArrowLeft16Regular ) ;
3637const DeleteIcon = bundleIcon ( Delete16Filled , Delete16Regular ) ;
@@ -52,7 +53,28 @@ export default function Bookmark() {
5253 const { showCitation } = useKnowledgeStore ( ) ;
5354 const { notifyInfo } = useToast ( ) ;
5455 const bookmarks = useBookmarkStore ( ( state ) => state . bookmarks ) ;
56+ const bookmark = useMemo (
57+ ( ) => bookmarks . find ( ( item ) => item . id === id ) as IBookmark ,
58+ [ id ] ,
59+ ) ;
60+ const citedFiles = useMemo (
61+ ( ) => JSON . parse ( bookmark ?. citedFiles || '[]' ) ,
62+ [ bookmark ] ,
63+ ) ;
5564 const { renderMermaid } = useMermaid ( ) ;
65+ const { initECharts, disposeECharts } = useECharts ( { message : bookmark } ) ;
66+
67+ const renderECharts = useCallback (
68+ ( prefix : string , msgDom : Element ) => {
69+ const charts = msgDom . querySelectorAll ( '.echarts-container' ) ;
70+ if ( charts . length > 0 ) {
71+ charts . forEach ( ( chart ) => {
72+ initECharts ( prefix , chart . id ) ;
73+ } ) ;
74+ }
75+ } ,
76+ [ initECharts ] ,
77+ ) ;
5678
5779 const onCitationClick = async ( event : any ) => {
5880 const url = new URL ( event . target ?. href ) ;
@@ -70,13 +92,19 @@ export default function Bookmark() {
7092 }
7193 } ;
7294
73-
7495 // @disable -lint react-hooks/exhaustive-deps
7596 useEffect ( ( ) => {
7697 setUpdated ( false ) ;
7798 setActiveBookmarkId ( id as string ) ;
99+ const msgDom = document . querySelector ( `#${ id } ` ) ;
100+ if ( ! msgDom ) {
101+ return ;
102+ }
103+ const promptNode = msgDom . querySelector ( '.bookmark-prompt' ) as Element ;
104+ renderECharts ( 'prompt' , promptNode ) ;
105+ const replyNode = msgDom . querySelector ( '.bookmark-reply' ) as Element ;
106+ renderECharts ( 'reply' , replyNode ) ;
78107 renderMermaid ( ) ;
79-
80108 const links = document . querySelectorAll ( '.bookmark-reply a' ) ;
81109 links . forEach ( ( link ) => {
82110 link . addEventListener ( 'click' , onCitationClick ) ;
@@ -85,19 +113,10 @@ export default function Bookmark() {
85113 links . forEach ( ( link ) => {
86114 link . removeEventListener ( 'click' , onCitationClick ) ;
87115 } ) ;
116+ disposeECharts ( ) ;
88117 } ;
89118 } , [ updated , id ] ) ;
90119
91- const bookmark = useMemo (
92- ( ) => bookmarks . find ( ( item ) => item . id === id ) as IBookmark ,
93- [ id ] ,
94- ) ;
95-
96- const citedFiles = useMemo (
97- ( ) => JSON . parse ( bookmark ?. citedFiles || '[]' ) ,
98- [ bookmark ] ,
99- ) ;
100-
101120 const [ isThinkShow , setIsThinkShow ] = useState ( false ) ;
102121 const toggleThink = useCallback ( ( ) => {
103122 setIsThinkShow ( ! isThinkShow ) ;
@@ -212,11 +231,11 @@ export default function Bookmark() {
212231 </ div >
213232 </ div >
214233 </ div >
215- < div className = "h-full overflow-y-auto -mr-5 bookmark" >
234+ < div className = "h-full overflow-y-auto -mr-5 bookmark" id = { id } >
216235 < div className = "mr-5" >
217236 < div className = "mx-auto" >
218237 < div
219- className = "bg-brand-surface-2 rounded px-1.5 py-2.5"
238+ className = "bg-brand-surface-2 rounded px-1.5 py-2.5 bookmark-prompt "
220239 dangerouslySetInnerHTML = { {
221240 __html : render ( bookmark . prompt || '' ) ,
222241 } }
0 commit comments