2022-05-21 12:21:06 +08:00
|
|
|
import { useEffect } from "react";
|
2022-09-19 22:27:50 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-09-21 21:30:33 +08:00
|
|
|
import { useLocation } from "react-router-dom";
|
2022-09-19 21:53:27 +08:00
|
|
|
import { globalService, userService } from "../services";
|
2022-07-19 21:46:38 +08:00
|
|
|
import { useAppSelector } from "../store";
|
2022-09-19 21:53:27 +08:00
|
|
|
import toastHelper from "../components/Toast";
|
2022-07-07 23:11:20 +08:00
|
|
|
import Sidebar from "../components/Sidebar";
|
2022-05-28 07:38:06 +08:00
|
|
|
import MemosHeader from "../components/MemosHeader";
|
|
|
|
import MemoEditor from "../components/MemoEditor";
|
|
|
|
import MemoFilter from "../components/MemoFilter";
|
|
|
|
import MemoList from "../components/MemoList";
|
2021-12-08 23:43:52 +08:00
|
|
|
import "../less/home.less";
|
|
|
|
|
|
|
|
function Home() {
|
2022-09-19 22:27:50 +08:00
|
|
|
const { t } = useTranslation();
|
2022-09-19 21:53:27 +08:00
|
|
|
const location = useLocation();
|
2022-07-25 21:50:25 +08:00
|
|
|
const user = useAppSelector((state) => state.user.user);
|
2021-12-08 23:43:52 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-09-21 21:30:33 +08:00
|
|
|
const { owner } = userService.getState();
|
2022-09-19 21:53:27 +08:00
|
|
|
|
|
|
|
if (userService.isVisitorMode()) {
|
|
|
|
if (!owner) {
|
|
|
|
toastHelper.error(t("message.user-not-found"));
|
|
|
|
}
|
|
|
|
}
|
2022-07-19 21:46:38 +08:00
|
|
|
}, [location]);
|
2021-12-08 23:43:52 +08:00
|
|
|
|
2022-09-19 21:53:27 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (user?.setting.locale) {
|
|
|
|
globalService.setLocale(user.setting.locale);
|
|
|
|
}
|
|
|
|
}, [user?.setting.locale]);
|
|
|
|
|
2021-12-08 23:43:52 +08:00
|
|
|
return (
|
2022-06-19 11:32:49 +08:00
|
|
|
<section className="page-wrapper home">
|
2022-09-19 21:53:27 +08:00
|
|
|
<div className="page-container">
|
|
|
|
<Sidebar />
|
|
|
|
<main className="memos-wrapper">
|
|
|
|
<div className="memos-editor-wrapper">
|
|
|
|
<MemosHeader />
|
2022-09-20 23:30:25 +08:00
|
|
|
{!userService.isVisitorMode() && <MemoEditor />}
|
2022-09-19 21:53:27 +08:00
|
|
|
<MemoFilter />
|
|
|
|
</div>
|
|
|
|
<MemoList />
|
2022-09-20 23:30:25 +08:00
|
|
|
{userService.isVisitorMode() && (
|
2022-09-19 21:53:27 +08:00
|
|
|
<div className="addtion-btn-container">
|
|
|
|
{user ? (
|
|
|
|
<button className="btn" onClick={() => (window.location.href = "/")}>
|
|
|
|
<span className="icon">🏠</span> {t("common.back-to-home")}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button className="btn" onClick={() => (window.location.href = "/auth")}>
|
|
|
|
<span className="icon">👉</span> {t("common.sign-in")}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-09-20 23:30:25 +08:00
|
|
|
)}
|
2022-09-19 21:53:27 +08:00
|
|
|
</main>
|
|
|
|
</div>
|
2022-06-19 11:32:49 +08:00
|
|
|
</section>
|
2021-12-08 23:43:52 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home;
|