generated from railmapgen/seed-project
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#285 Support importing project from RMG in upload view
- Loading branch information
Showing
9 changed files
with
809 additions
and
633 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { SystemStyleObject } from '@chakra-ui/react'; | ||
import { useEffect, useState } from 'react'; | ||
import rmgRuntime from '@railmapgen/rmg-runtime'; | ||
import { RmgAppClip } from '@railmapgen/rmg-components'; | ||
|
||
const CHANNEL_PREFIX = 'rmg-bridge--'; | ||
|
||
const styles: SystemStyleObject = { | ||
h: 500, | ||
maxH: '70%', | ||
|
||
'& iframe': { | ||
h: '100%', | ||
w: '100%', | ||
}, | ||
}; | ||
|
||
interface RmgAppClipProps { | ||
templateId?: string; | ||
onClose: () => void; | ||
onImport: (param: Record<string, any>) => void; | ||
} | ||
|
||
export default function RmgParamAppClip(props: RmgAppClipProps) { | ||
const { templateId, onClose, onImport } = props; | ||
|
||
const [appClipId] = useState(crypto.randomUUID()); | ||
const frameUrl = | ||
'/rmg/import?' + | ||
new URLSearchParams({ | ||
parentComponent: rmgRuntime.getAppName(), | ||
parentId: appClipId, | ||
}); | ||
|
||
useEffect(() => { | ||
const channel = new BroadcastChannel(CHANNEL_PREFIX + appClipId); | ||
channel.onmessage = ev => { | ||
const { event, data } = ev.data; | ||
console.log('[rmg-templates] Received event from RMG app clip:', event); | ||
if (event === 'CLOSE') { | ||
onClose(); | ||
} else if (event === 'IMPORT') { | ||
onImport(data); | ||
} | ||
}; | ||
|
||
return () => { | ||
channel.close(); | ||
}; | ||
}, [templateId]); | ||
|
||
return ( | ||
<RmgAppClip isOpen={!!templateId} onClose={onClose} sx={styles}> | ||
<iframe src={frameUrl} loading="lazy" /> | ||
</RmgAppClip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters