forked from vhaudiquet/rhema-together
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.
This commit is contained in:
1 parent
3b82719d56
commit
d7aa268ae0
2 files changed
+182
-10
No files matched your search
+59
-10
@@ -1,9 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import { LogOut, Plus, Settings } from 'lucide-vue-next'
|
||||
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}`
|
||||
@@ -19,6 +44,7 @@ const {
|
||||
} = useRooms()
|
||||
|
||||
onMounted(() => {
|
||||
collapsed.value = readSidebar()
|
||||
if (session.value.loaded && user.value) void refreshRooms()
|
||||
})
|
||||
|
||||
@@ -32,17 +58,33 @@ async function onSignOut() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app-shell">
|
||||
<aside class="sidebar">
|
||||
<div class="app-shell" :class="{ 'sidebar-collapsed': collapsed }">
|
||||
<aside id="app-sidebar" class="sidebar">
|
||||
<div class="sidebar-top">
|
||||
<NuxtLink to="/rooms" class="sidebar-brand">
|
||||
<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>Rooms</span>
|
||||
<span class="sidebar-label-text">Rooms</span>
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
@@ -64,18 +106,25 @@ async function onSignOut() {
|
||||
:to="`/room/${room.id}`"
|
||||
class="sidebar-room"
|
||||
:title="room.name"
|
||||
:aria-label="room.name"
|
||||
>
|
||||
{{ 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">
|
||||
<NuxtLink to="/settings" class="sidebar-link" title="Settings" aria-label="Settings">
|
||||
<Settings :size="16" aria-hidden="true" />
|
||||
<span>Settings</span>
|
||||
<span class="sidebar-link-text">Settings</span>
|
||||
</NuxtLink>
|
||||
<div class="sidebar-account">
|
||||
<NuxtLink to="/profile" class="sidebar-account-link" title="Open profile">
|
||||
<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"
|
||||
|
||||
Reference in new issue
Block a user