web: improve item flash animation when revealing item in list

this also fixes a potential memory leak due to event listener not unsubscribing
This commit is contained in:
Abdullah Atta
2025-03-27 13:48:25 +05:00
parent f0fd20051e
commit 174bb9a935
2 changed files with 5 additions and 4 deletions

View File

@@ -206,7 +206,7 @@ textarea,
} }
.flash { .flash {
animation: flash 0.5s; animation: flash 1s;
} }
@keyframes flash { @keyframes flash {

View File

@@ -112,7 +112,7 @@ function ListContainer(props: ListContainerProps) {
let flashStartTimeout: NodeJS.Timeout; let flashStartTimeout: NodeJS.Timeout;
let flashEndTimeout: NodeJS.Timeout; let flashEndTimeout: NodeJS.Timeout;
AppEventManager.subscribe( const event = AppEventManager.subscribe(
AppEvents.revealItemInList, AppEvents.revealItemInList,
async (id?: string) => { async (id?: string) => {
if (!id || !listRef.current) return; if (!id || !listRef.current) return;
@@ -133,16 +133,17 @@ function ListContainer(props: ListContainerProps) {
noteItem.classList.add("flash"); noteItem.classList.add("flash");
flashEndTimeout = setTimeout(() => { flashEndTimeout = setTimeout(() => {
noteItem.classList.remove("flash"); noteItem.classList.remove("flash");
}, 1000); }, 2000);
}, 500); }, 500);
} }
); );
return () => { return () => {
event.unsubscribe();
clearTimeout(flashStartTimeout); clearTimeout(flashStartTimeout);
clearTimeout(flashEndTimeout); clearTimeout(flashEndTimeout);
}; };
}, []); }, [items]);
useEffect(() => { useEffect(() => {
return () => { return () => {