File tree Expand file tree Collapse file tree
modules/ppcp-settings/resources/js/data/todos Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
114123export function resetDismissedTodos ( ) {
115124 return async ( { dispatch } ) => {
116125 try {
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ const useStoreData = () => {
3838
3939const useHooks = ( ) => {
4040 const { dispatch, select } = useStoreData ( ) ;
41- const { fetchTodos, setDismissedTodos , setCompletedTodos } = dispatch ;
41+ const { fetchTodos, addDismissedTodo , setCompletedTodos } = dispatch ;
4242
4343 // Get todos data from store
4444 const todos = select . getTodos ( ) ;
@@ -47,12 +47,7 @@ const useHooks = () => {
4747
4848 const dismissedSet = new Set ( dismissedTodos ) ;
4949
50- const dismissTodo = async ( todoId ) => {
51- if ( ! dismissedSet . has ( todoId ) ) {
52- const newDismissedTodos = [ ...dismissedTodos , todoId ] ;
53- await setDismissedTodos ( newDismissedTodos ) ;
54- }
55- } ;
50+ const dismissTodo = ( todoId ) => addDismissedTodo ( todoId ) ;
5651
5752 const setTodoCompleted = async ( todoId , isCompleted ) => {
5853 let newCompletedTodos ;
You can’t perform that action at this time.
0 commit comments