From 0f3e01a92240bf2410739d635f2562f38d9e7c6a Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Mon, 5 Dec 2022 19:31:55 +0800 Subject: [PATCH] feat: user search --- src/common/component/User/index.tsx | 4 ++-- src/common/component/User/styled.tsx | 3 +++ .../component => routes/users}/Search.tsx | 23 +++++++++++-------- src/routes/users/index.tsx | 15 ++++++------ 4 files changed, 25 insertions(+), 20 deletions(-) rename src/{common/component => routes/users}/Search.tsx (65%) diff --git a/src/common/component/User/index.tsx b/src/common/component/User/index.tsx index 2ccc6897..e3c23d54 100644 --- a/src/common/component/User/index.tsx +++ b/src/common/component/User/index.tsx @@ -61,7 +61,7 @@ const User: FC = ({
- {!compact && {curr?.name}} + {!compact && {curr?.name}} {owner && } @@ -91,7 +91,7 @@ const User: FC = ({
- {!compact && {curr?.name}} + {!compact && {curr?.name}} {owner && } diff --git a/src/common/component/User/styled.tsx b/src/common/component/User/styled.tsx index 2118a9ab..3fa76f7c 100644 --- a/src/common/component/User/styled.tsx +++ b/src/common/component/User/styled.tsx @@ -50,6 +50,9 @@ const StyledWrapper = styled.div` font-size: 14px; line-height: 20px; color: #52525b; + max-width: 190px; + overflow: hidden; + text-overflow: ellipsis; } /* session nav */ &.compact { diff --git a/src/common/component/Search.tsx b/src/routes/users/Search.tsx similarity index 65% rename from src/common/component/Search.tsx rename to src/routes/users/Search.tsx index 349a696c..b0c46b48 100644 --- a/src/common/component/Search.tsx +++ b/src/routes/users/Search.tsx @@ -2,9 +2,9 @@ import styled from "styled-components"; import Tippy from "@tippyjs/react"; import searchIcon from "../../assets/icons/search.svg?url"; import addIcon from "../../assets/icons/add.svg?url"; -import AddEntriesMenu from "./AddEntriesMenu"; -import Tooltip from "./Tooltip"; -import { FC } from "react"; +import AddEntriesMenu from "../../common/component/AddEntriesMenu"; +import Tooltip from "../../common/component/Tooltip"; +import { FC, ChangeEvent } from "react"; import { useTranslation } from "react-i18next"; const StyledWrapper = styled.div` @@ -30,22 +30,25 @@ const StyledWrapper = styled.div` line-height: 20px; } } - .add { - cursor: pointer; - } `; -type Props = {}; -const Search: FC = () => { +type Props = { + input: string, + updateInput: (input: string) => void +}; +const Search: FC = ({ input, updateInput }) => { const { t } = useTranslation(); + const handleInput = (evt: ChangeEvent) => { + updateInput(evt.target.value); + }; return (
search icon - +
}> - add icon + add icon
diff --git a/src/routes/users/index.tsx b/src/routes/users/index.tsx index 9a44f360..a6d01f02 100644 --- a/src/routes/users/index.tsx +++ b/src/routes/users/index.tsx @@ -1,22 +1,21 @@ import { memo, useEffect } from "react"; import { NavLink, useParams, useLocation } from "react-router-dom"; import { useDispatch } from "react-redux"; -import _ from "lodash"; import { updateRememberedNavs } from "../../app/slices/ui"; -import Search from "../../common/component/Search"; +import Search from "./Search"; import User from "../../common/component/User"; import Profile from "../../common/component/Profile"; import StyledWrapper from "./styled"; import BlankPlaceholder from "../../common/component/BlankPlaceholder"; -import { useAppSelector } from "../../app/store"; +import useFilteredUsers from "../../common/hook/useFilteredUsers"; function UsersPage() { const dispatch = useDispatch(); const { pathname } = useLocation(); - + const { input, updateInput, users } = useFilteredUsers(); const { user_id } = useParams(); - const userIds = useAppSelector((store) => store.users.ids, _.isEqual); + // 记住路由 useEffect(() => { dispatch(updateRememberedNavs({ key: "user" })); return () => { @@ -24,14 +23,14 @@ function UsersPage() { }; }, [pathname]); - if (!userIds) return null; + if (!users) return null; return (
- +