Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions frontend/src/components/layout/NavBar.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {
PlayingCardsFan,
Search,
Heart,
MessageCircle,
Settings,
LogOut,
} from '@lucide/vue'
import { useAuth } from '@/composable/useAuth'

interface NavItem {
label: string
Expand All @@ -30,28 +30,42 @@ const isActive = (path: string) => {
}

const goTo = (path: string) => router.push(path)

const logout = () => {
useAuth().disconnect()
}
</script>

<template>
<!-- ===== Desktop / tablette : sidebar verticale ===== -->
<nav
class="hidden md:flex md:flex-col md:justify-between md:items-center lg:items-stretch md:w-20 lg:w-64 md:h-screen md:sticky md:top-0 border-r bg-background"
>
<div class="flex flex-col gap-2 p-3 mt-4">
<div class="h-full flex flex-col justify-between p-3">
<div class="flex flex-col gap-2 mt-4">
<button
v-for="item in navItems"
:key="item.path"
@click="goTo(item.path)"
:class="[
'flex items-center gap-3 rounded-xl px-3 py-2.5 transition-colors',
'hover:bg-muted',
isActive(item.path)
? 'bg-primary/10 text-primary font-medium'
: 'text-muted-foreground',
]"
>
<component :is="item.icon" class="h-6 w-6 shrink-0 md:items-center" />
<span class="hidden lg:inline text-sm">{{ item.label }}</span>
</button>
</div>

<button
v-for="item in navItems"
:key="item.path"
@click="goTo(item.path)"
:class="[
'flex items-center gap-3 rounded-xl px-3 py-2.5 transition-colors',
'hover:bg-muted',
isActive(item.path)
? 'bg-primary/10 text-primary font-medium'
: 'text-muted-foreground',
]"
class="flex items-center gap-3 rounded-xl px-3 py-2.5 transition-colors hover:bg-muted text-destructive"
@click="() => logout()"
>
<component :is="item.icon" class="h-6 w-6 shrink-0 md:items-center" />
<span class="hidden lg:inline text-sm">{{ item.label }}</span>
<LogOut class="h-6 w-6 shrink-0 md:items-center" />
<span class="hidden lg:inline text-sm">Logout</span>
</button>
</div>
</nav>
Expand All @@ -77,6 +91,13 @@ const goTo = (path: string) => router.push(path)
/>
<span class="leading-none">{{ item.label }}</span>
</button>
<button
@click="() => logout()"
class="flex flex-col items-center justify-center gap-1 flex-1 h-full text-xs transition-colors text-muted-foreground"
>
<LogOut class="h-6 w-6" />
<span class="leading-none">Logout</span>
</button>
</div>
</nav>
</template>
8 changes: 4 additions & 4 deletions frontend/src/composable/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref } from 'vue'
import { authApi, type LoginResponse, type RegisterCredentials } from '@/api/auth'
import { getSocket } from '@/plugins/socket'
import { disconnectSocket, getSocket } from '@/plugins/socket'
import router from '@/router'
import { useAuthStore } from '@/store/useAuthStore'

Expand Down Expand Up @@ -99,12 +99,12 @@ export function useAuth() {

useAuthStore().clearSession()

getSocket().close()
disconnectSocket()
}

const disconnect = (): void => {
const disconnect = async (): Promise<void> => {
logout()
router.push({ name: 'home' }).then(r => {})
await router.push({ name: 'auth' })
}

const forgotPassword = async (email: string): Promise<boolean> => {
Expand Down
Loading