@@ -3,11 +3,12 @@ import ParamSelector from './param-selector';
33import  React ,  {  useEffect ,  useRef ,  useState  }  from  'react' ; 
44import  {  Events ,  LocalStorageKey ,  ParamConfig  }  from  '../../constants/constants' ; 
55import  {  getParamRegistry  }  from  '../../util/param-manager-utils' ; 
6- import  {  Button ,  HStack ,  IconButton ,  SystemStyleObject  }  from  '@chakra-ui/react' ; 
6+ import  {  Alert ,   AlertIcon ,   Button ,  HStack ,  IconButton ,  SystemStyleObject  }  from  '@chakra-ui/react' ; 
77import  {  useTranslation  }  from  'react-i18next' ; 
88import  {  useSearchParams  }  from  'react-router-dom' ; 
99import  rmgRuntime  from  '@railmapgen/rmg-runtime' ; 
1010import  {  MdRefresh ,  MdSettings  }  from  'react-icons/md' ; 
11+ import  {  updateParam  }  from  '../../util/param-updater-utils' ; 
1112
1213const  CHANNEL_PREFIX  =  'rmg-bridge--' ; 
1314
@@ -40,6 +41,7 @@ export default function AppClipView() {
4041
4142    const  [ paramRegistry ,  setParamRegistry ]  =  useState < ParamConfig [ ] > ( [ ] ) ; 
4243    const  [ selectedParam ,  setSelectedParam ]  =  useState < string > ( ) ; 
44+     const  [ isError ,  setIsError ]  =  useState ( false ) ; 
4345
4446    const  channelRef  =  useRef < BroadcastChannel > ( ) ; 
4547
@@ -65,14 +67,21 @@ export default function AppClipView() {
6567    const  handleImport  =  ( )  =>  { 
6668        const  paramConfigStr  =  window . localStorage . getItem ( LocalStorageKey . PARAM_CONFIG_BY_ID  +  selectedParam ) ; 
6769        const  paramStr  =  window . localStorage . getItem ( LocalStorageKey . PARAM_BY_ID  +  selectedParam ) ; 
68-         channelRef . current ?. postMessage ( { 
69-             event : 'IMPORT' , 
70-             meta : paramConfigStr  ? JSON . parse ( paramConfigStr )  : null , 
71-             data : paramStr  ? JSON . parse ( paramStr )  : null , 
72-         } ) ; 
73-         rmgRuntime . event ( Events . APP_CLIP_VIEW_IMPORT ,  {  parentComponent } ) ; 
7470
75-         setSelectedParam ( undefined ) ; 
71+         try  { 
72+             const  updatedParam  =  paramStr  ? updateParam ( JSON . parse ( paramStr ) )  : null ; 
73+             channelRef . current ?. postMessage ( { 
74+                 event : 'IMPORT' , 
75+                 meta : paramConfigStr  ? JSON . parse ( paramConfigStr )  : null , 
76+                 data : updatedParam , 
77+             } ) ; 
78+             rmgRuntime . event ( Events . APP_CLIP_VIEW_IMPORT ,  {  parentComponent } ) ; 
79+ 
80+             setSelectedParam ( undefined ) ; 
81+             setIsError ( false ) ; 
82+         }  catch  ( e )  { 
83+             setIsError ( true ) ; 
84+         } 
7685    } ; 
7786
7887    const  handleClose  =  ( )  =>  { 
@@ -82,6 +91,7 @@ export default function AppClipView() {
8291        rmgRuntime . event ( Events . APP_CLIP_VIEW_CLOSED ,  {  parentComponent } ) ; 
8392
8493        setSelectedParam ( undefined ) ; 
94+         setIsError ( false ) ; 
8595    } ; 
8696
8797    const  handleManage  =  ( )  =>  { 
@@ -90,6 +100,12 @@ export default function AppClipView() {
90100
91101    return  ( 
92102        < RmgPage > 
103+             { isError  &&  ( 
104+                 < Alert  status = "error"  variant = "solid"  size = "xs"  pl = { 3 }  pr = { 1 }  py = { 1 } > 
105+                     < AlertIcon  /> 
106+                     { t ( 'Project selected is invalid or corrupted.' ) } 
107+                 </ Alert > 
108+             ) } 
93109            < RmgCard  sx = { styles } > 
94110                < ParamSelector 
95111                    paramRegistry = { paramRegistry } 
0 commit comments