mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 02:48:01 +03:00
Try out history safe-go-back
This commit is contained in:
@@ -2,6 +2,7 @@ import useSetSubheader from "components/layout/header/useSetSubheader";
|
||||
import React from "react";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { ToCDNURL } from "util/api";
|
||||
import { HistorySafeGoBack } from "util/misc";
|
||||
|
||||
export function ErrorPage({
|
||||
statusCode,
|
||||
@@ -72,12 +73,7 @@ export function ErrorPage({
|
||||
{statusCode || "Completely Screwed."}
|
||||
</h1>
|
||||
<p className="font-size-h3 font-weight-light">{message}</p>
|
||||
<a
|
||||
className="text-primary"
|
||||
onClick={() =>
|
||||
history.length === 1 ? history.replace("/") : history.goBack()
|
||||
}
|
||||
>
|
||||
<a className="text-primary" onClick={() => HistorySafeGoBack(history)}>
|
||||
Go Back.
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import React, { useState } from "react";
|
||||
import { Link, useHistory } from "react-router-dom";
|
||||
import { APIFetchV1 } from "util/api";
|
||||
import MainPageTitleContainer from "components/util/MainPageTitleContainer";
|
||||
import { HistorySafeGoBack } from "util/misc";
|
||||
|
||||
export default function ForgotPasswordPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
@@ -59,7 +60,7 @@ export default function ForgotPasswordPage() {
|
||||
</Form.Group>
|
||||
<Form.Group className="justify-content-center d-flex pt-4">
|
||||
<span
|
||||
onClick={() => history.goBack()}
|
||||
onClick={() => HistorySafeGoBack(history)}
|
||||
tabIndex={4}
|
||||
className="mr-auto btn btn-outline-danger"
|
||||
>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Link, useHistory } from "react-router-dom";
|
||||
import { PublicUserDocument } from "tachi-common";
|
||||
import { APIFetchV1 } from "util/api";
|
||||
import { HumaniseError } from "util/humanise-error";
|
||||
import { HistorySafeGoBack } from "util/misc";
|
||||
|
||||
export default function LoginPage() {
|
||||
useSetSubheader("Login");
|
||||
@@ -59,7 +60,7 @@ export default function LoginPage() {
|
||||
setUser(userRJ.body);
|
||||
localStorage.setItem("isLoggedIn", "true");
|
||||
|
||||
history.goBack();
|
||||
HistorySafeGoBack(history);
|
||||
}, 500);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import { PublicUserDocument } from "tachi-common";
|
||||
import { UseFormik } from "types/react";
|
||||
import { APIFetchV1, ToCDNURL } from "util/api";
|
||||
import { HumaniseError } from "util/humanise-error";
|
||||
import { HistorySafeGoBack } from "util/misc";
|
||||
|
||||
// seconds it takes for a user to actually read the rules.
|
||||
const RULES_READ_TIME = Number(process.env.REACT_APP_RULES_READ_TIME) || 30;
|
||||
@@ -78,7 +79,7 @@ export default function RegisterPage() {
|
||||
setUser(rj.body);
|
||||
localStorage.setItem("isLoggedIn", "true");
|
||||
|
||||
history.goBack();
|
||||
HistorySafeGoBack(history);
|
||||
}, 500);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import { UserContext } from "context/UserContext";
|
||||
import { ClientConfig } from "lib/config";
|
||||
import React, { useContext } from "react";
|
||||
import { Redirect, Route, Switch, useHistory } from "react-router-dom";
|
||||
import { HistorySafeGoBack } from "util/misc";
|
||||
import ClientFileFlowRoutes from "./ClientFileFlowRoutes";
|
||||
import DashboardRoutes from "./DashboardRoutes";
|
||||
import OAuth2CallbackRoutes from "./OAuth2CallbackRoutes";
|
||||
@@ -76,7 +77,7 @@ export function Routes() {
|
||||
desc="If you signed up with a fake email, you're now locked out of this account. Nice one."
|
||||
/>
|
||||
<span
|
||||
onClick={() => history.goBack()}
|
||||
onClick={() => HistorySafeGoBack(history)}
|
||||
tabIndex={4}
|
||||
className="btn btn-outline-danger"
|
||||
>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import toast from "react-hot-toast";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import {
|
||||
APIPermissions,
|
||||
ChartDocument,
|
||||
@@ -188,3 +189,11 @@ export function WrapError<T>(fn: () => T, errMsg: string) {
|
||||
export function Sleep(ms: number) {
|
||||
return new Promise<void>(resolve => setTimeout(() => resolve(), ms));
|
||||
}
|
||||
|
||||
export function HistorySafeGoBack(history: ReturnType<typeof useHistory>) {
|
||||
if (history.length === 1) {
|
||||
history.replace("/");
|
||||
} else {
|
||||
history.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user