11import { IJGISStoryMap , IJupyterGISModel } from '@jupytergis/schema' ;
2- import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
2+ import jgisSchema from '@jupytergis/schema/lib/schema/project/jgis.json' ;
3+ import React , { useMemo } from 'react' ;
34
45import { StoryEditorForm } from '@/src/formbuilder/objectform/StoryForm' ;
56import { deepCopy } from '@/src/tools' ;
@@ -10,46 +11,12 @@ interface IStoryPanelProps {
1011 togglePreview : ( ) => void ;
1112}
1213
13- export function StoryEditorPanel ( { model, togglePreview } : IStoryPanelProps ) {
14- const [ schema , setSchema ] = useState < IDict | undefined > ( undefined ) ;
15- const [ storyData , setStoryData ] = useState < IJGISStoryMap | null > ( null ) ;
14+ const storyMapSchema : IDict = deepCopy ( jgisSchema . definitions . jGISStoryMap ) ;
1615
17- // Get selected story info (derived from model)
16+ export function StoryEditorPanel ( { model , togglePreview } : IStoryPanelProps ) {
1817 const { landmarkId, story } = useMemo ( ( ) => {
1918 return model . getSelectedStory ( ) ;
20- } , [ model ] ) ;
21-
22- // Helper to update story data from selected story
23- const updateStoryFromModel = useCallback ( ( ) => {
24- setStoryData ( story ?? null ) ;
25- } , [ story ] ) ;
26-
27- // Load schema once on mount
28- useEffect ( ( ) => {
29- // Get the story map schema from the definitions
30- // eslint-disable-next-line @typescript-eslint/no-var-requires
31- const jgisSchema = require ( '@jupytergis/schema/lib/schema/project/jgis.json' ) ;
32- const storyMapSchema = deepCopy ( jgisSchema . definitions . jGISStoryMap ) ;
33- setSchema ( storyMapSchema ) ;
34- } , [ ] ) ;
35-
36- // Load initial story data when selected story changes
37- useEffect ( ( ) => {
38- updateStoryFromModel ( ) ;
39- } , [ updateStoryFromModel ] ) ;
40-
41- // Listen for story map changes
42- useEffect ( ( ) => {
43- if ( ! landmarkId ) {
44- return ;
45- }
46-
47- model . sharedModel . storyMapsChanged . connect ( updateStoryFromModel ) ;
48-
49- return ( ) => {
50- model . sharedModel . storyMapsChanged . disconnect ( updateStoryFromModel ) ;
51- } ;
52- } , [ model , landmarkId , updateStoryFromModel ] ) ;
19+ } , [ model , model . sharedModel . storiesMap ] ) ;
5320
5421 const syncStoryData = ( properties : IDict ) => {
5522 if ( ! landmarkId ) {
@@ -59,11 +26,10 @@ export function StoryEditorPanel({ model, togglePreview }: IStoryPanelProps) {
5926 const { title, storyType, landmarks } = properties ;
6027 const updatedStory : IJGISStoryMap = { title, storyType, landmarks } ;
6128
62- setStoryData ( updatedStory ) ;
6329 model . sharedModel . updateStoryMap ( landmarkId , updatedStory ) ;
6430 } ;
6531
66- if ( ! storyData ) {
32+ if ( ! story ) {
6733 return (
6834 < div style = { { padding : '10px' } } >
6935 < p > No story map available. Create one by adding a landmark.</ p >
@@ -76,9 +42,9 @@ export function StoryEditorPanel({ model, togglePreview }: IStoryPanelProps) {
7642 < h3 > Story Map Properties</ h3 >
7743 < StoryEditorForm
7844 formContext = "update"
79- sourceData = { storyData }
45+ sourceData = { story }
8046 model = { model }
81- schema = { schema }
47+ schema = { storyMapSchema }
8248 syncData = { syncStoryData }
8349 filePath = { model . filePath }
8450 togglePreview = { togglePreview }
0 commit comments