Skip to content

Commit

Permalink
fix: cancel removes memo cache (#3826)
Browse files Browse the repository at this point in the history
Clear local storage record of memo changes if chanes to a memo are cancelled
  • Loading branch information
RoccoSmit authored Aug 23, 2024
1 parent 5f35ac5 commit eca9649
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions web/src/components/MemoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface State {
}

const MemoEditor = (props: Props) => {
const { className, cacheKey, memoName, parentMemoName, autoFocus, onConfirm } = props;
const { className, cacheKey, memoName, parentMemoName, autoFocus, onConfirm, onCancel } = props;
const t = useTranslate();
const { i18n } = useTranslation();
const workspaceSettingStore = useWorkspaceSettingStore();
Expand Down Expand Up @@ -364,6 +364,14 @@ const MemoEditor = (props: Props) => {
});
};

const handleCancelBtnClick = () => {
localStorage.removeItem(contentCacheKey);

if (onCancel) {
onCancel();
}
};

const handleEditorFocus = () => {
editorRef.current?.focus();
};
Expand Down Expand Up @@ -457,7 +465,7 @@ const MemoEditor = (props: Props) => {
</div>
<div className="shrink-0 flex flex-row justify-end items-center gap-2">
{props.onCancel && (
<Button className="!font-normal" color="neutral" variant="plain" loading={state.isRequesting} onClick={props.onCancel}>
<Button className="!font-normal" color="neutral" variant="plain" loading={state.isRequesting} onClick={handleCancelBtnClick}>
{t("common.cancel")}
</Button>
)}
Expand Down

0 comments on commit eca9649

Please sign in to comment.