Files
vhaudiquet d7aa268ae0 feat: fold the sidebar to a rail
A toggle at the top of the sidebar collapses it from 232px to a 64px
rail with the logo, room initials, and the bottom actions. Opening it
again restores the room names. The choice is stored in localStorage and
restored on the next visit.

The toggle is hidden on the horizontal mobile bar, where the sidebar
already runs as a single row.
2026-11-28 02:12:10 +01:00

157 lines
4.5 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { LogOut, PanelLeftClose, PanelLeftOpen, Plus, Settings } from 'lucide-vue-next'
const { user, signOut, session } = useSession()
const SIDEBAR_KEY = 'together.sidebar'
const collapsed = ref(false)
function roomInitial(name: string): string {
const trimmed = name.trim()
return trimmed ? trimmed.charAt(0).toUpperCase() : '?'
}
function readSidebar(): boolean {
try {
return window.localStorage.getItem(SIDEBAR_KEY) === 'collapsed'
} catch {
return false
}
}
function toggleSidebar() {
collapsed.value = !collapsed.value
try {
window.localStorage.setItem(SIDEBAR_KEY, collapsed.value ? 'collapsed' : 'open')
} catch {
// A browser that refuses storage still gets the toggle for this visit.
}
}
const avatarSrc = computed(() => {
if (!user.value?.avatar_updated_at) return null
return `/api/avatars/${user.value.id}?v=${user.value.avatar_updated_at}`
})
const {
rooms: roomList,
loading: roomsLoading,
error: roomsError,
creating,
openCreate,
closeCreate,
refresh: refreshRooms,
} = useRooms()
onMounted(() => {
collapsed.value = readSidebar()
if (session.value.loaded && user.value) void refreshRooms()
})
watch(user, (current) => {
if (current) void refreshRooms()
})
async function onSignOut() {
await signOut()
}
</script>
<template>
<div class="app-shell" :class="{ 'sidebar-collapsed': collapsed }">
<aside id="app-sidebar" class="sidebar">
<div class="sidebar-top">
<NuxtLink
to="/rooms"
class="sidebar-brand"
title="Rhema Together"
aria-label="Rhema Together"
>
<img src="/rhema-logo.png" class="sidebar-brand-mark" alt="">
<span>Rhema Together</span>
</NuxtLink>
<button
type="button"
class="icon-btn sidebar-toggle"
:aria-label="collapsed ? 'Expand sidebar' : 'Collapse sidebar'"
:aria-expanded="!collapsed"
aria-controls="app-sidebar"
:title="collapsed ? 'Expand sidebar' : 'Collapse sidebar'"
@click="toggleSidebar"
>
<component :is="collapsed ? PanelLeftOpen : PanelLeftClose" :size="16" aria-hidden="true" />
</button>
</div>
<div class="sidebar-label">
<span class="sidebar-label-text">Rooms</span>
<button
type="button"
class="icon-btn"
aria-label="New room"
title="New room"
@click="openCreate()"
>
<Plus :size="16" aria-hidden="true" />
</button>
</div>
<nav class="sidebar-rooms" aria-label="Rooms">
<p v-if="roomsLoading && roomList.length === 0" class="sidebar-room muted">Loading rooms.</p>
<p v-else-if="roomsError" class="sidebar-room muted">{{ roomsError }}</p>
<p v-else-if="roomList.length === 0" class="sidebar-room muted">No rooms yet.</p>
<NuxtLink
v-for="room in roomList"
:key="room.id"
:to="`/room/${room.id}`"
class="sidebar-room"
:title="room.name"
:aria-label="room.name"
>
<span class="sidebar-room-text">{{ room.name }}</span>
<span class="sidebar-room-initial" aria-hidden="true">{{ roomInitial(room.name) }}</span>
</NuxtLink>
</nav>
<div class="sidebar-bottom">
<NuxtLink to="/settings" class="sidebar-link" title="Settings" aria-label="Settings">
<Settings :size="16" aria-hidden="true" />
<span class="sidebar-link-text">Settings</span>
</NuxtLink>
<div class="sidebar-account">
<NuxtLink
to="/profile"
class="sidebar-account-link"
title="Open profile"
:aria-label="`Open ${user?.display_name ?? 'your'} profile`"
>
<AppAvatar
v-if="user"
:name="user.display_name"
color="var(--member-1)"
:src="avatarSrc"
size="sm"
/>
<span class="sidebar-account-name" :title="user?.handle">{{ user?.display_name }}</span>
</NuxtLink>
<button
type="button"
class="icon-btn"
aria-label="Sign out"
title="Sign out"
@click="onSignOut"
>
<LogOut :size="16" aria-hidden="true" />
</button>
</div>
</div>
</aside>
<div class="main">
<slot />
</div>
<NewRoomDialog v-if="creating" @close="closeCreate()" />
</div>
</template>