refactor: add typescript support to project

This commit is contained in:
HD
2022-06-21 15:08:35 +08:00
parent 88ec2b742a
commit bd799ebea8
259 changed files with 1042 additions and 458 deletions
+26
View File
@@ -0,0 +1,26 @@
import { updateDraftMarkdown, updateDraftMixedText } from "../../app/slices/ui";
import { useAppDispatch, useAppSelector } from "../../app/store";
export default function useDraft({ context = "", id = "" }) {
const dispatch = useAppDispatch();
const _key = `${context}_${id}`;
const { draftMarkdown, draftMixedText } = useAppSelector((store) => {
return {
draftMarkdown: store.ui.draftMarkdown,
draftMixedText: store.ui.draftMixedText
};
});
const getUpdateDraft = (type = "mixed") => {
const update = type == "mixed" ? updateDraftMixedText : updateDraftMarkdown;
return (value) => {
dispatch(update({ key: _key, value }));
};
};
const getDraft = (type = "mixed") => {
return type == "mixed" ? draftMixedText[_key] : draftMarkdown[_key];
};
return { getDraft, getUpdateDraft };
}