mirror of https://github.com/usememos/memos
chore: add explore sidebar
parent
192ee7acc0
commit
90679cc33a
@ -0,0 +1,23 @@
|
||||
import classNames from "classnames";
|
||||
import SearchBar from "@/components/SearchBar";
|
||||
import UserList from "../UserList";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const ExploreSidebar = (props: Props) => {
|
||||
return (
|
||||
<aside
|
||||
className={classNames(
|
||||
"relative w-full h-auto max-h-screen overflow-auto hide-scrollbar flex flex-col justify-start items-start",
|
||||
props.className,
|
||||
)}
|
||||
>
|
||||
<SearchBar />
|
||||
<UserList />
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExploreSidebar;
|
@ -0,0 +1,37 @@
|
||||
import { Drawer, IconButton } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import Icon from "../Icon";
|
||||
import ExploreSidebar from "./ExploreSidebar";
|
||||
|
||||
const ExploreSidebarDrawer = () => {
|
||||
const location = useLocation();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(false);
|
||||
}, [location.pathname]);
|
||||
|
||||
const toggleDrawer = (inOpen: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => {
|
||||
if (event.type === "keydown" && ((event as React.KeyboardEvent).key === "Tab" || (event as React.KeyboardEvent).key === "Shift")) {
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(inOpen);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton onClick={toggleDrawer(true)}>
|
||||
<Icon.Search className="w-5 h-auto dark:text-gray-400" />
|
||||
</IconButton>
|
||||
<Drawer anchor="right" size="sm" open={open} onClose={toggleDrawer(false)}>
|
||||
<div className="w-full h-full px-5 bg-zinc-100 dark:bg-zinc-900">
|
||||
<ExploreSidebar className="py-4" />
|
||||
</div>
|
||||
</Drawer>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExploreSidebarDrawer;
|
@ -0,0 +1,4 @@
|
||||
import ExploreSidebar from "./ExploreSidebar";
|
||||
import ExploreSidebarDrawer from "./ExploreSidebarDrawer";
|
||||
|
||||
export { ExploreSidebar, ExploreSidebarDrawer };
|
@ -1,8 +1,8 @@
|
||||
import classNames from "classnames";
|
||||
import PersonalStatistics from "@/components/PersonalStatistics";
|
||||
import SearchBar from "@/components/SearchBar";
|
||||
import TagList from "@/components/TagList";
|
||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||
import PersonalStatistics from "./PersonalStatistics";
|
||||
import SearchBar from "./SearchBar";
|
||||
import TagList from "./TagList";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
@ -1,8 +1,8 @@
|
||||
import { Drawer, IconButton } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import Icon from "../Icon";
|
||||
import HomeSidebar from "./HomeSidebar";
|
||||
import Icon from "./Icon";
|
||||
|
||||
const HomeSidebarDrawer = () => {
|
||||
const location = useLocation();
|
@ -0,0 +1,4 @@
|
||||
import HomeSidebar from "./HomeSidebar";
|
||||
import HomeSidebarDrawer from "./HomeSidebarDrawer";
|
||||
|
||||
export { HomeSidebar, HomeSidebarDrawer };
|
@ -0,0 +1,47 @@
|
||||
import { IconButton } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useUserStore } from "@/store/v1";
|
||||
import { User } from "@/types/proto/api/v2/user_service";
|
||||
import Icon from "./Icon";
|
||||
import UserAvatar from "./UserAvatar";
|
||||
|
||||
const UserList = () => {
|
||||
const userStore = useUserStore();
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
|
||||
const fetchRecommendUsers = async () => {
|
||||
const users = await userStore.searchUsers(`random == true && limit == 5`);
|
||||
setUsers(users);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchRecommendUsers();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="w-full mt-2 flex flex-col p-2 bg-gray-50 dark:bg-black rounded-lg">
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<span className="text-gray-400 font-medium text-sm pl-1">Users</span>
|
||||
<IconButton size="sm" onClick={fetchRecommendUsers}>
|
||||
<Icon.RefreshCcw className="text-gray-400 w-4 h-auto" />
|
||||
</IconButton>
|
||||
</div>
|
||||
{users.map((user) => (
|
||||
<div
|
||||
key={user.name}
|
||||
className="w-full flex flex-row justify-start items-center px-2 py-1.5 hover:bg-gray-100 dark:hover:bg-zinc-900 rounded-lg"
|
||||
>
|
||||
<Link className="w-full flex flex-row items-center" to={`/u/${encodeURIComponent(user.username)}`} unstable_viewTransition>
|
||||
<UserAvatar className="mr-2 shrink-0" avatarUrl={user.avatarUrl} />
|
||||
<div className="w-full flex flex-col justify-center items-start">
|
||||
<span className="text-gray-600 leading-tight max-w-[80%] truncate dark:text-gray-400">{user.nickname || user.username}</span>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserList;
|
Loading…
Reference in New Issue