need to commit to switch branch

This commit is contained in:
Anthony Cooper 2025-08-27 10:11:19 -04:00
parent 3b4b90861c
commit c679bd6fdd
1 changed files with 36 additions and 25 deletions

View File

@ -89,13 +89,17 @@ const MemoActionMenu = observer((props: Props) => {
return; return;
} }
}; };
//() => Promise.resolve({})
//async () => {} = () => Promise.resolve({})
//await promiseFunc, this just waits for the promise to be fulfilled
//use async just so we can use await inside, dont care about returned Promise
const handleToggleMemoStatusClick = async () => { const handleToggleMemoStatusClick = async () => {
//changing the state //changing the state
const state = memo.state === State.ARCHIVED ? State.NORMAL : State.ARCHIVED; const state = memo.state === State.ARCHIVED ? State.NORMAL : State.ARCHIVED;
//showing message depending on state //showing message depending on state
const message = memo.state === State.ARCHIVED ? t("message.restored-successfully") : t("message.archived-successfully"); const message = memo.state === State.ARCHIVED ? t("message.restored-successfully") : t("message.archived-successfully");
try { try {
//must wait for this promise returned by updateMemo to be fulfileld before continuing
await memoStore.updateMemo( await memoStore.updateMemo(
{ {
name: memo.name, name: memo.name,
@ -104,31 +108,38 @@ const MemoActionMenu = observer((props: Props) => {
["state"], ["state"],
); );
// Show toast with Undo button //Show toast with Undo button
//input is function that takes in the toast object we will work with and it will be used in the output of the higher order function //input is function that takes in the toast object we will work with and it will be used in the output of the higher order function
toast.custom((tToast) => ( toast.custom(
<div className="flex items-center gap-3 bg-white dark:bg-gray-800 p-3 rounded-xl shadow"> (
<span>{message}</span> tToast,
<button ) => (
className="ml-auto text-blue-600 hover:underline" //div container
onClick={async () => { <div className="flex items-center gap-3 bg-white dark:bg-gray-800 p-3 rounded-xl shadow">
// Undo action: revert to previous state <span>{message}</span>
await memoStore.updateMemo( <button
{ //attributes
name: memo.name, className="ml-auto text-blue-600 hover:underline"
state: memo.state, // revert to old state //onClick attribute is using async only so we can use await
}, onClick={async () => {
["state"], //must wait for this promise returned by updateMemo to be fulfileld before continuing
); await memoStore.updateMemo(
toast.dismiss(tToast.id); // close the toast {
toast.success(t("message.undo-successful")); // optional success toast name: memo.name,
memoUpdatedCallback(); state: memo.state, // revert to old state
}} },
> ["state"],
{t("common.undo")} );
</button> toast.dismiss(tToast.id); // close the toast
</div> toast.success(t("message.undo-successful")); // optional success toast
)); memoUpdatedCallback();
}}
>
{t("common.undo")}
</button>
</div>
),
);
} catch (error: any) { } catch (error: any) {
toast.error(error.details); toast.error(error.details);
console.error(error); console.error(error);