Skip to content

Commit b01ce1c

Browse files
Cheerego7crimx
authored andcommitted
fix(renderer-app): use page store and disable MainPageLayout component in class page (#1633)
* refactor(renderer-app): use page store and adjust style * fix(renderer-app): disable MainPageLayout component in class page
1 parent cbc4eec commit b01ce1c

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

desktop/renderer-app/src/components/MainPageLayoutWrapper.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ export const MainPageLayoutWrapper = observer(function MainPageLayoutWrap({ chil
2424
});
2525
}, [location.pathname]);
2626

27-
return (
27+
const isClassPage = useMemo((): boolean => {
28+
return [
29+
routeConfig.BigClassPage,
30+
routeConfig.SmallClassPage,
31+
routeConfig.OneToOnePage,
32+
].some(({ path }) => {
33+
return !!matchPath(location.pathname, {
34+
path,
35+
sensitive: true,
36+
});
37+
});
38+
}, [location.pathname]);
39+
40+
return isClassPage ? (
41+
<>{children}</>
42+
) : (
2843
<MainPageLayoutContainer
2944
MainPageHeaderTitle={pageStore.title}
3045
activeKeys={pageStore.activeKeys}

desktop/renderer-app/src/pages/CloudStoragePage/index.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import "./style.less";
33
import { CloudStorageContainer } from "flat-components";
44
import { observer } from "mobx-react-lite";
55
import React, { useEffect, useState } from "react";
6-
import { MainPageLayoutContainer } from "../../components/MainPageLayoutContainer";
76
import { CloudStorageStore } from "./store";
87
import { loginCheck } from "../../api-middleware/flatServer";
98
import { ServerRequestError } from "../../utils/error/server-request-error";
@@ -42,9 +41,5 @@ export const CloudStoragePage = observer<CloudStoragePageProps>(function CloudSt
4241

4342
useEffect(() => store.initialize(), [store]);
4443

45-
return (
46-
<MainPageLayoutContainer>
47-
<CloudStorageContainer store={store} />
48-
</MainPageLayoutContainer>
49-
);
44+
return <CloudStorageContainer store={store} />;
5045
});

desktop/renderer-app/src/pages/DeviceCheckPages/DeviceCheckLayoutContainer.tsx

+37-42
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import speakerSVG from "./icons/speaker.svg";
55
import microphoneSVG from "./icons/microphone.svg";
66
import "./DeviceCheckLayoutContainer.less";
77

8-
import React from "react";
9-
import { MainPageLayoutContainer } from "../../components/MainPageLayoutContainer";
10-
import { useWindowSize } from "../../utils/hooks/use-window-size";
8+
import React, { useContext, useEffect } from "react";
119
import { routeConfig, RouteNameType } from "../../route-config";
1210
import { useHistory, useLocation } from "react-router-dom";
1311
import { DeviceCheckState } from "./utils";
@@ -20,50 +18,47 @@ export const DeviceCheckLayoutContainer: React.FC = ({ children }): React.ReactE
2018
const t = useTranslate();
2119
const history = useHistory<DeviceCheckState>();
2220
const location = useLocation<DeviceCheckState | undefined>();
21+
const pageStore = useContext(PageStoreContext);
2322

24-
const subMenu = [
25-
{
26-
key: routeConfig[RouteNameType.SystemCheckPage].path,
27-
icon: (): React.ReactNode => <img src={systemSVG} />,
28-
title: t("system-testing"),
29-
route: routeConfig[RouteNameType.SystemCheckPage].path,
30-
},
31-
{
32-
key: routeConfig[RouteNameType.CameraCheckPage].path,
33-
icon: (): React.ReactNode => <img src={cameraSVG} />,
34-
title: t("camera-testing"),
35-
route: routeConfig[RouteNameType.CameraCheckPage].path,
36-
},
37-
{
38-
key: routeConfig[RouteNameType.SpeakerCheckPage].path,
39-
icon: (): React.ReactNode => <img src={speakerSVG} />,
40-
title: t("headphone-testing"),
41-
route: routeConfig[RouteNameType.SpeakerCheckPage].path,
42-
},
43-
{
44-
key: routeConfig[RouteNameType.MicrophoneCheckPage].path,
45-
icon: (): React.ReactNode => <img src={microphoneSVG} />,
46-
title: t("microphone-testing"),
47-
route: routeConfig[RouteNameType.MicrophoneCheckPage].path,
48-
},
49-
];
50-
51-
const activeKeys = ["deviceCheck", location.pathname];
52-
53-
return (
54-
<MainPageLayoutContainer
55-
activeKeys={activeKeys}
56-
subMenu={subMenu}
57-
onRouteChange={(mainPageLayoutItem: MainPageLayoutItem) => {
23+
useEffect(() => {
24+
pageStore.configure({
25+
subMenu: [
26+
{
27+
key: routeConfig[RouteNameType.SystemCheckPage].path,
28+
icon: (): React.ReactNode => <img src={systemSVG} />,
29+
title: t("system-testing"),
30+
route: routeConfig[RouteNameType.SystemCheckPage].path,
31+
},
32+
{
33+
key: routeConfig[RouteNameType.CameraCheckPage].path,
34+
icon: (): React.ReactNode => <img src={cameraSVG} />,
35+
title: t("camera-testing"),
36+
route: routeConfig[RouteNameType.CameraCheckPage].path,
37+
},
38+
{
39+
key: routeConfig[RouteNameType.SpeakerCheckPage].path,
40+
icon: (): React.ReactNode => <img src={speakerSVG} />,
41+
title: t("headphone-testing"),
42+
route: routeConfig[RouteNameType.SpeakerCheckPage].path,
43+
},
44+
{
45+
key: routeConfig[RouteNameType.MicrophoneCheckPage].path,
46+
icon: (): React.ReactNode => <img src={microphoneSVG} />,
47+
title: t("microphone-testing"),
48+
route: routeConfig[RouteNameType.MicrophoneCheckPage].path,
49+
},
50+
],
51+
activeKeys: ["deviceCheck", location.pathname],
52+
onRouteChange(mainPageLayoutItem: MainPageLayoutItem) {
5853
history.push({
5954
pathname: mainPageLayoutItem.route,
6055
state: {
6156
...location.state,
6257
},
6358
});
64-
}}
65-
>
66-
<div className="device-check-layout-container">{children}</div>
67-
</MainPageLayoutContainer>
68-
);
59+
},
60+
});
61+
}, [history, location.pathname, location.state, pageStore, t]);
62+
63+
return <div className="device-check-layout-container">{children}</div>;
6964
};

