diff --git a/package.json b/package.json index 82b6906..537aaf2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "voipms-desktop", "productName": "bubble", - "version": "0.9.1", + "version": "0.9.2", "description": "Signal-style desktop SMS client for voip.ms", "author": "trav ", "private": true, diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 6d4d790..12651bc 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -21,6 +21,11 @@ export interface Jump { nonce: number } +/** Which chats the sidebar lists. */ +export type ListView = 'chats' | 'archived' | 'unread' + +export const isUnread = (c: Conversation): boolean => c.unread > 0 || c.markedUnread + export const sameConv = (a?: ConvKey | null, b?: ConvKey | null): boolean => !!a && !!b && a.did === b.did && a.contact === b.contact export function App() { @@ -34,7 +39,13 @@ export function App() { const [sync, setSync] = useState() const [settingsOpen, setSettingsOpen] = useState(false) const [msgVersion, setMsgVersion] = useState(0) - const [archiveView, setArchiveView] = useState(false) + const [view, setViewState] = useState('chats') + // The chat opened from the unread view: it stays listed (read now) until another is opened. + const [kept, setKept] = useState(null) + const setView = useCallback((v: ListView) => { + setViewState(v) + setKept(null) + }, []) const [info, setInfo] = useState(null) const [exporting, setExporting] = useState(null) const [adding, setAdding] = useState(null) @@ -60,6 +71,7 @@ export function App() { window.api.onOpenConversation((key) => { setMode('chats') setSelected(key) + setKept(key) setJump(undefined) }) ] @@ -78,6 +90,7 @@ export function App() { const open = useCallback((key: ConvKey, jumpTo?: number) => { setSelected(key) + setKept(key) setJump(jumpTo !== undefined ? { id: jumpTo, nonce: Date.now() } : undefined) }, []) @@ -85,7 +98,14 @@ export function App() { const onMarkUnread = useCallback((key: ConvKey) => setSelected((cur) => (sameConv(cur, key) ? null : cur)), []) // The list currently shown in the sidebar (for Alt+↑/↓). - const listed = useMemo(() => conversations.filter((c) => c.archived === archiveView), [conversations, archiveView]) + // The unread view takes archived chats too. + const listed = useMemo( + () => + conversations.filter((c) => + view === 'unread' ? isUnread(c) || sameConv(c, kept) : c.archived === (view === 'archived') + ), + [conversations, view, kept] + ) useEffect(() => setTooltipsEnabled(state?.settings.showTooltips !== false), [state?.settings.showTooltips]) // Which look the stylesheet draws (styles.css): the house look unless Signal vibes are chosen. @@ -103,10 +123,10 @@ export function App() { document.getElementById('sidebar-search')?.focus() } else if (c === 'newChat') setMode('compose') else if (c === 'preferences') setSettingsOpen(true) - else if (c === 'archived') setArchiveView((v) => !v) + else if (c === 'archived') setView(view === 'archived' ? 'chats' : 'archived') else if (c === 'checkNow') void window.api.pollNow() }), - [state?.configured] + [state?.configured, view, setView] ) // Keyboard shortcuts (Signal-like, plus the menu bar's). @@ -166,8 +186,9 @@ export function App() { gvNumber={state.gvoiceNumber} defaultDid={state.settings.defaultDid ?? smsDids[0]?.did} onSettings={() => setSettingsOpen(true)} - archiveView={archiveView} - setArchiveView={setArchiveView} + view={view} + setView={setView} + listed={listed} onMarkUnread={onMarkUnread} onInfo={setInfo} onExport={setExporting} diff --git a/src/renderer/src/components/Icons.tsx b/src/renderer/src/components/Icons.tsx index 6f23822..a0a67bc 100644 --- a/src/renderer/src/components/Icons.tsx +++ b/src/renderer/src/components/Icons.tsx @@ -90,6 +90,14 @@ export const ArchiveIcon = () => ( ) +// Three outlined bubbles of different sizes: the unread view. +export const BubblesIcon = () => ( + + + + + +) export const GroupIcon = () => ( diff --git a/src/renderer/src/components/Sidebar.tsx b/src/renderer/src/components/Sidebar.tsx index de5f1c0..f4ef37c 100644 --- a/src/renderer/src/components/Sidebar.tsx +++ b/src/renderer/src/components/Sidebar.tsx @@ -1,13 +1,20 @@ import { useEffect, useRef, useState, type CSSProperties, type PointerEvent as ReactPointerEvent } from 'react' import type { ContactInfo, Conversation, Did, SyncStatus } from '@shared/types' -import type { ConvKey } from '../App' +import type { ConvKey, ListView } from '../App' import { ConversationList } from './ConversationList' import { SearchResults } from './SearchResults' import { NewChat } from './NewChat' -import { ArchiveIcon, BackIcon, CloseIcon, ComposeIcon, GearIcon, RefreshIcon, SearchIcon } from './Icons' +import { ArchiveIcon, BackIcon, BubblesIcon, CloseIcon, ComposeIcon, GearIcon, RefreshIcon, SearchIcon } from './Icons' export type SidebarMode = 'chats' | 'search' | 'compose' +const VIEW_TITLE = { unread: 'Unread chats', archived: 'Archived chats' } as const +const EMPTY_TEXT: Record = { + chats: 'No conversations yet.', + archived: 'No archived chats. Right-click a chat to archive it.', + unread: 'No unread chats.' +} + // Dragging below the default width shrinks the sidebar's contents // proportionally (via --s) rather than dropping parts of each row. const DEFAULT_WIDTH = 340 @@ -100,8 +107,10 @@ interface Props { gvNumber?: string defaultDid?: string onSettings: () => void - archiveView: boolean - setArchiveView: (on: boolean) => void + view: ListView + setView: (v: ListView) => void + /** The chats the current view shows. */ + listed: Conversation[] onMarkUnread: (key: ConvKey) => void onInfo: (key: ConvKey) => void onExport: (key: ConvKey) => void @@ -176,17 +185,20 @@ export function Sidebar(p: Props) { - + {(['unread', 'archived'] as const).map((v) => ( + + ))} @@ -204,21 +216,21 @@ export function Sidebar(p: Props) { /> ) : ( <> - {p.archiveView && ( + {p.view !== 'chats' && (
- - Archived chats + {VIEW_TITLE[p.view]}
)} c.archived === p.archiveView)} + conversations={p.listed} contactMap={p.contactMap} selected={p.selected} multiDid={p.multiDid} gvNumber={p.gvNumber} - emptyText={p.archiveView ? 'No archived chats. Right-click a chat to archive it.' : 'No conversations yet.'} + emptyText={EMPTY_TEXT[p.view]} onOpen={p.onOpen} onMarkUnread={p.onMarkUnread} onInfo={p.onInfo}