From 42e68edc65c374fab3fc7c57bc7e849e5182c992 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 24 Nov 2022 14:44:09 -0600 Subject: [PATCH] Fix:Users table activity & cleanup --- client/components/tables/UsersTable.vue | 10 ++++------ client/layouts/default.vue | 11 ++++------- client/store/users.js | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/client/components/tables/UsersTable.vue b/client/components/tables/UsersTable.vue index c4459b0d..8fb644ea 100644 --- a/client/components/tables/UsersTable.vue +++ b/client/components/tables/UsersTable.vue @@ -26,11 +26,9 @@ {{ user.type }} -
-

Listening: {{ usersOnline[user.id].session.libraryItem.media.metadata.title || '' }}

-
-
-

Last: {{ user.mostRecent.metadata.title }}

+
+

Listening: {{ usersOnline[user.id].session.libraryItem.media.metadata.title || '' }}

+

Last: {{ usersOnline[user.id].mostRecent.media.metadata.title }}

@@ -81,7 +79,7 @@ export default { }, usersOnline() { var usermap = {} - this.$store.state.users.users.forEach((u) => (usermap[u.id] = { online: true, session: u.session })) + this.$store.state.users.usersOnline.forEach((u) => (usermap[u.id] = u)) return usermap } }, diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 557b5258..643a5b38 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -133,10 +133,7 @@ export default { }) if (payload.usersOnline) { - this.$store.commit('users/resetUsers') - payload.usersOnline.forEach((user) => { - this.$store.commit('users/updateUser', user) - }) + this.$store.commit('users/setUsersOnline', payload.usersOnline) } this.$eventBus.$emit('socket_init') @@ -283,13 +280,13 @@ export default { } }, userOnline(user) { - this.$store.commit('users/updateUser', user) + this.$store.commit('users/updateUserOnline', user) }, userOffline(user) { - this.$store.commit('users/removeUser', user) + this.$store.commit('users/removeUserOnline', user) }, userStreamUpdate(user) { - this.$store.commit('users/updateUser', user) + this.$store.commit('users/updateUserOnline', user) }, userMediaProgressUpdate(payload) { this.$store.commit('user/updateMediaProgress', payload) diff --git a/client/store/users.js b/client/store/users.js index 131b7d8c..2439ee31 100644 --- a/client/store/users.js +++ b/client/store/users.js @@ -1,11 +1,11 @@ export const state = () => ({ - users: [] + usersOnline: [] }) export const getters = { getIsUserOnline: state => id => { - return state.users.find(u => u.id === id) + return state.usersOnline.find(u => u.id === id) } } @@ -14,18 +14,18 @@ export const actions = { } export const mutations = { - resetUsers(state) { - state.users = [] + setUsersOnline(state, usersOnline) { + state.usersOnline = usersOnline }, - updateUser(state, user) { - var index = state.users.findIndex(u => u.id === user.id) + updateUserOnline(state, user) { + var index = state.usersOnline.findIndex(u => u.id === user.id) if (index >= 0) { - state.users.splice(index, 1, user) + state.usersOnline.splice(index, 1, user) } else { - state.users.push(user) + state.usersOnline.push(user) } }, - removeUser(state, user) { - state.users = state.users.filter(u => u.id !== user.id) + removeUserOnline(state, user) { + state.usersOnline = state.usersOnline.filter(u => u.id !== user.id) } } \ No newline at end of file