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.

fix(sidebar): styling for collapsed unread widget (#2645)

dev-rbd46b80ca0e21
diff --git a/js/app/packages/app/component/app-sidebar/channels-unread-widget.tsx b/js/app/packages/app/component/app-sidebar/channels-unread-widget.tsx
index 6180ab2891..d0e55c18c0 100644
--- a/js/app/packages/app/component/app-sidebar/channels-unread-widget.tsx
+++ b/js/app/packages/app/component/app-sidebar/channels-unread-widget.tsx
@@ -10,8 +10,7 @@ import {
on,
onMount,
} from 'solid-js';
-import ChannelIcon from '@macro-icons/wide/channel.svg?component-solid';
-import { UserGroup } from '@core/component/UserGroup';
+import { UserIcon } from '@core/component/UserIcon';
import { useSenderName } from '@app/component/app-sidebar/utils';
import { globalSplitManager } from '@app/signal/splitLayout';
import { compareDateDesc } from '@core/util/date';
@@ -23,8 +22,6 @@ import { isChannelNotification } from '@notifications/notification-helpers';
import type { SidebarState } from '@app/component/app-sidebar/sidebar';
import { cn } from '@ui/utils/classname';
import { Button } from '@ui/components/Button';
-import { useChannelsContext } from '@core/context/channels';
-import { useUserId } from '@core/context/user';
function getChannelInfo(notification: UnifiedNotification): {
channelName: string | null;
@@ -52,6 +49,36 @@ interface ChannelGroup {
latestSenderId: string | null;
}
+function computeChannelLetters(groups: ChannelGroup[]): Map<string, string> {
+ const result = new Map<string, string>();
+ const firstLetterCount = new Map<string, number>();
+
+ for (const group of groups) {
+ if (group.isDM || !group.channelName) continue;
+ const first = group.channelName[0]?.toUpperCase() ?? '';
+ firstLetterCount.set(first, (firstLetterCount.get(first) ?? 0) + 1);
+ }
+
+ for (const group of groups) {
+ if (group.isDM || !group.channelName) continue;
+ const name = group.channelName;
+ const first = name[0]?.toUpperCase() ?? '';
+ const needsTwo = (firstLetterCount.get(first) ?? 0) > 1 && name.length > 1;
+ const letters = needsTwo ? first + name[1].toUpperCase() : first;
+ result.set(group.entityId, letters);
+ }
+
+ return result;
+}
+
+function ChannelLetterIcon(props: { letters: string }) {
+ return (
+ <div class="size-full rounded-sm border border-ink/40 text-ink-muted flex items-center justify-center">
+ <span class="text-[10px] leading-none">{props.letters}</span>
+ </div>
+ );
+}
+
function groupByChannel(
notifications: UnifiedNotification[]
): Map<string, ChannelGroup> {
@@ -90,10 +117,9 @@ function ChannelGroupItem(props: {
group: ChannelGroup;
animate?: boolean;
isSlim?: boolean;
+ channelLetters?: string;
}) {
const [isVisible, setIsVisible] = createSignal(!props.animate);
- const { channelsById } = useChannelsContext();
- const currentUserId = useUserId();
onMount(() => {
if (props.animate) {
@@ -106,25 +132,8 @@ function ChannelGroupItem(props: {
const senderName = useSenderName(props.group.latestSenderId);
const count = () => props.group.notifications.length;
- const channelData = createMemo(() => channelsById()[props.group.entityId]);
-
- const isGroupOrDM = createMemo(() => {
- const channel = channelData();
- if (!channel) return false;
- return (
- channel.channel_type === 'direct_message' ||
- channel.channel_type === 'private'
- );
- });
-
- const otherParticipantIds = createMemo(() => {
- const channel = channelData();
- if (!channel?.participants) return [];
- const userId = currentUserId();
- return channel.participants
- .filter((p) => p.user_id !== userId && !p.left_at)
- .map((p) => p.user_id);
- });
+ const isDM = () => props.group.isDM;
+ const senderId = () => props.group.latestSenderId;
const displayName = () => {
if (props.group.isDM) {
@@ -191,19 +200,14 @@ function ChannelGroupItem(props: {
navigateToLatestNotification(e.shiftKey);
}}
>
- <div class="relative flex items-center justify-center flex-shrink-0">
+ <div class="relative flex items-center justify-center flex-shrink-0 size-5">
<Show
- when={isGroupOrDM() && otherParticipantIds().length > 0}
- fallback={
- <div class="text-ink-muted size-4">
- <ChannelIcon />
- </div>
- }
+ when={isDM() && senderId()}
+ fallback={<ChannelLetterIcon letters={props.channelLetters ?? '?'} />}
>
- <UserGroup
- userIds={otherParticipantIds()}
- size="xs"
- maxUsers={3}
+ <UserIcon
+ id={senderId()!}
+ size="fill"
suppressClick
showTooltip={false}
/>
@@ -304,6 +308,10 @@ export const ChannelsUnreadWidget = (props: { sidebarState: SidebarState }) => {
.filter((g): g is ChannelGroup => g != null);
});
+ const channelLettersMap = createMemo(() =>
+ computeChannelLetters(channelGroups())
+ );
+
const isSlim = () => props.sidebarState === 'slim';
const SLIM_MAX = 4;
const slimVisible = () => channelGroups().slice(0, SLIM_MAX);
@@ -317,7 +325,12 @@ export const ChannelsUnreadWidget = (props: { sidebarState: SidebarState }) => {
<section class="w-full py-2 px-2 flex flex-col items-center">
<For each={slimVisible()}>
{(group) => (
- <ChannelGroupItem group={group} animate={false} isSlim />
+ <ChannelGroupItem
+ group={group}
+ animate={false}
+ isSlim
+ channelLetters={channelLettersMap().get(group.entityId)}
+ />
)}
</For>
<Show when={slimOverflow() > 0}>
@@ -335,7 +348,13 @@ export const ChannelsUnreadWidget = (props: { sidebarState: SidebarState }) => {
<div class="flex-1">
<For each={channelGroups()}>
- {(group) => <ChannelGroupItem group={group} animate={false} />}
+ {(group) => (
+ <ChannelGroupItem
+ group={group}
+ animate={false}
+ channelLetters={channelLettersMap().get(group.entityId)}
+ />
+ )}
</For>
</div>
</section>