chore: add useNavigateTo hook

This commit is contained in:
steven
2023-09-24 21:21:34 +08:00
parent f78b072bb8
commit 159dfc9446
9 changed files with 47 additions and 45 deletions

View File

@ -69,7 +69,7 @@ const Home: React.FC = () => {
</div>
<FilterView />
{loadingState.isLoading ? (
<div className="py-12 w-full flex flex-row justify-center items-center opacity-80">
<div className="py-12 w-full flex flex-row justify-center items-center opacity-80 dark:text-gray-500">
<Icon.Loader className="mr-2 w-5 h-auto animate-spin" />
loading
</div>

View File

@ -4,7 +4,8 @@ import copy from "copy-to-clipboard";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { useLoaderData, useNavigate } from "react-router-dom";
import { useLoaderData } from "react-router-dom";
import useNavigateTo from "@/hooks/useNavigateTo";
import { showCommonDialog } from "../components/Alert";
import AnalyticsView from "../components/AnalyticsView";
import CreateShortcutDialog from "../components/CreateShortcutDialog";
@ -23,7 +24,7 @@ interface State {
const ShortcutDetail = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const navigateTo = useNavigateTo();
const shortcutId = (useLoaderData() as Shortcut).id;
const shortcut = shortcutService.getShortcutById(shortcutId) as Shortcut;
const currentUser = useUserStore().getCurrentUser();
@ -56,7 +57,7 @@ const ShortcutDetail = () => {
style: "danger",
onConfirm: async () => {
await shortcutService.deleteShortcutById(shortcut.id);
navigate("/", {
navigateTo("/", {
replace: true,
});
},

View File

@ -2,7 +2,8 @@ import { Button, Input } from "@mui/joy";
import React, { FormEvent, useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { Link, useNavigate } from "react-router-dom";
import { Link } from "react-router-dom";
import useNavigateTo from "@/hooks/useNavigateTo";
import useWorkspaceStore from "@/stores/v1/workspace";
import * as api from "../helpers/api";
import useLoading from "../hooks/useLoading";
@ -10,7 +11,7 @@ import useUserStore from "../stores/v1/user";
const SignIn: React.FC = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const navigateTo = useNavigateTo();
const userStore = useUserStore();
const workspaceStore = useWorkspaceStore();
const [email, setEmail] = useState("");
@ -20,7 +21,7 @@ const SignIn: React.FC = () => {
useEffect(() => {
if (userStore.getCurrentUser()) {
return navigate("/", {
return navigateTo("/", {
replace: true,
});
}
@ -52,7 +53,7 @@ const SignIn: React.FC = () => {
await api.signin(email, password);
const user = await userStore.fetchCurrentUser();
if (user) {
navigate("/", {
navigateTo("/", {
replace: true,
});
} else {

View File

@ -2,7 +2,8 @@ import { Button, Input } from "@mui/joy";
import React, { FormEvent, useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { Link, useNavigate } from "react-router-dom";
import { Link } from "react-router-dom";
import useNavigateTo from "@/hooks/useNavigateTo";
import useWorkspaceStore from "@/stores/v1/workspace";
import * as api from "../helpers/api";
import useLoading from "../hooks/useLoading";
@ -10,7 +11,7 @@ import useUserStore from "../stores/v1/user";
const SignUp: React.FC = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const navigateTo = useNavigateTo();
const userStore = useUserStore();
const workspaceStore = useWorkspaceStore();
const [email, setEmail] = useState("");
@ -21,13 +22,13 @@ const SignUp: React.FC = () => {
useEffect(() => {
if (userStore.getCurrentUser()) {
return navigate("/", {
return navigateTo("/", {
replace: true,
});
}
if (!workspaceStore.setting.enableSignup) {
return navigate("/auth", {
return navigateTo("/auth", {
replace: true,
});
}
@ -59,7 +60,7 @@ const SignUp: React.FC = () => {
await api.signup(email, nickname, password);
const user = await userStore.fetchCurrentUser();
if (user) {
navigate("/", {
navigateTo("/", {
replace: true,
});
} else {