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,
@ -106,13 +110,19 @@ const MemoActionMenu = observer((props: Props) => {
//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(
(
tToast,
) => (
//div container
<div className="flex items-center gap-3 bg-white dark:bg-gray-800 p-3 rounded-xl shadow"> <div className="flex items-center gap-3 bg-white dark:bg-gray-800 p-3 rounded-xl shadow">
<span>{message}</span> <span>{message}</span>
<button <button
//attributes
className="ml-auto text-blue-600 hover:underline" className="ml-auto text-blue-600 hover:underline"
//onClick attribute is using async only so we can use await
onClick={async () => { onClick={async () => {
// Undo action: revert to previous state //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,
@ -128,7 +138,8 @@ const MemoActionMenu = observer((props: Props) => {
{t("common.undo")} {t("common.undo")}
</button> </button>
</div> </div>
)); ),
);
} catch (error: any) { } catch (error: any) {
toast.error(error.details); toast.error(error.details);
console.error(error); console.error(error);