You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/Sidebar.tsx

78 lines
2.5 KiB
TypeScript

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

import { userService } from "../services";
import { useAppSelector } from "../store";
import Only from "./common/OnlyWhen";
import showDailyReviewDialog from "./DailyReviewDialog";
import showSettingDialog from "./SettingDialog";
import showArchivedMemoDialog from "./ArchivedMemoDialog";
import UserBanner from "./UserBanner";
import UsageHeatMap from "./UsageHeatMap";
import ShortcutList from "./ShortcutList";
import TagList from "./TagList";
import "../less/siderbar.less";
interface Props {}
const Sidebar: React.FC<Props> = () => {
const user = useAppSelector((state) => state.user.user);
const handleMyAccountBtnClick = () => {
showSettingDialog();
};
const handleArchivedBtnClick = () => {
showArchivedMemoDialog();
};
return (
<aside className="sidebar-wrapper">
<div className="close-container">
<span className="action-btn" onClick={toggleSiderbar}>
<i className="fa-solid fa-xmark icon-img"></i>
</span>
</div>
<UserBanner />
<UsageHeatMap />
<div className="action-btns-container">
<button className="btn action-btn" onClick={() => showDailyReviewDialog()}>
<span className="icon">📅</span> Daily Review
</button>
<Only when={!userService.isVisitorMode()}>
<button className="btn action-btn" onClick={handleMyAccountBtnClick}>
<span className="icon"></span> Setting
</button>
</Only>
<button className="btn action-btn" onClick={handleArchivedBtnClick}>
<span className="icon">🗂</span> Archived
</button>
<Only when={userService.isVisitorMode()}>
{user ? (
<button className="btn action-btn" onClick={() => (window.location.href = "/")}>
<span className="icon">🏠</span> Back to Home
</button>
) : (
<button className="btn action-btn" onClick={() => (window.location.href = "/signin")}>
<span className="icon">👉</span> Sign in
</button>
)}
</Only>
</div>
<Only when={!userService.isVisitorMode()}>
<ShortcutList />
</Only>
<TagList />
</aside>
);
};
export const toggleSiderbar = () => {
const sidebarEl = document.body.querySelector(".sidebar-wrapper") as HTMLDivElement;
const display = window.getComputedStyle(sidebarEl).display;
if (display === "none") {
sidebarEl.style.display = "flex";
} else {
sidebarEl.style.display = "none";
}
};
export default Sidebar;