Skip to content

Commit

Permalink
#877 Fix loading param to master node from designer and gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
langonginc committed Nov 10, 2024
1 parent 32c1057 commit fb603dd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/components/page-header/master-import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ export const MasterImport = (props: {
const [list, setList] = React.useState<MasterTypeList[]>([]);
const [selectedParam, setSelectedParam] = React.useState<MasterTypeList>(defaultMasterSelected);
const [param, setParam] = React.useState('');
const paramRef = React.useRef(param);
const [useTextarea, setUseTextarea] = React.useState(false);
const [textareaInvalid, setTextareaInvalid] = React.useState(false);
React.useEffect(() => {
paramRef.current = param;
}, [param]);

React.useEffect(() => {
if (isOpen) {
Expand All @@ -97,10 +93,9 @@ export const MasterImport = (props: {
}
}, [isOpen]);

const handleChange = () => {
const handleChange = (importedParam: string) => {
try {
const s = selectedParam.param === null ? paramRef.current : JSON.stringify(selectedParam.param);
const p = JSON.parse(s);
const p = selectedParam.param ?? JSON.parse(importedParam);
const rid = p.id ? p.id : p.randomId;
const hex = p.labelColorBg ?? getRandomHexColor();
const param: MasterParam = {
Expand Down Expand Up @@ -143,9 +138,8 @@ export const MasterImport = (props: {
const handleMaster = (e: MessageEvent) => {
const { event, data } = e.data;
if (event === RMP_MASTER_CHANNEL_POST && isOpenRef.current) {
setParam(data);
setAppClipOpen(false);
handleChange();
handleChange(data);
}
};
CHN.addEventListener('message', handleMaster);
Expand Down Expand Up @@ -242,7 +236,7 @@ export const MasterImport = (props: {
colorScheme="blue"
variant="solid"
mr="1"
onClick={handleChange}
onClick={() => handleChange(param)}
isDisabled={selectedParam.id === 'null' && param === ''}
>
{t('apply')}
Expand Down

0 comments on commit fb603dd

Please sign in to comment.