diff --git a/src/hook/useUrlQueryParams.ts b/src/hook/useUrlQueryParams.ts new file mode 100644 index 0000000..402538f --- /dev/null +++ b/src/hook/useUrlQueryParams.ts @@ -0,0 +1,26 @@ +import { useMemo } from "react"; +import { URLSearchParamsInit, useSearchParams } from "react-router-dom"; +import { cleanObject } from "../utils"; + +const useUrlQueryParams = (keys: K[]) => { + const [searchParams, setSearchParams] = useSearchParams(); + return [ + useMemo( + () => + keys.reduce( + (prev, key) => ({ + ...prev, + [key]: searchParams.get(key) || "", + }), + {} as { [key in K]: string } + ), + [searchParams] + ), + (params: Partial<{ [key in K]: unknown }>) => { + const newParams = cleanObject({ ...Object.fromEntries(searchParams), ...params }) as URLSearchParamsInit + setSearchParams(newParams) + }, + ] as const; +}; + +export default useUrlQueryParams; diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 73b0c50..56542f6 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -1,12 +1,13 @@ import React from "react"; import { Dropdown, Menu, Button } from "antd"; import { Navigate, Route, Routes } from "react-router"; -import { BrowserRouter } from 'react-router-dom' +import { BrowserRouter } from "react-router-dom"; import ProjectList from "../ProjectList"; import Project from "../Project"; import { useAuth } from "../../context/auth-context"; import { ReactComponent as SoftwareLogo } from "../../assets/software-logo.svg"; import { Main, Container, Header, HeaderLeft, HeaderRight } from "./style"; +import { resetRoute } from "../../utils"; const Home = () => { return ( @@ -17,6 +18,7 @@ const Home = () => { } /> } /> + } /> @@ -29,7 +31,9 @@ const PageHeader = () => { return (
- +

项目

用户

diff --git a/src/pages/Project/Kanban/index.tsx b/src/pages/Project/Kanban/index.tsx new file mode 100644 index 0000000..1055c62 --- /dev/null +++ b/src/pages/Project/Kanban/index.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const Kanban = () => { + return
Kanban
; +}; + +export default Kanban; diff --git a/src/pages/Project/Task/index.tsx b/src/pages/Project/Task/index.tsx new file mode 100644 index 0000000..ffb8838 --- /dev/null +++ b/src/pages/Project/Task/index.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const Task = () => { + return
Task
; +}; + +export default Task; diff --git a/src/pages/Project/index.tsx b/src/pages/Project/index.tsx index 5c86070..8037864 100644 --- a/src/pages/Project/index.tsx +++ b/src/pages/Project/index.tsx @@ -1,7 +1,25 @@ -import React from 'react' +import React from "react"; +import { Routes, Route, Navigate } from "react-router"; +import { Link } from "react-router-dom"; +import Kanban from "./Kanban"; +import Task from "./Task"; const Project = () => { - return
Project
-} + return ( +
+

Project

+ 看板 + 任务组 + + } /> + } /> + } + /> + +
+ ); +}; -export default Project \ No newline at end of file +export default Project; diff --git a/src/pages/ProjectList/Search/index.tsx b/src/pages/ProjectList/Search/index.tsx index 746ba62..17e1f10 100644 --- a/src/pages/ProjectList/Search/index.tsx +++ b/src/pages/ProjectList/Search/index.tsx @@ -39,7 +39,7 @@ const Search = ({ param, setParam, users }: SearchPanelProps) => { > {users.map((user) => ( - ))} diff --git a/src/pages/ProjectList/index.tsx b/src/pages/ProjectList/index.tsx index 0686427..340b779 100644 --- a/src/pages/ProjectList/index.tsx +++ b/src/pages/ProjectList/index.tsx @@ -7,6 +7,7 @@ import { Container } from "./style"; import useProjects from "../../hook/useProjects"; import useUsers from "../../hook/useUsers"; import useDocumentTitle from "../../hook/useDocumentTitle"; +import useUrlQueryParams from "../../hook/useUrlQueryParams"; interface Project { id: string; @@ -18,7 +19,7 @@ interface Project { } const ProjectList = () => { - const [param, setParam] = useState({ name: "", personId: "" }); + const [param, setParam] = useUrlQueryParams(["name", "personId"]); const debounceParams = useDebounce(param, 200); const { isLoading, error, data: list } = useProjects(debounceParams); const { data: users } = useUsers(); diff --git a/src/utils/index.ts b/src/utils/index.ts index 8e5630a..2892c06 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,6 @@ export const isFalsy = (value: unknown) => (value === 0 ? false : !value); -export const isVoid = (value: unknown) => value === undefined || value === null || value === ''; +export const isVoid = (value: unknown) => value === undefined || value === null || value === ""; // 筛选对象空值 export const cleanObject = (object: { [key: string]: unknown }) => { @@ -12,4 +12,6 @@ export const cleanObject = (object: { [key: string]: unknown }) => { }); return result; -}; \ No newline at end of file +}; + +export const resetRoute = () => (window.location.href = window.location.origin);