From 5f0289c363b5ca96369943a308211506ed40a527 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 7 May 2019 00:56:08 +0300 Subject: [PATCH] Fix filter logic to work with multiple choice on different pages --- src/store/modules/users.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 56eb07a0..f49a4778 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -21,14 +21,9 @@ const users = { SET_LOADING: (state, status) => { state.loading = status }, - SWAP_USER: (state, user) => { - const usersWithoutSwapped = state.fetchedUsers.filter(u => { - return u.id !== user.id - }) - - state.fetchedUsers = [...usersWithoutSwapped, user].sort((a, b) => - a.nickname.localeCompare(b.nickname) - ) + SWAP_USER: (state, updatedUser) => { + const updated = state.fetchedUsers.map(user => user.id === updatedUser.id ? updatedUser : user) + state.fetchedUsers = updated.sort((a, b) => a.nickname.localeCompare(b.nickname)) }, SET_COUNT: (state, count) => { state.totalUsersCount = count