Skip to content

Commit

Permalink
init tab states on the panel entry
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed May 14, 2024
1 parent 6cd1a62 commit 415c970
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Props {

export function EditorInspectorButton({tabID, setErrorMessage}: Props) {
const {isSelecting} = useExtensionStore();
const isActive = isSelecting[tabID] ?? false;
const isActive = isSelecting[tabID];

const handleClick = () => {
const injectedPegasusService = getRPCService<IInjectedPegasusService>(
Expand Down
20 changes: 11 additions & 9 deletions packages/lexical-devtools/src/entrypoints/devtools-panel/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import App from './App.tsx';
const tabID = browser.devtools.inspectedWindow.tabId;
initPegasusTransport();

extensionStoreReady().then(() =>
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ChakraProvider>
<App tabID={tabID} />
</ChakraProvider>
</React.StrictMode>,
),
);
extensionStoreReady()
.then((store) => store.getState().initTab(tabID))
.then(() =>
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ChakraProvider>
<App tabID={tabID} />
</ChakraProvider>
</React.StrictMode>,
),
);
16 changes: 16 additions & 0 deletions packages/lexical-devtools/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ExtensionState {
isSelecting: {
[tabID: number]: boolean;
};
initTab: (tabID: number) => void;
markTabAsRestricted: (tabID: number) => void;
setStatesForTab: (
id: number,
Expand All @@ -36,6 +37,21 @@ export interface ExtensionState {

export const useExtensionStore = create<ExtensionState>()(
subscribeWithSelector((set) => ({
initTab: (tabID: number) =>
set((state) => ({
isSelecting: {
...state.isSelecting,
[tabID]: false,
},
lexicalState: {
...state.lexicalState,
[tabID]: null,
},
selectedEditorKey: {
...state.selectedEditorKey,
[tabID]: null,
},
})),
isSelecting: {},
lexicalState: {},
markTabAsRestricted: (tabID: number) =>
Expand Down

0 comments on commit 415c970

Please sign in to comment.