mirror of https://github.com/usememos/memos
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.
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useMemoStore } from "../store/module";
|
|
import useLoading from "../hooks/useLoading";
|
|
import Icon from "./Icon";
|
|
import { generateDialog } from "./Dialog";
|
|
import toastHelper from "./Toast";
|
|
import ArchivedMemo from "./ArchivedMemo";
|
|
import "../less/archived-memo-dialog.less";
|
|
|
|
type Props = DialogProps;
|
|
|
|
const ArchivedMemoDialog: React.FC<Props> = (props: Props) => {
|
|
const { t } = useTranslation();
|
|
const { destroy } = props;
|
|
const memoStore = useMemoStore();
|
|
const memos = memoStore.state.memos;
|
|
const loadingState = useLoading();
|
|
const [archivedMemos, setArchivedMemos] = useState<Memo[]>([]);
|
|
|
|
useEffect(() => {
|
|
memoStore
|
|
.fetchArchivedMemos()
|
|
.then((result) => {
|
|
setArchivedMemos(result);
|
|
})
|
|
.catch((error) => {
|
|
console.error(error);
|
|
toastHelper.error(error.response.data.message);
|
|
})
|
|
.finally(() => {
|
|
loadingState.setFinish();
|
|
});
|
|
}, [memos]);
|
|
|
|
return (
|
|
<>
|
|
<div className="dialog-header-container">
|
|
<p className="title-text">
|
|
<span className="icon-text">🗂</span>
|
|
{t("archived.archived-memos")}
|
|
</p>
|
|
<button className="btn close-btn" onClick={destroy}>
|
|
<Icon.X className="icon-img" />
|
|
</button>
|
|
</div>
|
|
<div className="dialog-content-container">
|
|
{loadingState.isLoading ? (
|
|
<div className="tip-text-container">
|
|
<p className="tip-text">{t("archived.fetching-data")}</p>
|
|
</div>
|
|
) : archivedMemos.length === 0 ? (
|
|
<div className="tip-text-container">
|
|
<p className="tip-text">{t("archived.no-archived-memos")}</p>
|
|
</div>
|
|
) : (
|
|
<div className="archived-memos-container">
|
|
{archivedMemos.map((memo) => (
|
|
<ArchivedMemo key={`${memo.id}-${memo.updatedTs}`} memo={memo} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default function showArchivedMemoDialog(): void {
|
|
generateDialog(
|
|
{
|
|
className: "archived-memo-dialog",
|
|
dialogName: "archived-memo-dialog",
|
|
},
|
|
ArchivedMemoDialog,
|
|
{}
|
|
);
|
|
}
|