Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chg(sidebar): rename channels widget -> latest, add unread toggle (#5469)

Seamus1767917944be
diff --git a/apps/web/src/components/app/app-sidebar/collapsible-sidebar-section.tsx b/apps/web/src/components/app/app-sidebar/collapsible-sidebar-section.tsx
index 667358ac75..8273d40e49 100644
--- a/apps/web/src/components/app/app-sidebar/collapsible-sidebar-section.tsx
+++ b/apps/web/src/components/app/app-sidebar/collapsible-sidebar-section.tsx
@@ -1,6 +1,7 @@
+import type { HotkeyToken } from '@core/hotkey/tokens';
import CaretDownIcon from '@phosphor/caret-down.svg';
import { makePersisted } from '@solid-primitives/storage';
-import { cn } from '@ui';
+import { cn, Tooltip } from '@ui';
import { createSignal, For, type JSX, onCleanup, Show } from 'solid-js';
export type CollapsibleSidebarSectionItem = {
@@ -12,7 +13,12 @@ export type CollapsibleSidebarSectionItem = {
export function CollapsibleSidebarSection(props: {
label: string;
items: readonly CollapsibleSidebarSectionItem[];
- headerMenu?: () => JSX.Element;
+ headerMenu?: (open: boolean) => JSX.Element;
+ headerWrapper?: (header: JSX.Element) => JSX.Element;
+ headerTooltip?: {
+ label: string;
+ hotkey?: HotkeyToken | HotkeyToken[];
+ };
defaultOpen?: boolean;
/** Persist the open state locally under this key. */
persistKey?: string;
@@ -43,31 +49,53 @@ export function CollapsibleSidebarSection(props: {
}, 130);
};
+ const headerButton = () => (
+ <button
+ type="button"
+ class={cn(
+ 'flex h-7 w-full min-w-0 items-center justify-start gap-1 rounded-md px-2 text-left text-[13px] font-medium text-ink-extra-muted/60 transition-colors group-hover/section:bg-ink/3 group-hover/section:text-ink-muted',
+ props.headerMenu ? 'pr-18' : 'pr-2'
+ )}
+ aria-expanded={open()}
+ onClick={toggleOpen}
+ >
+ <span class="min-w-0 truncate">{props.label}</span>
+ <CaretDownIcon
+ class={cn(
+ 'size-3 shrink-0 transition-transform duration-[120ms] ease-in-out',
+ !open() && '-rotate-90'
+ )}
+ />
+ </button>
+ );
+
+ const header = () => (
+ <header class="group/section relative">
+ <Show when={props.headerTooltip} fallback={headerButton()}>
+ {(tooltip) => (
+ <Tooltip
+ label={tooltip().label}
+ hotkey={tooltip().hotkey}
+ placement="right"
+ class="w-full"
+ >
+ {headerButton()}
+ </Tooltip>
+ )}
+ </Show>
+ <Show when={props.headerMenu}>
+ {(headerMenu) => (
+ <div class="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 z-10 flex items-center">
+ {headerMenu()(open())}
+ </div>
+ )}
+ </Show>
+ </header>
+ );
+
return (
- <section class="w-full flex flex-col">
- <header class="group/section relative">
- <button
- type="button"
- class="flex h-7 w-full min-w-0 items-center justify-start gap-1 rounded-md px-2 pr-9 text-left text-[13px] font-medium text-ink-extra-muted/60 transition-colors group-hover/section:bg-ink/3 group-hover/section:text-ink-muted"
- aria-expanded={open()}
- onClick={toggleOpen}
- >
- <span class="min-w-0 truncate">{props.label}</span>
- <CaretDownIcon
- class={cn(
- 'size-3 shrink-0 transition-transform duration-[120ms] ease-in-out',
- !open() && '-rotate-90'
- )}
- />
- </button>
- <Show when={props.headerMenu}>
- {(headerMenu) => (
- <div class="absolute right-1 top-1/2 -translate-y-1/2 flex items-center">
- {headerMenu()()}
- </div>
- )}
- </Show>
- </header>
+ <section class="group/sidebar-section w-full flex flex-col">
+ {props.headerWrapper ? props.headerWrapper(header()) : header()}
<div
class={cn('grid overflow-hidden', !open() && 'pointer-events-none')}
aria-hidden={!open()}
diff --git a/apps/web/src/components/app/app-sidebar/sidebar.tsx b/apps/web/src/components/app/app-sidebar/sidebar.tsx
index 4d63a9ce19..3a47d3e3d5 100644
--- a/apps/web/src/components/app/app-sidebar/sidebar.tsx
+++ b/apps/web/src/components/app/app-sidebar/sidebar.tsx
@@ -1245,6 +1245,13 @@ export const AppSidebar = (props: AppSidebarProps) => {
const findLink = (id: SidebarItem['id']) =>
allLinks().find((link) => link.id === id && !link.hiddenFromSidebar);
const searchLink = () => allLinks().find((link) => link.id === 'search');
+ const channelsLink = () => allLinks().find((link) => link.id === 'channels');
+ const channelsContent = () =>
+ ({
+ type: 'component',
+ id: 'channels',
+ params: channelsLink()?.params,
+ }) as const;
const renderSidebarLink = (link: SidebarItem) => (
<Dynamic
@@ -1483,12 +1490,14 @@ export const AppSidebar = (props: AppSidebarProps) => {
persistKey="workspace"
items={workspaceItems()}
headerMenu={() => (
- <SidebarSectionMenu
- label="Workspace"
- options={sectionMenuOptionsFor(WORKSPACE_LINK_IDS)}
- onToggle={toggleSectionVisibility}
- onOpenChange={handleWorkspaceContextMenuOpenChange}
- />
+ <div class="pointer-events-auto">
+ <SidebarSectionMenu
+ label="Workspace"
+ options={sectionMenuOptionsFor(WORKSPACE_LINK_IDS)}
+ onToggle={toggleSectionVisibility}
+ onOpenChange={handleWorkspaceContextMenuOpenChange}
+ />
+ </div>
)}
onOpenChange={scheduleMiddleScrollUpdate}
/>
@@ -1505,6 +1514,14 @@ export const AppSidebar = (props: AppSidebarProps) => {
sidebarState={sidebarDisplayState()}
onSectionOpenChange={scheduleMiddleScrollUpdate}
onDropdownOpenChange={handleOverlayDropdownOpenChange}
+ headerWrapper={(header) => (
+ <SidebarOpenInSplitMenu
+ content={channelsContent}
+ onOpenChange={handleOverlayDropdownOpenChange}
+ >
+ {header}
+ </SidebarOpenInSplitMenu>
+ )}
/>
</Suspense>
</div>
diff --git a/apps/web/src/components/ui/components/ToggleSwitch.tsx b/apps/web/src/components/ui/components/ToggleSwitch.tsx
index 9527b8c750..c4307e0528 100644
--- a/apps/web/src/components/ui/components/ToggleSwitch.tsx
+++ b/apps/web/src/components/ui/components/ToggleSwitch.tsx
@@ -12,11 +12,18 @@ export type ToggleSwitchProps = {
checked?: boolean;
/** Visual size. `sm` (default) is the compact toolbar size; `md` is larger,
* used in settings rows. */
- size?: 'sm' | 'md';
+ size?: 'xs' | 'sm' | 'md';
class?: string;
+ controlClass?: string;
};
const SWITCH_SIZES = {
+ xs: {
+ control: 'h-3.5 w-5.5',
+ thumb: 'top-0.5 left-0.5 h-2.5',
+ stretched: 'w-3 data-checked:translate-x-1.5',
+ normal: 'w-2.5 data-checked:translate-x-2',
+ },
sm: {
control: 'h-4 w-6',
thumb: 'top-0.5 left-0.5 h-3',
@@ -39,6 +46,7 @@ export const ToggleSwitch = (props: ToggleSwitchProps): JSX.Element => {
'disabled',
'checked',
'class',
+ 'controlClass',
'label',
'size',
]);
@@ -83,7 +91,8 @@ export const ToggleSwitch = (props: ToggleSwitchProps): JSX.Element => {
<KobalteSwitch.Control
class={cn(
'relative rounded-full bg-ink-muted/40 transition-colors duration-100 data-checked:bg-accent',
- sizing().control
+ sizing().control,
+ local.controlClass
)}
>
<KobalteSwitch.Thumb
diff --git a/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx b/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx
index 2243c2668e..77f5c31b0d 100644
--- a/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx
+++ b/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx
@@ -24,12 +24,7 @@ import {
} from '@core/component/ContextMenu';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { compareDateDesc } from '@core/util/date';
-import {
- type ChannelEntity,
- EntityRowIcon,
- isChannelEntity,
- UnreadIndicator,
-} from '@entity';
+import { type ChannelEntity, EntityRowIcon, isChannelEntity } from '@entity';
import { ContextMenu } from '@kobalte/core/context-menu';
import { Tooltip as KobalteTooltip } from '@kobalte/core/tooltip';
import { openNotification } from '@notifications';
@@ -40,19 +35,21 @@ import {
import { getChannelNotificationParams } from '@notifications/notification-navigation';
import type { UnifiedNotification } from '@notifications/types';
import { useSoupAstItemsQuery } from '@queries/soup/items';
-import { cn, NavRow, Surface, Tooltip } from '@ui';
+import { makePersisted } from '@solid-primitives/storage';
+import { cn, NavRow, Surface, ToggleSwitch, Tooltip } from '@ui';
import {
createEffect,
createMemo,
createSignal,
For,
+ type JSX,
onCleanup,
type ParentProps,
Show,
} from 'solid-js';
/** Rows the channel list shows before it scrolls internally. */
-const VISIBLE_CHANNEL_COUNT = 5;
+const VISIBLE_CHANNEL_COUNT = 12;
/**
* How long the user must be done scrolling the list before a new channel
* message snaps it back to the top.
@@ -70,6 +67,10 @@ interface RecentChannel {
unread: UnifiedNotification[];
}
+function unreadCountLabel(count: number): string {
+ return count > 99 ? '99+' : String(count);
+}
+
/**
* Open a channel like the soup list would: an unread channel opens at its
* newest unread message, a read one opens at the latest message.
@@ -200,6 +201,7 @@ function ChannelRow(props: {
const entity = () => props.channel.entity;
const isUnread = () => props.channel.unread.length > 0;
+ const unreadCount = () => props.channel.unread.length;
const isSlim = () => props.isSlim ?? false;
const canOpenInNewSplit = () =>
@@ -231,7 +233,9 @@ function ChannelRow(props: {
<EntityRowIcon entity={entity()} suppressClick showTooltip={false} />
</div>
<Show when={isSlim() && isUnread()}>
- <div class="absolute -top-0.5 -right-0.5 size-1.5 bg-accent rounded-full ring-surface ring-2" />
+ <span class="absolute -top-1.5 -right-1.5 min-w-3.5 h-3.5 px-0.5 flex items-center justify-center text-[9px] leading-none font-medium bg-accent text-surface rounded-full ring-surface ring-2">
+ {unreadCountLabel(unreadCount())}
+ </span>
</Show>
</div>
@@ -241,7 +245,9 @@ function ChannelRow(props: {
</span>
</Show>
<Show when={!isSlim() && isUnread()}>
- <UnreadIndicator active />
+ <span class="ml-auto shrink-0 min-w-5 h-5 px-1.5 flex items-center justify-center text-xs font-medium bg-ink/6 text-ink-muted rounded-md">
+ {unreadCountLabel(unreadCount())}
+ </span>
</Show>
</NavRow>
);
@@ -307,8 +313,12 @@ export const ChannelsRecentWidget = (props: {
maxVisible?: number;
onSectionOpenChange?: () => void;
onDropdownOpenChange?: (open: boolean) => void;
+ headerWrapper?: (header: JSX.Element) => JSX.Element;
}) => {
const notificationSource = useGlobalNotificationSource();
+ const [unreadOnly, setUnreadOnly] = makePersisted(createSignal(false), {
+ name: 'sidebar-recent-channels-unread-only',
+ });
const channelsQuery = useSoupAstItemsQuery(
() => ({
@@ -359,6 +369,15 @@ export const ChannelsRecentWidget = (props: {
...channels.filter((channel) => channel.unread.length === 0),
];
});
+ const visibleChannels = createMemo(() =>
+ unreadOnly()
+ ? recentChannels().filter((channel) => channel.unread.length > 0)
+ : recentChannels()
+ );
+ const showAllCaughtUp = () =>
+ unreadOnly() &&
+ recentChannels().length > 0 &&
+ visibleChannels().length === 0;
const maxVisible = () => props.maxVisible ?? VISIBLE_CHANNEL_COUNT;
// The list shows `maxVisible` rows (h-7 rows, gap-0.5) and scrolls inside
@@ -401,7 +420,7 @@ export const ChannelsRecentWidget = (props: {
// Overflow can change without a scroll event (channels load in, rows are
// removed, the visible-row cap changes), so re-check when those change too.
createEffect(() => {
- recentChannels();
+ visibleChannels();
maxVisible();
scheduleListScrollUpdate();
});
@@ -444,7 +463,7 @@ export const ChannelsRecentWidget = (props: {
lastUserScrollAt = Date.now();
}}
>
- <For each={recentChannels()}>
+ <For each={visibleChannels()}>
{(channel) => (
<ChannelRow
channel={channel}
@@ -452,6 +471,11 @@ export const ChannelsRecentWidget = (props: {
/>
)}
</For>
+ <Show when={showAllCaughtUp()}>
+ <div class="flex h-7 w-full items-center gap-2 px-2 py-1 text-sm font-medium text-ink-extra-muted/60">
+ <span class="truncate">All caught up</span>
+ </div>
+ </Show>
</div>
<div
class={cn(
@@ -491,9 +515,38 @@ export const ChannelsRecentWidget = (props: {
>
<Show when={recentChannels().length > 0}>
<CollapsibleSidebarSection
- label="Channels"
+ label="Latest"
persistKey="recent-channels"
items={sectionItems()}
+ headerWrapper={props.headerWrapper}
+ headerMenu={(open) => (
+ <Show when={open}>
+ <Tooltip
+ label="Toggle unread filter"
+ placement="top"
+ class="pointer-events-none rounded-full opacity-0 transition-opacity duration-100 group-hover/sidebar-section:pointer-events-auto group-hover/sidebar-section:opacity-100"
+ >
+ <div
+ onMouseDown={(event) => event.stopPropagation()}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <ToggleSwitch
+ checked={unreadOnly()}
+ onChange={setUnreadOnly}
+ size="xs"
+ label={
+ <span class="text-[11px] font-medium leading-none text-ink-extra-muted/60">
+ Unread
+ </span>
+ }
+ labelClass="flex items-center"
+ controlClass="bg-ink-extra-muted/25 data-checked:bg-accent"
+ class="flex-row-reverse gap-1 rounded-full px-1.5 py-1"
+ />
+ </div>
+ </Tooltip>
+ </Show>
+ )}
onOpenChange={() => props.onSectionOpenChange?.()}
/>
</Show>