Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(whiteboard): window-manager repeat mount when whiteboard unMount #1014

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions desktop/renderer-app/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { WhiteboardStore } from "../stores/whiteboard-store";
import { isSupportedImageType, onDropImage } from "../utils/dnd/image";
import { ScenesController } from "flat-components";
import { AppStoreButton } from "./AppStoreButton";
import { useIsUnMounted } from "../utils/hooks/lifecycle";

export interface WhiteboardProps {
whiteboardStore: WhiteboardStore;
}

export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteboardStore }) {
const { room } = whiteboardStore;
const isUnMountedRef = useIsUnMounted();

const [whiteboardEl, setWhiteboardEl] = useState<HTMLElement | null>(null);
const [collectorEl, setCollectorEl] = useState<HTMLElement | null>(null);
Expand All @@ -40,12 +42,20 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteb
},
chessboard: false,
});
whiteboardStore.onMainViewModeChange();
whiteboardStore.onWindowManagerBoxStateChange();
if (isUnMountedRef.current) {
whiteboardStore.destroyWindowManager();
} else {
whiteboardStore.onMainViewModeChange();
whiteboardStore.onWindowManagerBoxStateChange();
}
}
};

void mountWindowManager();

return () => {
whiteboardStore.destroyWindowManager();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [whiteboardEl, collectorEl, room]);

Expand Down
7 changes: 6 additions & 1 deletion desktop/renderer-app/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export class WhiteboardStore {
});
};

public destroyWindowManager = (): void => {
this.windowManager?.destroy();
this.windowManager = null;
};

public async joinWhiteboardRoom(): Promise<void> {
if (!globalStore.userUUID) {
throw new Error("Missing userUUID");
Expand Down Expand Up @@ -372,7 +377,7 @@ export class WhiteboardStore {

public destroy(): void {
this.preloadPPTResource.cancel();
this.windowManager?.destroy();
this.destroyWindowManager();
this.room?.callbacks.off();

if (NODE_ENV === "development") {
Expand Down
14 changes: 12 additions & 2 deletions web/flat-web/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { WhiteboardStore } from "../stores/whiteboard-store";
import { isSupportedImageType, onDropImage } from "../utils/dnd/image";
import { ScenesController } from "../../../../packages/flat-components/src";
import { AppStoreButton } from "./AppStoreButton";
import { useIsUnMounted } from "../utils/hooks/lifecycle";

export interface WhiteboardProps {
whiteboardStore: WhiteboardStore;
}

export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteboardStore }) {
const { room } = whiteboardStore;
const isUnMountedRef = useIsUnMounted();

const [whiteboardEl, setWhiteboardEl] = useState<HTMLElement | null>(null);
const [collectorEl, setCollectorEl] = useState<HTMLElement | null>(null);
Expand All @@ -40,12 +42,20 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteb
},
chessboard: false,
});
whiteboardStore.onMainViewModeChange();
whiteboardStore.onWindowManagerBoxStateChange();
if (isUnMountedRef.current) {
whiteboardStore.destroyWindowManager();
} else {
whiteboardStore.onMainViewModeChange();
whiteboardStore.onWindowManagerBoxStateChange();
}
}
};

void mountWindowManager();

return () => {
whiteboardStore.destroyWindowManager();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [whiteboardEl, collectorEl, room]);

Expand Down
7 changes: 6 additions & 1 deletion web/flat-web/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ export class WhiteboardStore {
});
};

public destroyWindowManager = (): void => {
this.windowManager?.destroy();
this.windowManager = null;
};

public async joinWhiteboardRoom(): Promise<void> {
if (!globalStore.userUUID) {
throw new Error("Missing userUUID");
Expand Down Expand Up @@ -380,7 +385,7 @@ export class WhiteboardStore {

public destroy(): void {
this.preloadPPTResource.cancel();
this.windowManager?.destroy();
this.destroyWindowManager();
this.room?.callbacks.off();

if (NODE_ENV === "development") {
Expand Down