packages/flat-pages/src/DevicesTestPage/style.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.device-test-page-container {
2-
height: 100vh;
2+
height: 100%;
33
display: flex;
44
align-items: center;
55
justify-content: center;

packages/flat-pages/src/utils/join-room-handler.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateRoutePath, RouteNameType, usePushHistory } from "../utils/routes";
1+
import { RouteNameType, usePushHistory } from "../utils/routes";
22
import { roomStore, globalStore } from "@netless/flat-stores";
33
import { RoomType } from "@netless/flat-server-api";
44
import { errorTips } from "flat-components";
@@ -14,22 +14,18 @@ export const joinRoomHandler = async (
1414
const data = await roomStore.joinRoom(periodicUUID || formatRoomUUID);
1515
globalStore.updateShowGuide(data.showGuide);
1616
globalStore.updatePeriodicUUID(roomInfo?.periodicUUID);
17-
// try to work around chrome does not show permission popup after
18-
// soft navigating. here we do a "hard" navigating instead.
17+
1918
switch (data.roomType) {
2019
case RoomType.BigClass: {
21-
// pushHistory(RouteNameType.BigClassPage, data);
22-
window.location.href = generateRoutePath(RouteNameType.BigClassPage, data);
20+
pushHistory(RouteNameType.BigClassPage, data);
2321
break;
2422
}
2523
case RoomType.SmallClass: {
26-
// pushHistory(RouteNameType.SmallClassPage, data);
27-
window.location.href = generateRoutePath(RouteNameType.SmallClassPage, data);
24+
pushHistory(RouteNameType.SmallClassPage, data);
2825
break;
2926
}
3027
case RoomType.OneToOne: {
31-
// pushHistory(RouteNameType.OneToOnePage, data);
32-
window.location.href = generateRoutePath(RouteNameType.OneToOnePage, data);
28+
pushHistory(RouteNameType.OneToOnePage, data);
3329
break;
3430
}
3531
default: {

0 commit comments

Comments
 (0)