update the user profile so it works for non admins

This commit is contained in:
zipben 2025-06-04 22:33:14 +00:00
parent 2fd6809624
commit 0d39fc429c
4 changed files with 142 additions and 99 deletions

View file

@ -42,14 +42,31 @@
</ui-tooltip>
</nuxt-link>
<nuxt-link :to="'/user/' + user.id" class="relative w-9 h-9 md:w-32 bg-fg border border-gray-500 rounded-sm shadow-xs ml-1.5 sm:ml-3 md:ml-5 md:pl-3 md:pr-10 py-2 text-left sm:text-sm cursor-pointer hover:bg-bg/40" aria-haspopup="listbox" aria-expanded="true">
<span class="items-center hidden md:flex">
<span class="block truncate">{{ username }}</span>
</span>
<span class="h-full md:ml-3 md:absolute inset-y-0 md:right-0 flex items-center justify-center md:pr-2 pointer-events-none">
<span class="material-symbols text-xl text-gray-100">&#xe7fd;</span>
</span>
</nuxt-link>
<div class="relative">
<button @click="showProfileDropdown = !showProfileDropdown" class="relative w-9 h-9 md:w-32 bg-fg border border-gray-500 rounded-sm shadow-xs ml-1.5 sm:ml-3 md:ml-5 md:pl-3 md:pr-10 py-2 text-left sm:text-sm cursor-pointer hover:bg-bg/40" aria-haspopup="true" :aria-expanded="showProfileDropdown">
<span class="items-center hidden md:flex">
<span class="block truncate">{{ username }}</span>
</span>
<span class="h-full md:ml-3 md:absolute inset-y-0 md:right-0 flex items-center justify-center md:pr-2 pointer-events-none">
<span class="material-symbols text-xl text-gray-100">&#xe7fd;</span>
</span>
</button>
<div v-if="showProfileDropdown" class="absolute right-0 mt-1 w-48 bg-bg border border-gray-500 rounded-sm shadow-lg z-50 overflow-hidden">
<nuxt-link :to="'/user/' + user.id" class="block px-4 py-2.5 text-sm text-white hover:bg-primary/40 transition-colors duration-150">
<div class="flex items-center">
<span class="material-symbols text-lg mr-2">&#xe7fd;</span>
Profile
</div>
</nuxt-link>
<button @click="logout" class="w-full text-left px-4 py-2.5 text-sm text-white hover:bg-primary/40 transition-colors duration-150">
<div class="flex items-center">
<span class="material-symbols text-lg mr-2">&#xe9ba;</span>
Logout
</div>
</button>
</div>
</div>
</div>
<div v-show="numMediaItemsSelected" class="absolute top-0 left-0 w-full h-full px-4 bg-primary flex items-center">
<h1 class="text-lg md:text-2xl px-4">{{ $getString('MessageItemsSelected', [numMediaItemsSelected]) }}</h1>
@ -87,7 +104,8 @@
export default {
data() {
return {
totalEntities: 0
totalEntities: 0,
showProfileDropdown: false
}
},
computed: {
@ -375,13 +393,54 @@ export default {
},
batchAutoMatchClick() {
this.$store.commit('globals/setShowBatchQuickMatchModal', true)
},
logout() {
this.showProfileDropdown = false
// Disconnect from socket if it exists and is connected
if (this.$root.socket && this.$root.socket.connected) {
try {
console.log('Disconnecting from socket', this.$root.socket.id)
this.$root.socket.removeAllListeners()
this.$root.socket.disconnect()
} catch (error) {
console.error('Error disconnecting socket:', error)
}
}
// Clear user data
localStorage.removeItem('token')
this.$store.commit('libraries/setUserPlaylists', [])
this.$store.commit('libraries/setCollections', [])
this.$store.commit('user/setUser', null)
// Logout request
this.$axios
.$post('/logout')
.catch((error) => {
console.error('Logout error:', error)
})
.finally(() => {
this.$router.push('/login')
})
}
},
mounted() {
this.$eventBus.$on('bookshelf-total-entities', this.setBookshelfTotalEntities)
// Close dropdown when clicking outside
this.handleClickOutside = (e) => {
if (!this.$el.contains(e.target)) {
this.showProfileDropdown = false
}
}
document.addEventListener('click', this.handleClickOutside)
},
beforeDestroy() {
this.$eventBus.$off('bookshelf-total-entities', this.setBookshelfTotalEntities)
// Remove event listener with proper reference
if (this.handleClickOutside) {
document.removeEventListener('click', this.handleClickOutside)
}
}
}
</script>