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