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.

style(calls): use active call layout logic for incoming calls (#4900)

Seamus35d3837c0cf2
diff --git a/apps/web/src/components/app/Layout.tsx b/apps/web/src/components/app/Layout.tsx
index 4a1a0266d7..b28abfc17c 100644
--- a/apps/web/src/components/app/Layout.tsx
+++ b/apps/web/src/components/app/Layout.tsx
@@ -2,7 +2,11 @@ import { ROUTER_BASE_CONCAT } from '@app/constants/routerBase';
import Banner from '@app/features/auth/banner/Banner';
import { GithubReauthenticationPrompt } from '@app/features/auth/GithubReauthenticationPrompt';
import { GmailReauthenticationPrompt } from '@app/features/auth/GmailReauthenticationPrompt';
-import { SidebarActiveCallWidget } from '@app/features/block-call/sidebar/active-call-widget';
+import {
+ IncomingCallWidgetEvents,
+ SidebarActiveCallWidget,
+ useIncomingCallWidgetVisible,
+} from '@app/features/block-call/sidebar/active-call-widget';
import { CommandMenu } from '@app/features/command';
import { FavoritesCommands } from '@app/features/command/FavoritesCommands';
import {
@@ -112,12 +116,17 @@ export function Layout(props: RouteSectionProps) {
);
}
-function CollapsedSidebarCallWidget(props: { visible: boolean }) {
+function DraggableCallWidget(props: {
+ visible: boolean;
+ dragLabel: string;
+ defaultBottomGap?: number;
+ children: JSX.Element;
+}) {
const EDGE_GAP = 12;
- const DEFAULT_BOTTOM_GAP = 12;
const [root, setRoot] = createSignal<HTMLDivElement>();
const [dragging, setDragging] = createSignal(false);
const [position, setPosition] = createSignal<{ left: number; top: number }>();
+ const defaultBottomGap = () => props.defaultBottomGap ?? 12;
const clampPosition = (next: { left: number; top: number }) => {
const el = root();
@@ -138,20 +147,21 @@ function CollapsedSidebarCallWidget(props: { visible: boolean }) {
};
};
- const resetToDefaultPosition = () => {
+ const resetToDefaultPosition = (bottomGap = defaultBottomGap()) => {
const el = root();
if (!el) return;
setPosition(
clampPosition({
left: Math.round((window.innerWidth - el.offsetWidth) / 2),
- top: window.innerHeight - el.offsetHeight - DEFAULT_BOTTOM_GAP,
+ top: window.innerHeight - el.offsetHeight - bottomGap,
})
);
};
createEffect(() => {
if (!props.visible) return;
- requestAnimationFrame(() => resetToDefaultPosition());
+ const bottomGap = defaultBottomGap();
+ requestAnimationFrame(() => resetToDefaultPosition(bottomGap));
});
createEffect(() => {
@@ -213,27 +223,53 @@ function CollapsedSidebarCallWidget(props: { visible: boolean }) {
style={{
left: position() ? `${position()!.left}px` : '50%',
top: position() ? `${position()!.top}px` : undefined,
- bottom: position() ? undefined : `${DEFAULT_BOTTOM_GAP}px`,
+ bottom: position() ? undefined : `${defaultBottomGap()}px`,
transform: position() ? undefined : 'translateX(-50%)',
}}
>
<div class="relative rounded-xl border border-edge-muted bg-surface shadow-menu p-1">
<button
type="button"
- aria-label="Drag to move active call controls"
+ aria-label={props.dragLabel}
class={cn(
'absolute left-1 right-10 top-1 z-10 h-8 rounded-t-lg rounded-b-md bg-transparent select-none',
dragging() ? 'cursor-grabbing' : 'cursor-grab'
)}
onPointerDown={startDrag}
/>
- <InCallPanel isSlim={() => false} />
+ {props.children}
</div>
</div>
</Show>
);
}
+function CollapsedSidebarCallWidget(props: { visible: boolean }) {
+ return (
+ <DraggableCallWidget
+ visible={props.visible}
+ dragLabel="Drag to move active call controls"
+ >
+ <InCallPanel isSlim={() => false} />
+ </DraggableCallWidget>
+ );
+}
+
+function CollapsedSidebarIncomingCallWidget(props: {
+ visible: boolean;
+ activeCallWidgetVisible: boolean;
+}) {
+ return (
+ <DraggableCallWidget
+ visible={props.visible}
+ dragLabel="Drag to move incoming calls"
+ defaultBottomGap={props.activeCallWidgetVisible ? 168 : 12}
+ >
+ <SidebarActiveCallWidget sidebarState="expanded" />
+ </DraggableCallWidget>
+ );
+}
+
function LayoutInner(props: RouteSectionProps) {
const isAuthenticated = useIsAuthenticated();
const { paywallOpen, showPaywall } = usePaywallState();
@@ -242,9 +278,17 @@ function LayoutInner(props: RouteSectionProps) {
const [sidebarOverlayTriggerHovered, setSidebarOverlayTriggerHovered] =
createSignal(false);
const callCtx = useCallContextOptional();
+ const incomingCallWidgetVisible = useIncomingCallWidgetVisible();
const sidebarCollapsed = createMemo(
() => isSidebarVisible() && sidebarState() === 'slim'
);
+ const activeCallWidgetVisible = createMemo(
+ () =>
+ isSidebarVisible() &&
+ sidebarState() === 'slim' &&
+ !!callCtx?.isInCall() &&
+ !callCtx?.isCallPage()
+ );
let sidebarOverlayCloseTimer: ReturnType<typeof setTimeout> | undefined;
const clearSidebarOverlayCloseTimer = () => {
@@ -326,6 +370,9 @@ function LayoutInner(props: RouteSectionProps) {
<CommandMenu />
</Suspense>
</Show>
+ <Show when={isSidebarVisible()}>
+ <IncomingCallWidgetEvents />
+ </Show>
<Suspense>
<PropertyEditorModal />
</Suspense>
@@ -392,27 +439,15 @@ function LayoutInner(props: RouteSectionProps) {
</div>
</ItemDndProvider>
</div>
- <Show when={isSidebarVisible()}>
- <div
- class="fixed bottom-3 z-page-overlay w-64 flex flex-col gap-2 transition-[left] duration-[120ms] ease-in-out"
- style={{
- left: sidebarState() === 'expanded' ? '15.75rem' : '0.75rem',
- }}
- >
- <SidebarActiveCallWidget
- sidebarState="expanded"
- class="rounded-xl border border-edge-muted bg-surface shadow-menu p-1"
- />
- </div>
- </Show>
- <CollapsedSidebarCallWidget
+ <CollapsedSidebarIncomingCallWidget
visible={
isSidebarVisible() &&
sidebarState() === 'slim' &&
- !!callCtx?.isInCall() &&
- !callCtx?.isCallPage()
+ incomingCallWidgetVisible()
}
+ activeCallWidgetVisible={activeCallWidgetVisible()}
/>
+ <CollapsedSidebarCallWidget visible={activeCallWidgetVisible()} />
<Show
when={
isMobile() &&
diff --git a/apps/web/src/components/app/app-sidebar/sidebar.tsx b/apps/web/src/components/app/app-sidebar/sidebar.tsx
index 0fcb2ac7b2..a3430af924 100644
--- a/apps/web/src/components/app/app-sidebar/sidebar.tsx
+++ b/apps/web/src/components/app/app-sidebar/sidebar.tsx
@@ -1,5 +1,6 @@
import { GO_TO_COMMAND_SCOPE, GO_TO_LEADER_KEY } from '@app/constants/hotkeys';
import { LIST_VIEW_PATHS, type ListView } from '@app/constants/list-views';
+import { SidebarActiveCallWidget } from '@app/features/block-call/sidebar/active-call-widget';
import { ChannelsUnreadWidget } from '@app/features/channel/sidebar/channels-unread-widget';
import { CommandState } from '@app/features/command';
import { SidebarCreateMenu } from '@app/features/command/sidebar/sidebar-create-menu';
@@ -1409,6 +1410,12 @@ export const AppSidebar = (props: AppSidebarProps) => {
</div>
<div class="shrink-0 w-full pt-2 flex flex-col gap-2">
+ <Show when={isExpandedView()}>
+ <SidebarActiveCallWidget
+ sidebarState="expanded"
+ class="rounded-xl border border-edge-muted bg-surface shadow-menu p-1"
+ />
+ </Show>
<Show when={isExpandedView() && callCtx?.isInCall()}>
<div data-ui="sidebar-in-call-panel">
<InCallPanel isSlim={() => false} />
diff --git a/apps/web/src/features/block-call/sidebar/active-call-widget.tsx b/apps/web/src/features/block-call/sidebar/active-call-widget.tsx
index 8ebc54d21c..ee34c2c260 100644
--- a/apps/web/src/features/block-call/sidebar/active-call-widget.tsx
+++ b/apps/web/src/features/block-call/sidebar/active-call-widget.tsx
@@ -4,16 +4,18 @@ import { joinChannelCall } from '@channel/Call/join-channel-call';
import { openChannelCallTab } from '@channel/Call/open-channel-call-tab';
import type { SidebarState } from '@components/app/app-sidebar/sidebar';
import { ContextMenuContent, MenuItem } from '@core/component/ContextMenu';
-import { ENABLE_CALLS } from '@core/constant/featureFlags';
+import { DEV_MODE_ENV, ENABLE_CALLS } from '@core/constant/featureFlags';
import { useChannelsContext } from '@core/context/channels';
import { useUserId } from '@core/context/user';
import PhoneIcon from '@icon/wide-call.svg';
import { ContextMenu } from '@kobalte/core/context-menu';
+import XIcon from '@phosphor/x.svg';
import { createConnectionWebsocketEffect } from '@service-connection/websocket';
import type { ApiChannelWithLatest } from '@service-storage/channel-list-types';
import { ChannelTypeEnum } from '@service-storage/client';
import { Avatar, Button, cn, Tooltip } from '@ui';
import {
+ type Accessor,
createEffect,
createMemo,
createSignal,
@@ -44,6 +46,25 @@ type CallEndedPayload = {
call_id?: string;
};
+type DebugIncomingCallOptions = {
+ channelId?: string;
+ callId?: string;
+ createdAt?: string;
+ createdBy?: string | null;
+};
+
+declare global {
+ interface Window {
+ macroDebugIncomingCall?: (
+ options?: DebugIncomingCallOptions
+ ) => IncomingCall | null;
+ macroClearDebugIncomingCalls?: () => void;
+ }
+}
+
+const [incomingCalls, setIncomingCalls] = createSignal<IncomingCall[]>([]);
+const incomingCallTimeouts = new Map<string, number>();
+
function displayName(channel: ApiChannelWithLatest | undefined) {
if (!channel) return 'Channel';
if (channel.channel_type === ChannelTypeEnum.DirectMessage) {
@@ -58,8 +79,8 @@ function ChannelCallBadge(props: {
slim: boolean;
}) {
return (
- <div class="relative flex items-center justify-center shrink-0 size-5">
- <Avatar size="md" class="bg-ink-extra-muted/15 text-ink-muted">
+ <div class="relative flex items-center justify-center shrink-0 size-[22px]">
+ <Avatar size="fill" class="bg-ink-extra-muted/15 text-ink-muted">
<Avatar.Fallback class="font-semibold">{props.letters}</Avatar.Fallback>
</Avatar>
<Show when={props.slim}>
@@ -177,63 +198,126 @@ const IncomingCallContextMenu: FlowComponent<IncomingCallContextMenuProps> = (
);
};
-export function SidebarActiveCallWidget(props: {
- sidebarState: SidebarState;
- class?: string;
-}) {
- const channelsCtx = useChannelsContext();
- const callCtx = useCallContextOptional();
- const userId = useUserId();
- const [incomingCalls, setIncomingCalls] = createSignal<IncomingCall[]>([]);
- const incomingCallTimeouts = new Map<string, number>();
- const [nowMs, setNowMs] = createSignal(Date.now());
- const durationTimer = globalThis.setInterval(
- () => setNowMs(Date.now()),
- 1000
+function clearIncomingCallTimeouts() {
+ for (const timeoutId of incomingCallTimeouts.values()) {
+ window.clearTimeout(timeoutId);
+ }
+ incomingCallTimeouts.clear();
+}
+
+function dismissIncomingCall(callId: string) {
+ stopCallRinger(callId);
+ const timeoutId = incomingCallTimeouts.get(callId);
+ if (timeoutId !== undefined) {
+ window.clearTimeout(timeoutId);
+ incomingCallTimeouts.delete(callId);
+ }
+ setIncomingCalls((calls) => calls.filter((call) => call.callId !== callId));
+}
+
+function addIncomingCall(call: IncomingCall) {
+ const existingTimeoutId = incomingCallTimeouts.get(call.callId);
+ if (existingTimeoutId !== undefined) {
+ window.clearTimeout(existingTimeoutId);
+ }
+ incomingCallTimeouts.set(
+ call.callId,
+ window.setTimeout(
+ () => dismissIncomingCall(call.callId),
+ MAX_RING_DURATION_MS
+ )
);
- onCleanup(() => {
- globalThis.clearInterval(durationTimer);
- for (const timeoutId of incomingCallTimeouts.values()) {
- window.clearTimeout(timeoutId);
- }
- incomingCallTimeouts.clear();
+
+ setIncomingCalls((calls) => {
+ const withoutDuplicate = calls.filter(
+ (candidate) =>
+ candidate.callId !== call.callId &&
+ candidate.channelId !== call.channelId
+ );
+ return [call, ...withoutDuplicate].sort(
+ (a, b) =>
+ new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
+ );
});
+}
- const dismissIncomingCall = (callId: string) => {
- stopCallRinger(callId);
- const timeoutId = incomingCallTimeouts.get(callId);
- if (timeoutId !== undefined) {
- window.clearTimeout(timeoutId);
- incomingCallTimeouts.delete(callId);
- }
- setIncomingCalls((calls) => calls.filter((call) => call.callId !== callId));
- };
+function useVisibleIncomingCalls(): Accessor<IncomingCall[]> {
+ const channelsCtx = useChannelsContext();
+ const callCtx = useCallContextOptional();
- const addIncomingCall = (call: IncomingCall) => {
- const existingTimeoutId = incomingCallTimeouts.get(call.callId);
- if (existingTimeoutId !== undefined) {
- window.clearTimeout(existingTimeoutId);
- }
- incomingCallTimeouts.set(
- call.callId,
- window.setTimeout(
- () => dismissIncomingCall(call.callId),
- MAX_RING_DURATION_MS
- )
- );
+ return createMemo(() => {
+ const channelsById = channelsCtx.channelsById();
+ const joinedChannelId = callCtx?.isInCall()
+ ? callCtx.activeChannelId()
+ : null;
+ const joinedCallId = callCtx?.isInCall() ? callCtx.activeCallId() : null;
- setIncomingCalls((calls) => {
- const withoutDuplicate = calls.filter(
- (candidate) =>
- candidate.callId !== call.callId &&
- candidate.channelId !== call.channelId
- );
- return [call, ...withoutDuplicate].sort(
+ return incomingCalls()
+ .filter((call) => {
+ if (!channelsById[call.channelId]) return false;
+ return (
+ call.channelId !== joinedChannelId && call.callId !== joinedCallId
+ );
+ })
+ .sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
);
+ });
+}
+
+export function useIncomingCallWidgetVisible() {
+ const visibleIncomingCalls = useVisibleIncomingCalls();
+ return createMemo(() => visibleIncomingCalls().length > 0);
+}
+
+export function IncomingCallWidgetEvents() {
+ const callCtx = useCallContextOptional();
+ const channelsCtx = useChannelsContext();
+ const userId = useUserId();
+
+ createEffect(() => {
+ if (!DEV_MODE_ENV) return;
+
+ window.macroDebugIncomingCall = (options = {}) => {
+ const channelsById = channelsCtx.channelsById();
+ const channelId = options.channelId ?? Object.keys(channelsById)[0];
+
+ if (!channelId || !channelsById[channelId]) {
+ console.warn(
+ '[incoming-call-widget] No cached channel found for debug call',
+ options
+ );
+ return null;
+ }
+
+ const call = {
+ channelId,
+ callId:
+ options.callId ??
+ `debug-${globalThis.crypto?.randomUUID?.() ?? Date.now()}`,
+ createdAt: options.createdAt ?? new Date().toISOString(),
+ createdBy: options.createdBy ?? 'debug',
+ };
+ addIncomingCall(call);
+ return call;
+ };
+
+ window.macroClearDebugIncomingCalls = () => {
+ clearIncomingCallTimeouts();
+ setIncomingCalls([]);
+ };
+
+ onCleanup(() => {
+ delete window.macroDebugIncomingCall;
+ delete window.macroClearDebugIncomingCalls;
});
- };
+ });
+
+ onCleanup(() => {
+ clearIncomingCallTimeouts();
+ setIncomingCalls([]);
+ });
createEffect(() => {
const activeCallId = callCtx?.activeCallId();
@@ -274,25 +358,23 @@ export function SidebarActiveCallWidget(props: {
});
});
- const activeCalls = createMemo(() => {
- const channelsById = channelsCtx.channelsById();
- const joinedChannelId = callCtx?.isInCall()
- ? callCtx.activeChannelId()
- : null;
- const joinedCallId = callCtx?.isInCall() ? callCtx.activeCallId() : null;
+ return null;
+}
- return incomingCalls()
- .filter((call) => {
- if (!channelsById[call.channelId]) return false;
- return (
- call.channelId !== joinedChannelId && call.callId !== joinedCallId
- );
- })
- .sort(
- (a, b) =>
- new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
- );
- });
+export function SidebarActiveCallWidget(props: {
+ sidebarState: SidebarState;
+ class?: string;
+}) {
+ const channelsCtx = useChannelsContext();
+ const userId = useUserId();
+ const [nowMs, setNowMs] = createSignal(Date.now());
+ const durationTimer = globalThis.setInterval(
+ () => setNowMs(Date.now()),
+ 1000
+ );
+ onCleanup(() => globalThis.clearInterval(durationTimer));
+
+ const activeCalls = useVisibleIncomingCalls();
const activeCallChannels = createMemo(() =>
activeCalls().map((call) => ({
@@ -370,13 +452,10 @@ export function SidebarActiveCallWidget(props: {
}
>
<section
- class={cn(
- 'size-full flex flex-col justify-center px-2 py-1.5',
- props.class
- )}
+ class={cn('size-full flex flex-col justify-center', props.class)}
>
- <header class="text-xs font-medium text-ink-muted ml-2 mb-1 whitespace-nowrap">
- <h1>Incoming calls</h1>
+ <header class="text-xs font-medium text-ink-muted whitespace-nowrap p-2">
+ <h1>Incoming call</h1>
</header>
<div class="flex-1 w-full">
@@ -391,43 +470,90 @@ export function SidebarActiveCallWidget(props: {
? `${displayName(channel())} call - ${time}`
: `${displayName(channel())} call`;
};
+ const dismissLabel = () =>
+ `Dismiss ${displayName(channel())} call`;
+ const openCall = () => {
+ void openChannelCallTab(call.channelId);
+ };
+
return (
- <div class="w-full h-8">
+ <div class="w-full">
<IncomingCallContextMenu
callId={call.callId}
channelId={call.channelId}
onDismiss={() => dismissIncomingCall(call.callId)}
>
- <Tooltip class="w-full" label={label()} placement="right">
- <Button
- class={cn(
- 'flex items-center cursor-default rounded-md text-ink-extra-muted not-disabled:hover:bg-ink/3',
- 'justify-start gap-2 w-full h-8 py-1'
- )}
+ <div class="flex items-center gap-1.5 w-full rounded-lg p-2 text-ink-extra-muted hover:bg-ink/3">
+ <Tooltip
+ class="min-w-0 flex-1"
+ label={label()}
+ placement="right"
+ >
+ <button
+ type="button"
+ class="flex min-w-0 flex-1 items-center justify-start gap-2 cursor-default"
+ draggable={false}
+ onMouseDown={(e) => {
+ if (e.button !== 0) return;
+ e.preventDefault();
+ }}
+ onClick={(e) => {
+ e.preventDefault();
+ openCall();
+ }}
+ >
+ <ChannelCallBadge
+ channel={channel()}
+ letters={
+ channelLetters().get(call.channelId) ?? '?'
+ }
+ slim={false}
+ />
+ <span class="text-sm font-medium truncate">
+ {displayName(channel())}
+ </span>
+ </button>
+ </Tooltip>
+ <button
+ type="button"
+ aria-label={label()}
+ class="shrink-0 size-5 flex items-center justify-center text-xs font-medium bg-success/15 text-success rounded-md"
draggable={false}
- variant="ghost"
- size="sm"
onMouseDown={(e) => {
if (e.button !== 0) return;
e.preventDefault();
- void openChannelCallTab(call.channelId);
+ e.stopPropagation();
+ }}
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ openCall();
}}
>
- <ChannelCallBadge
- channel={channel()}
- letters={
- channelLetters().get(call.channelId) ?? '?'
- }
- slim={false}
- />
- <span class="text-sm font-medium truncate">
- {displayName(channel())}
- </span>
- <span class="shrink-0 size-5 flex items-center justify-center text-xs font-medium bg-success/15 text-success rounded-md ml-auto">
- <PhoneIcon class="size-3" />
- </span>
- </Button>
- </Tooltip>
+ <PhoneIcon class="size-3" />
+ </button>
+ <Tooltip label={dismissLabel()} placement="right">
+ <Button
+ aria-label={dismissLabel()}
+ class="shrink-0 size-5 p-0 flex items-center justify-center rounded-md bg-ink-muted/10 text-ink-muted/80 not-disabled:hover:bg-failure/10 not-disabled:hover:text-failure"
+ draggable={false}
+ variant="ghost"
+ size="sm"
+ onMouseDown={(e) => {
+ if (e.button !== 0) return;
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ dismissIncomingCall(call.callId);
+ }}
+ >
+ <XIcon class="size-3" />
+ </Button>
+ </Tooltip>
+ </div>
</IncomingCallContextMenu>
</div>
);