feat(desktop): add session list density modes
Squashed from #68124, resolved against current main (inbox cards, marquee titles, actions cluster). Adds a Settings → Appearance 'Session list density' preference — compact (default, unchanged), comfortable (+deterministic metadata line), detailed (+initial-request preview) — with density-aware virtualizer estimates. Closes #68119 (cherry picked from commits 93bc19400a..568f78a8fc)
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type { SessionInfo } from '@/types/hermes'
|
||||
|
||||
import { sessionRowDetails, sessionRowEstimate, type SessionRowFormatters } from './session-row-details'
|
||||
|
||||
const en: SessionRowFormatters = {
|
||||
messageCount: count => `${count} ${count === 1 ? 'message' : 'messages'}`,
|
||||
toolCallCount: count => `${count} ${count === 1 ? 'tool call' : 'tool calls'}`
|
||||
}
|
||||
|
||||
const session = (overrides: Partial<SessionInfo> = {}): SessionInfo => ({
|
||||
ended_at: null,
|
||||
id: 's1',
|
||||
input_tokens: 0,
|
||||
is_active: false,
|
||||
last_active: 1,
|
||||
message_count: 26,
|
||||
model: 'google/gemini-3.1-pro',
|
||||
output_tokens: 0,
|
||||
preview: ' Explore\nGmail-like density tiers for session rows. ',
|
||||
source: 'desktop',
|
||||
started_at: 1,
|
||||
title: 'Session density exploration',
|
||||
tool_call_count: 8,
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('session row details', () => {
|
||||
it('provides density-aware virtual row estimates', () => {
|
||||
expect(sessionRowEstimate('compact')).toBe(28)
|
||||
expect(sessionRowEstimate('comfortable')).toBe(45)
|
||||
expect(sessionRowEstimate('detailed')).toBe(63)
|
||||
})
|
||||
|
||||
it('keeps the detailed estimate even when preview is omitted as a title duplicate', () => {
|
||||
const details = sessionRowDetails(session({ title: null }), en)
|
||||
|
||||
expect(details.preview).toBeNull()
|
||||
expect(sessionRowEstimate('detailed')).toBe(63)
|
||||
})
|
||||
|
||||
it('formats deterministic metadata without ambiguous call wording', () => {
|
||||
expect(sessionRowDetails(session({ git_branch: 'feature/menu' }), en)).toEqual({
|
||||
metadata: 'feature/menu · gemini-3.1-pro · 26 messages · 8 tool calls',
|
||||
preview: 'Explore Gmail-like density tiers for session rows.'
|
||||
})
|
||||
})
|
||||
|
||||
it('uses singular labels and omits unavailable fields', () => {
|
||||
expect(
|
||||
sessionRowDetails(
|
||||
session({
|
||||
git_branch: null,
|
||||
message_count: 1,
|
||||
model: null,
|
||||
preview: null,
|
||||
title: 'Manual title',
|
||||
tool_call_count: 1
|
||||
}),
|
||||
en
|
||||
)
|
||||
).toEqual({ metadata: '1 message · 1 tool call', preview: null })
|
||||
})
|
||||
|
||||
it('omits zero counts from metadata so the sidebar stays clean', () => {
|
||||
expect(
|
||||
sessionRowDetails(
|
||||
session({ git_branch: null, message_count: 0, model: null, tool_call_count: 0 }),
|
||||
en
|
||||
)
|
||||
).toEqual({ metadata: '', preview: 'Explore Gmail-like density tiers for session rows.' })
|
||||
})
|
||||
|
||||
it('normalizes whitespace-only title, branch, and preview values', () => {
|
||||
expect(
|
||||
sessionRowDetails(
|
||||
session({
|
||||
git_branch: ' ',
|
||||
preview: ' ',
|
||||
title: ' '
|
||||
}),
|
||||
en
|
||||
)
|
||||
).toEqual({ metadata: 'gemini-3.1-pro · 26 messages · 8 tool calls', preview: null })
|
||||
})
|
||||
|
||||
it('omits the preview when it already supplies the displayed title', () => {
|
||||
expect(sessionRowDetails(session({ title: null }), en)).toEqual({
|
||||
metadata: 'gemini-3.1-pro · 26 messages · 8 tool calls',
|
||||
preview: null
|
||||
})
|
||||
})
|
||||
|
||||
it('localizes count labels via the formatter interface', () => {
|
||||
const ja: SessionRowFormatters = {
|
||||
messageCount: count => `${count} 件のメッセージ`,
|
||||
toolCallCount: count => `${count} 件のツール呼び出し`
|
||||
}
|
||||
|
||||
expect(
|
||||
sessionRowDetails(
|
||||
session({ git_branch: null, message_count: 3, model: null, tool_call_count: 5 }),
|
||||
ja
|
||||
)
|
||||
).toEqual({
|
||||
metadata: '3 件のメッセージ · 5 件のツール呼び出し',
|
||||
preview: 'Explore Gmail-like density tiers for session rows.'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { SessionListDensity } from '@/store/session-list-density'
|
||||
import type { SessionInfo } from '@/types/hermes'
|
||||
|
||||
export interface SessionRowDetails {
|
||||
metadata: string
|
||||
preview: null | string
|
||||
}
|
||||
|
||||
export interface SessionRowFormatters {
|
||||
messageCount: (count: number) => string
|
||||
toolCallCount: (count: number) => string
|
||||
}
|
||||
|
||||
const modelLabel = (model: null | string) => model?.split('/').pop()?.trim() || null
|
||||
const oneLine = (value: null | string) => value?.replace(/\s+/g, ' ').trim() || null
|
||||
|
||||
export const sessionRowEstimate = (density: SessionListDensity) =>
|
||||
({ compact: 28, comfortable: 45, detailed: 63 })[density]
|
||||
|
||||
export function sessionRowDetails(session: SessionInfo, fmt: SessionRowFormatters): SessionRowDetails {
|
||||
const preview = oneLine(session.preview)
|
||||
const hasOwnTitle = Boolean(session.title?.trim())
|
||||
|
||||
const metadata = [
|
||||
session.git_branch?.trim() || null,
|
||||
modelLabel(session.model),
|
||||
session.message_count > 0 ? fmt.messageCount(session.message_count) : null,
|
||||
session.tool_call_count > 0 ? fmt.toolCallCount(session.tool_call_count) : null
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · ')
|
||||
|
||||
return {
|
||||
metadata,
|
||||
preview: hasOwnTitle ? preview : null
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import { normalizeProfileKey } from '@/store/profile'
|
||||
import { $projects } from '@/store/projects'
|
||||
import { $pullRequestsByBranch, sessionPrKey } from '@/store/pull-requests'
|
||||
import { $sessionDotStateById, hasLiveTurn, showsRunningArc } from '@/store/session-dot-state'
|
||||
import { $sessionListDensity } from '@/store/session-list-density'
|
||||
import { sessionCostUsd } from '@/store/sidebar-archive'
|
||||
import { $todoProgressBySession } from '@/store/todos'
|
||||
|
||||
@@ -43,6 +44,7 @@ import {
|
||||
SidebarRowShell
|
||||
} from './chrome'
|
||||
import { SessionActionsMenu, SessionContextMenu } from './session-actions-menu'
|
||||
import { sessionRowDetails } from './session-row-details'
|
||||
import { useProfilePrewarm } from './use-profile-prewarm'
|
||||
|
||||
interface SidebarSessionRowProps extends React.ComponentProps<'div'> {
|
||||
@@ -134,6 +136,12 @@ function SidebarSessionRowImpl({
|
||||
const r = t.sidebar.row
|
||||
const { cancelPrewarm, startPrewarm } = useProfilePrewarm(session.profile)
|
||||
const title = sessionTitle(session)
|
||||
const density = useStore($sessionListDensity)
|
||||
const fmt = t.sidebar
|
||||
const details = sessionRowDetails(session, {
|
||||
messageCount: fmt.messageCount,
|
||||
toolCallCount: fmt.toolCallCount
|
||||
})
|
||||
const age = formatAge(session.last_active || session.started_at, r)
|
||||
const handleLabel = `Reorder ${title}`
|
||||
// Opt-in row metadata from the sidebar's filter menu. Read from the store
|
||||
@@ -311,6 +319,10 @@ function SidebarSessionRowImpl({
|
||||
className={cn(
|
||||
'group row-hover relative',
|
||||
card && SIDEBAR_ROW_CARD_MIN_H,
|
||||
// Density-aware minimum heights for the inline (non-card) row: the
|
||||
// metadata / preview lines below need the extra rows (#68119).
|
||||
!card && density !== 'compact' && 'min-h-[2.75rem]',
|
||||
!card && density === 'detailed' && 'min-h-[3.875rem]',
|
||||
isSelected && 'bg-(--ui-row-active-background)',
|
||||
liveTurn && 'text-foreground',
|
||||
// Opaque surface while lifted so the dragged row erases what's under
|
||||
@@ -438,15 +450,30 @@ function SidebarSessionRowImpl({
|
||||
<>
|
||||
{leadNode}
|
||||
{handoffBadge}
|
||||
<OverflowTip label={title}>
|
||||
<SidebarRowLabel
|
||||
className="hover-marquee flex-1 font-normal group-hover:text-foreground group-data-[working=true]:text-foreground/90"
|
||||
onPointerEnter={armMarquee}
|
||||
onPointerLeave={disarmMarquee}
|
||||
>
|
||||
<span className="hover-marquee-inner">{title}</span>
|
||||
</SidebarRowLabel>
|
||||
</OverflowTip>
|
||||
<span className="min-w-0 flex-1 self-center">
|
||||
<OverflowTip label={title}>
|
||||
<SidebarRowLabel
|
||||
className="hover-marquee block font-normal group-hover:text-foreground group-data-[working=true]:text-foreground/90"
|
||||
onPointerEnter={armMarquee}
|
||||
onPointerLeave={disarmMarquee}
|
||||
>
|
||||
<span className="hover-marquee-inner">{title}</span>
|
||||
</SidebarRowLabel>
|
||||
</OverflowTip>
|
||||
{/* Session-list density (#68119): comfortable adds one
|
||||
deterministic metadata line; detailed adds the initial
|
||||
request preview. Compact keeps today's one-line row. */}
|
||||
{density !== 'compact' && details.metadata && (
|
||||
<span className="mt-0.5 block truncate text-[0.625rem] leading-none text-(--ui-text-tertiary)">
|
||||
{details.metadata}
|
||||
</span>
|
||||
)}
|
||||
{density === 'detailed' && details.preview && (
|
||||
<span className="mt-1 block truncate text-[0.625rem] leading-none text-(--ui-text-quaternary)">
|
||||
{details.preview}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useSortable } from '@dnd-kit/sortable'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import { useStore } from '@nanostores/react'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
import type * as React from 'react'
|
||||
import { type FC, useRef } from 'react'
|
||||
import { type FC, useEffect, useRef } from 'react'
|
||||
|
||||
import type { SessionInfo } from '@/hermes'
|
||||
import { useI18n } from '@/i18n'
|
||||
@@ -10,9 +11,11 @@ import { type SidebarListRow } from '@/lib/session-date-groups'
|
||||
import { sessionBucketLabel } from '@/lib/time'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { sessionPinId } from '@/store/session'
|
||||
import { $sessionListDensity } from '@/store/session-list-density'
|
||||
|
||||
import { SidebarDateDivider } from './chrome'
|
||||
import { SidebarSessionRow } from './session-row'
|
||||
import { sessionRowEstimate } from './session-row-details'
|
||||
|
||||
interface SessionRowCommonProps {
|
||||
branchStem?: string
|
||||
@@ -46,11 +49,11 @@ export interface VirtualSessionListProps {
|
||||
sortable: boolean
|
||||
}
|
||||
|
||||
const ROW_ESTIMATE_PX = 28
|
||||
// Matches the card's typical rendered height (four lines when a preview
|
||||
// exists) so long card lists don't jump under the scroll thumb before
|
||||
// self-measurement catches up.
|
||||
const CARD_ROW_ESTIMATE_PX = 66
|
||||
const DIVIDER_ESTIMATE_PX = 28
|
||||
const OVERSCAN_ROWS = 12
|
||||
|
||||
export const VirtualSessionList: FC<VirtualSessionListProps> = ({
|
||||
@@ -71,10 +74,19 @@ export const VirtualSessionList: FC<VirtualSessionListProps> = ({
|
||||
const { t } = useI18n()
|
||||
const dividerLabels = t.sidebar.dateDivider
|
||||
const scrollerRef = useRef<HTMLDivElement | null>(null)
|
||||
const density = useStore($sessionListDensity)
|
||||
|
||||
const virtualizer = useVirtualizer({
|
||||
count: listRows.length,
|
||||
estimateSize: () => (card ? CARD_ROW_ESTIMATE_PX : ROW_ESTIMATE_PX),
|
||||
estimateSize: (index: number) => {
|
||||
const row = listRows[index]
|
||||
|
||||
if (row?.kind === 'divider') {
|
||||
return DIVIDER_ESTIMATE_PX
|
||||
}
|
||||
|
||||
return card ? CARD_ROW_ESTIMATE_PX : sessionRowEstimate(density)
|
||||
},
|
||||
getItemKey: index => {
|
||||
const row = listRows[index]
|
||||
|
||||
@@ -86,6 +98,10 @@ export const VirtualSessionList: FC<VirtualSessionListProps> = ({
|
||||
overscan: OVERSCAN_ROWS
|
||||
})
|
||||
|
||||
// Rows are measured after paint, so changing density must invalidate cached
|
||||
// measurements from the previous mode before off-screen rows re-enter.
|
||||
useEffect(() => virtualizer.measure(), [density, virtualizer])
|
||||
|
||||
const virtualItems = virtualizer.getVirtualItems()
|
||||
const totalSize = virtualizer.getTotalSize()
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ import { $embedAllowed, $embedMode, clearEmbedAllowed, type EmbedMode, setEmbedM
|
||||
import { $activeGatewayProfile, $profiles, normalizeProfileKey } from '@/store/profile'
|
||||
import { $reactionsEnabled, setReactionsEnabled } from '@/store/reactions-enabled'
|
||||
import { $reasoningCollapsedByDefault, setReasoningCollapsedByDefault } from '@/store/reasoning-disclosure'
|
||||
import {
|
||||
$sessionListDensity,
|
||||
type SessionListDensity,
|
||||
setSessionListDensity
|
||||
} from '@/store/session-list-density'
|
||||
import { $toolViewMode, setToolViewMode } from '@/store/tool-view'
|
||||
import { $translucency, setTranslucency } from '@/store/translucency'
|
||||
import { $zoomPercent, setZoomPercent } from '@/store/zoom'
|
||||
@@ -250,6 +255,7 @@ export function AppearanceSettings() {
|
||||
const { themeName, mode, resolvedMode, availableThemes, setTheme, setMode } = useTheme()
|
||||
const toolViewMode = useStore($toolViewMode)
|
||||
const reasoningCollapsedByDefault = useStore($reasoningCollapsedByDefault)
|
||||
const sessionListDensity = useStore($sessionListDensity)
|
||||
const zoomPercent = useStore($zoomPercent)
|
||||
const embedMode = useStore($embedMode)
|
||||
const embedAllowed = useStore($embedAllowed)
|
||||
@@ -293,6 +299,12 @@ export function AppearanceSettings() {
|
||||
{ id: 'technical', label: a.technical }
|
||||
] as const
|
||||
|
||||
const sessionDensityOptions = [
|
||||
{ id: 'compact', label: a.sessionDensityCompact },
|
||||
{ id: 'comfortable', label: a.sessionDensityComfortable },
|
||||
{ id: 'detailed', label: a.sessionDensityDetailed }
|
||||
] as const satisfies readonly { id: SessionListDensity; label: string }[]
|
||||
|
||||
const embedOptions = [
|
||||
{ id: 'ask', label: a.embedsAsk },
|
||||
{ id: 'always', label: a.embedsAlways },
|
||||
@@ -435,6 +447,21 @@ export function AppearanceSettings() {
|
||||
|
||||
<TerminalFontSetting />
|
||||
|
||||
<ListRow
|
||||
action={
|
||||
<SegmentedControl
|
||||
onChange={id => {
|
||||
triggerHaptic('selection')
|
||||
setSessionListDensity(id)
|
||||
}}
|
||||
options={sessionDensityOptions}
|
||||
value={sessionListDensity}
|
||||
/>
|
||||
}
|
||||
description={a.sessionDensityDesc}
|
||||
title={a.sessionDensityTitle}
|
||||
/>
|
||||
|
||||
<ListRow
|
||||
action={
|
||||
<div className="flex items-center gap-3">
|
||||
|
||||
@@ -463,6 +463,11 @@ export const en: Translations = {
|
||||
uiScaleTitle: 'UI Scale',
|
||||
uiScaleDesc: (percent: number) =>
|
||||
`Scales text and controls across the whole app. Cmd/Ctrl with +, - and 0 also works. Current: ${percent}%.`,
|
||||
sessionDensityTitle: 'Session List Density',
|
||||
sessionDensityDesc: 'Choose how much context appears beneath session titles in the sidebar.',
|
||||
sessionDensityCompact: 'Compact',
|
||||
sessionDensityComfortable: 'Comfortable',
|
||||
sessionDensityDetailed: 'Detailed',
|
||||
terminalFontTitle: 'Terminal Font',
|
||||
terminalFontDesc:
|
||||
'Choose an installed font for Desktop terminals. Nerd Fonts render Powerlevel10k and shell icons; leave blank to use bundled JetBrains Mono.',
|
||||
@@ -2014,6 +2019,8 @@ export const en: Translations = {
|
||||
loading: 'Loading…',
|
||||
loadMore: 'Load more',
|
||||
loadCount: step => `Load ${step} more`,
|
||||
messageCount: count => `${count} ${count === 1 ? 'message' : 'messages'}`,
|
||||
toolCallCount: count => `${count} ${count === 1 ? 'tool call' : 'tool calls'}`,
|
||||
row: {
|
||||
pin: 'Pin',
|
||||
unpin: 'Unpin',
|
||||
|
||||
@@ -322,6 +322,11 @@ export const ja = defineLocale({
|
||||
uiScaleTitle: 'UI スケール',
|
||||
uiScaleDesc: (percent: number) =>
|
||||
`アプリ全体の文字と UI を拡大縮小します。Cmd/Ctrl と +、-、0 でも変更できます。現在: ${percent}%`,
|
||||
sessionDensityTitle: 'セッションリストの密度',
|
||||
sessionDensityDesc: 'サイドバーのセッションタイトルの下に表示する情報量を選びます。',
|
||||
sessionDensityCompact: 'コンパクト',
|
||||
sessionDensityComfortable: '標準',
|
||||
sessionDensityDetailed: '詳細',
|
||||
terminalFontTitle: 'ターミナルフォント',
|
||||
terminalFontDesc:
|
||||
'Desktop のターミナルで使用するインストール済みフォントを選びます。Nerd Font は Powerlevel10k とシェルアイコンを表示できます。空欄では内蔵の JetBrains Mono を使用します。',
|
||||
@@ -1787,6 +1792,8 @@ export const ja = defineLocale({
|
||||
loading: '読み込み中…',
|
||||
loadMore: 'さらに読み込む',
|
||||
loadCount: step => `さらに ${step} 件を読み込む`,
|
||||
messageCount: count => `${count} 件のメッセージ`,
|
||||
toolCallCount: count => `${count} 件のツール呼び出し`,
|
||||
row: {
|
||||
pin: 'ピン留め',
|
||||
unpin: 'ピン留めを解除',
|
||||
|
||||
@@ -365,6 +365,11 @@ export interface Translations {
|
||||
reasoningCollapsedDesc: string
|
||||
uiScaleTitle: string
|
||||
uiScaleDesc: (percent: number) => string
|
||||
sessionDensityTitle: string
|
||||
sessionDensityDesc: string
|
||||
sessionDensityCompact: string
|
||||
sessionDensityComfortable: string
|
||||
sessionDensityDetailed: string
|
||||
terminalFontTitle: string
|
||||
terminalFontDesc: string
|
||||
terminalFontPlaceholder: string
|
||||
@@ -1697,6 +1702,8 @@ export interface Translations {
|
||||
loading: string
|
||||
loadMore: string
|
||||
loadCount: (step: number) => string
|
||||
messageCount: (count: number) => string
|
||||
toolCallCount: (count: number) => string
|
||||
row: {
|
||||
pin: string
|
||||
unpin: string
|
||||
|
||||
@@ -314,6 +314,11 @@ export const zhHant = defineLocale({
|
||||
uiScaleTitle: '介面縮放',
|
||||
uiScaleDesc: (percent: number) =>
|
||||
`縮放整個應用程式的文字與介面。也可使用 Cmd/Ctrl 加 +、- 或 0 調整。目前:${percent}%`,
|
||||
sessionDensityTitle: '工作階段列表密度',
|
||||
sessionDensityDesc: '選擇側邊欄工作階段標題下方顯示的資訊量。',
|
||||
sessionDensityCompact: '緊湊',
|
||||
sessionDensityComfortable: '舒適',
|
||||
sessionDensityDetailed: '詳細',
|
||||
terminalFontTitle: '終端機字型',
|
||||
terminalFontDesc:
|
||||
'選擇已安裝的字型用於桌面端終端機。Nerd Font 可正確顯示 Powerlevel10k 與 Shell 圖示;留空則使用內建的 JetBrains Mono。',
|
||||
@@ -1729,6 +1734,8 @@ export const zhHant = defineLocale({
|
||||
loading: '載入中…',
|
||||
loadMore: '載入更多',
|
||||
loadCount: step => `再載入 ${step} 個`,
|
||||
messageCount: count => `${count} 條訊息`,
|
||||
toolCallCount: count => `${count} 次工具調用`,
|
||||
row: {
|
||||
pin: '釘選',
|
||||
unpin: '取消釘選',
|
||||
|
||||
@@ -453,6 +453,11 @@ export const zh: Translations = {
|
||||
uiScaleTitle: '界面缩放',
|
||||
uiScaleDesc: (percent: number) =>
|
||||
`缩放整个应用的文字和界面。也可使用 Cmd/Ctrl 加 +、- 或 0 调整。当前:${percent}%`,
|
||||
sessionDensityTitle: '会话列表密度',
|
||||
sessionDensityDesc: '选择侧边栏会话标题下方显示的信息量。',
|
||||
sessionDensityCompact: '紧凑',
|
||||
sessionDensityComfortable: '舒适',
|
||||
sessionDensityDetailed: '详细',
|
||||
terminalFontTitle: '终端字体',
|
||||
terminalFontDesc:
|
||||
'选择已安装的字体用于桌面端终端。Nerd Font 可正确显示 Powerlevel10k 和 Shell 图标;留空则使用内置的 JetBrains Mono。',
|
||||
@@ -2199,6 +2204,8 @@ export const zh: Translations = {
|
||||
loading: '加载中…',
|
||||
loadMore: '加载更多',
|
||||
loadCount: step => `再加载 ${step} 个`,
|
||||
messageCount: count => `${count} 条消息`,
|
||||
toolCallCount: count => `${count} 次工具调用`,
|
||||
row: {
|
||||
pin: '置顶',
|
||||
unpin: '取消置顶',
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const loadStore = async () => {
|
||||
vi.resetModules()
|
||||
|
||||
return import('./session-list-density')
|
||||
}
|
||||
|
||||
describe('session list density preference', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear()
|
||||
})
|
||||
|
||||
it('defaults to comfortable and persists changes', async () => {
|
||||
const first = await loadStore()
|
||||
|
||||
expect(first.$sessionListDensity.get()).toBe('comfortable')
|
||||
|
||||
first.setSessionListDensity('detailed')
|
||||
|
||||
expect(window.localStorage.getItem('hermes.desktop.sessionListDensity')).toBe('detailed')
|
||||
expect((await loadStore()).$sessionListDensity.get()).toBe('detailed')
|
||||
})
|
||||
|
||||
it('falls back to comfortable for an unknown stored value', async () => {
|
||||
window.localStorage.setItem('hermes.desktop.sessionListDensity', 'tiny')
|
||||
|
||||
expect((await loadStore()).$sessionListDensity.get()).toBe('comfortable')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type Codec, persistentAtom } from '@/lib/persisted'
|
||||
|
||||
export type SessionListDensity = 'compact' | 'comfortable' | 'detailed'
|
||||
|
||||
const STORAGE_KEY = 'hermes.desktop.sessionListDensity'
|
||||
|
||||
const densityCodec: Codec<SessionListDensity> = {
|
||||
decode: raw => (raw === 'compact' || raw === 'detailed' ? raw : 'comfortable'),
|
||||
encode: value => value
|
||||
}
|
||||
|
||||
export const $sessionListDensity = persistentAtom<SessionListDensity>(STORAGE_KEY, 'comfortable', densityCodec)
|
||||
|
||||
export function setSessionListDensity(density: SessionListDensity) {
|
||||
$sessionListDensity.set(density)
|
||||
}
|
||||
Reference in New Issue
Block a user