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

refactor(project): show refresh button on network error #1266

Merged
merged 1 commit into from
Jan 5, 2022
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
2 changes: 1 addition & 1 deletion desktop/renderer-app/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()

return (
<div className="realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()

return (
<div className="one-to-one-realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="one-to-one-realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP

return (
<div className="realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
1 change: 1 addition & 0 deletions desktop/renderer-app/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export class WhiteboardStore {
}
},
onDisconnectWithError: error => {
void message.error(this.i18n.t("on-disconnect-with-error"));
this.preloadPPTResource.cancel();
console.error(error);
},
Expand Down
39 changes: 31 additions & 8 deletions packages/flat-components/src/components/LoadingPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import "./style.less";
import loadingGIF from "./icons/loading.gif";

import React, { FC, useEffect, useState } from "react";
import { Button } from "antd";
import React, { FC, useCallback, useEffect, useState } from "react";
import classNames from "classnames";
import { Link } from "react-router-dom";
import { Button } from "antd";
import { useTranslation } from "react-i18next";

export interface LoadingPageProps {
text?: string;
timeMS?: number;
hasHeader?: boolean;
onTimeout?: "return-home" | "full-reload" | (() => void);
onTimeoutText?: string;
}

export const LoadingPage: FC<LoadingPageProps> = ({ text, timeMS = 20 * 1000, hasHeader }) => {
export const LoadingPage: FC<LoadingPageProps> = ({
text,
timeMS = 20 * 1000,
hasHeader,
onTimeout = "return-home",
onTimeoutText,
}) => {
const [isShowReturnHomePage, showReturnHomePage] = useState(false);
const { t } = useTranslation();

Expand All @@ -23,6 +30,21 @@ export const LoadingPage: FC<LoadingPageProps> = ({ text, timeMS = 20 * 1000, ha
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const timeoutText =
onTimeoutText || (typeof onTimeout === "string" ? t(onTimeout) : t("return-home"));

const timeoutBehavior = useCallback(
(type: "return-home" | "full-reload") => () => {
if (type === "return-home") {
window.location.pathname = "/";
}
if (type === "full-reload") {
window.location.reload();
}
},
[],
);

return (
<div className="loading-page">
<div
Expand All @@ -34,14 +56,15 @@ export const LoadingPage: FC<LoadingPageProps> = ({ text, timeMS = 20 * 1000, ha
<img className="loading-page-image" src={loadingGIF} alt="loading" />
{text && <span>{text}</span>}
</div>
<Link
to="/"
<Button
size="large"
className={classNames("loading-page-return-btn", {
"is-show": isShowReturnHomePage,
})}
onClick={typeof onTimeout === "string" ? timeoutBehavior(onTimeout) : onTimeout}
>
<Button size="large">{t("return-home")}</Button>
</Link>
{timeoutText}
</Button>
</div>
);
};
2 changes: 2 additions & 0 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"time": "by room end date"
},
"return-home": "Return Home",
"full-reload": "Refresh",
"on-disconnect-with-error": "The network is not available",
"error-page-description": "Please try again",
"error-page-title": "Sorry, we have an unknown error",
"error-page-return-home": "({{countdown}}) Go Back",
Expand Down
2 changes: 2 additions & 0 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"SmallClass": "最多 16 位学生"
},
"return-home": "返回首页",
"full-reload": "刷新",
"on-disconnect-with-error": "当前网络不可用",
"error-page-title": "抱歉,遇到未知错误",
"error-page-description": "请重试",
"error-page-return-home": "({{countdown}}) 返回首页",
Expand Down
2 changes: 1 addition & 1 deletion web/flat-web/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()

return (
<div className="realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
2 changes: 1 addition & 1 deletion web/flat-web/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()

return (
<div className="one-to-one-realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="one-to-one-realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
2 changes: 1 addition & 1 deletion web/flat-web/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP

return (
<div className="realtime-container">
{loadingPageRef.current && <LoadingPage />}
{loadingPageRef.current && <LoadingPage onTimeout="full-reload" />}
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
Expand Down
1 change: 1 addition & 0 deletions web/flat-web/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export class WhiteboardStore {
}
},
onDisconnectWithError: error => {
void message.error(this.i18n.t("on-disconnect-with-error"));
console.error(error);
this.preloadPPTResource.cancel();
},
Expand Down