Skip to content

Commit

Permalink
first test
Browse files Browse the repository at this point in the history
  • Loading branch information
langonginc committed Oct 19, 2024
1 parent 3eec759 commit dae720b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/app-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ import { setLogin } from '../redux/app/app-slice';
import { setParam } from '../redux/param/param-slice';
import { clearSelected, closePaletteAppClip, onPaletteAppClipEmit } from '../redux/runtime/runtime-slice';
import { Param } from '../constants/constants';
import { MetadataDetail } from '../constants/marketplace';
import { upgrade } from '../util/save';
import { nanoid } from '../util/helper';
import WindowHeader from './header/window-header';
import RmgPaletteAppClip from './panel/rmg-palette-app-clip';
import DesignerRoot from './designer-root';
import Ticket from './marketplace/ticket';
import { MetadataDetail } from '../constants/marketplace';

const RMP_GALLERY_CHANNEL_NAME = 'RMP_GALLERY_CHANNEL';
const RMP_GALLERY_CHANNEL_OPEN_EVENT = 'OPEN_DESIGNER';
const RMP_GALLERY_CHANNEL_NEW_EVENT = 'NEW_DESIGNER';
const CHN = new BroadcastChannel(RMP_GALLERY_CHANNEL_NAME);

const RMP_MASTER_CHANNEL_NAME = 'RMP_MASTER_CHANNEL';
const RMP_MASTER_CHANNEL_REQUEST = 'MASTER_REQUEST';
const RMP_MASTER_CHANNEL_POST = 'MASTER_POST';
const CHN_MASTER = new BroadcastChannel(RMP_MASTER_CHANNEL_NAME);

export default function AppRoot() {
const navigate = useNavigate();
const isInNew = useMatch('/new');
const dispatch = useRootDispatch();
const {
paletteAppClip: { input },
} = useRootSelector(state => state.runtime);
const param = useRootSelector(state => state.param);

React.useEffect(() => {
const p = localStorage.getItem('rmg-home__account');
Expand Down Expand Up @@ -61,8 +68,21 @@ export default function AppRoot() {
}
};
CHN.addEventListener('message', handleMessage);

const handleMaster = (e: MessageEvent) => {
const { event } = e.data;
if (event === RMP_MASTER_CHANNEL_REQUEST) {
const post = JSON.stringify({ ...param, id: nanoid(6) });
CHN.postMessage({
event: RMP_MASTER_CHANNEL_POST,
data: post,
});
}
};
CHN_MASTER.addEventListener('message', handleMaster);
return () => {
CHN.removeEventListener('message', handleMessage);
CHN_MASTER.removeEventListener('message', handleMaster);
};
}, []);

Expand Down

0 comments on commit dae720b

Please sign in to comment.