Skip to content

Commit 5fb96c4

Browse files
committed
feat(todos): add addDismissedTodo thunk action that reads current state from store
Introduces a thunk-based action that always reads the dismissed list from the store at dispatch time, avoiding stale closure issues.
1 parent 5e04228 commit 5fb96c4

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

  • modules/ppcp-settings/resources/js/data/todos

modules/ppcp-settings/resources/js/data/todos/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ export function refresh() {
111111
};
112112
}
113113

114+
export function addDismissedTodo( todoId ) {
115+
return async ( { select, dispatch } ) => {
116+
const current = select.getDismissedTodos() || [];
117+
if ( ! current.includes( todoId ) ) {
118+
await dispatch.setDismissedTodos( [ ...current, todoId ] );
119+
}
120+
};
121+
}
122+
114123
export function resetDismissedTodos() {
115124
return async ( { dispatch } ) => {
116125
try {

0 commit comments

Comments
 (0)