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.

feat(channels): fade out target highlighting (#5579)

Peter Chinmancbc37fc8bdd7
diff --git a/apps/web/src/features/channel/Channel/create-target-message-controller.ts b/apps/web/src/features/channel/Channel/create-target-message-controller.ts
index c047158f5f..5c6419eeea 100644
--- a/apps/web/src/features/channel/Channel/create-target-message-controller.ts
+++ b/apps/web/src/features/channel/Channel/create-target-message-controller.ts
@@ -3,10 +3,18 @@ import {
getChannelMessagesQueryKey,
} from '@queries/channel/channel-messages';
import { queryClient } from '@queries/client';
-import { type Accessor, createEffect, on } from 'solid-js';
+import { type Accessor, createEffect, on, onCleanup } from 'solid-js';
import { createStore } from 'solid-js/store';
import type { ThreadListNavigation } from './ThreadList';
+/**
+ * How long a navigation target keeps its accent highlight after its scroll
+ * has positioned it on screen. When the flash elapses the target releases
+ * itself; highlights owned by other state (e.g. the unified input's reply
+ * binding) are unaffected.
+ */
+export const TARGETED_MESSAGE_FLASH_MS = 1000;
+
type CreateTargetMessageControllerOptions = {
channelId: Accessor<string>;
initialTargetMessageId?: string | undefined;
@@ -50,6 +58,40 @@ export function createTargetMessageController(
const [targetMessageData, setTargetMessageData] =
createStore<TargetMessageData>(initialTargetMessageData);
+ let flashTimeout: ReturnType<typeof setTimeout> | undefined;
+
+ const cancelFlash = () => {
+ if (flashTimeout === undefined) return;
+ clearTimeout(flashTimeout);
+ flashTimeout = undefined;
+ };
+
+ const syncFlash = () => {
+ cancelFlash();
+
+ const activeTargetMessageId = targetMessageData['activeTargetMessageId'];
+ const hasPendingScroll =
+ targetMessageData['pendingScrollTargetId'] !== undefined ||
+ targetMessageData['pendingTargetReplyId'] !== undefined;
+
+ if (!activeTargetMessageId || hasPendingScroll) return;
+
+ flashTimeout = setTimeout(() => {
+ flashTimeout = undefined;
+ clearActiveTarget(activeTargetMessageId);
+ }, TARGETED_MESSAGE_FLASH_MS);
+ };
+
+ // Highlight and scroll-state changes go through this function so the flash
+ // timer stays synchronized. loadAroundMessageId does not affect highlighting,
+ // so it can be updated directly with setTargetMessageData.
+ const updateTargetMessageData = (patch: Partial<TargetMessageData>) => {
+ setTargetMessageData(patch);
+ syncFlash();
+ };
+
+ onCleanup(cancelFlash);
+
const hasMessageLoaded = (messageId: string) =>
options.messageKeys().includes(messageId);
@@ -62,7 +104,7 @@ export function createTargetMessageController(
if (isSameTarget && isSameReplyTarget && isPending) return;
- setTargetMessageData({
+ updateTargetMessageData({
activeTargetMessageId: messageId,
activeTargetMessageReplyId: replyId,
// TODO: need a better approach where the load around should be undefined
@@ -77,13 +119,13 @@ export function createTargetMessageController(
const completePendingScroll = (messageId: string) => {
if (targetMessageData['pendingScrollTargetId'] !== messageId) return;
- setTargetMessageData('pendingScrollTargetId', undefined);
+ updateTargetMessageData({ pendingScrollTargetId: undefined });
};
const completePendingReplyScroll = (messageId: string, replyId: string) => {
if (targetMessageData['activeTargetMessageId'] !== messageId) return;
if (targetMessageData['pendingTargetReplyId'] !== replyId) return;
- setTargetMessageData('pendingTargetReplyId', undefined);
+ updateTargetMessageData({ pendingTargetReplyId: undefined });
};
createEffect(
@@ -129,7 +171,7 @@ export function createTargetMessageController(
);
const reset = () => {
- setTargetMessageData({
+ updateTargetMessageData({
activeTargetMessageId: undefined,
activeTargetMessageReplyId: undefined,
loadAroundMessageId: undefined,
@@ -143,15 +185,15 @@ export function createTargetMessageController(
* `messageId`; no-op if navigation has since moved elsewhere. Leaves
* `loadAroundMessageId` untouched so pagination is not disturbed.
*/
- const clearActiveTarget = (messageId: string) => {
+ function clearActiveTarget(messageId: string) {
if (targetMessageData['activeTargetMessageId'] !== messageId) return;
- setTargetMessageData({
+ updateTargetMessageData({
activeTargetMessageId: undefined,
activeTargetMessageReplyId: undefined,
pendingScrollTargetId: undefined,
pendingTargetReplyId: undefined,
});
- };
+ }
return {
activeTargetMessageId: () => targetMessageData['activeTargetMessageId'],
diff --git a/apps/web/src/features/channel/Channel/tests/create-target-message-controller.test.ts b/apps/web/src/features/channel/Channel/tests/create-target-message-controller.test.ts
index 7b90be369c..60b52cd223 100644
--- a/apps/web/src/features/channel/Channel/tests/create-target-message-controller.test.ts
+++ b/apps/web/src/features/channel/Channel/tests/create-target-message-controller.test.ts
@@ -13,10 +13,12 @@ import {
import {
createTargetMessageController,
restoreDefaultChannelPaginationAfterTargetLoad,
+ TARGETED_MESSAGE_FLASH_MS,
} from '../create-target-message-controller';
afterEach(() => {
queryClient.clear();
+ vi.useRealTimers();
});
function createController(
@@ -155,6 +157,86 @@ describe('createTargetMessageController', () => {
dispose();
});
+ it('releases a root target after the accent flash once its scroll completes', async () => {
+ vi.useFakeTimers();
+ let dispose = () => {};
+ let controller!: ReturnType<typeof createTargetMessageController>;
+
+ createRoot((rootDispose) => {
+ dispose = rootDispose;
+ controller = createController({
+ messageKeys: ['message-1'],
+ }).controller;
+ });
+ await Promise.resolve();
+
+ controller.goToMessage('message-1');
+ controller.completePendingScroll('message-1');
+ await Promise.resolve();
+ expect(controller.activeTargetMessageId()).toBe('message-1');
+
+ vi.advanceTimersByTime(TARGETED_MESSAGE_FLASH_MS);
+ expect(controller.activeTargetMessageId()).toBeUndefined();
+ dispose();
+ });
+
+ it('holds the flash until a nested reply target completes its scroll', async () => {
+ vi.useFakeTimers();
+ let dispose = () => {};
+ let controller!: ReturnType<typeof createTargetMessageController>;
+
+ createRoot((rootDispose) => {
+ dispose = rootDispose;
+ controller = createController({
+ initialTargetMessageId: 'message-1',
+ initialTargetMessageReplyId: 'reply-4',
+ messageKeys: ['message-1'],
+ withNavigation: true,
+ didInitialScroll: true,
+ }).controller;
+ });
+ await Promise.resolve();
+
+ // The outer row is acknowledged, but the reply scroll is still pending —
+ // the flash countdown must not start yet.
+ expect(controller.pendingScrollTargetId()).toBeUndefined();
+ vi.advanceTimersByTime(TARGETED_MESSAGE_FLASH_MS);
+ expect(controller.activeTargetMessageId()).toBe('message-1');
+
+ controller.completePendingReplyScroll('message-1', 'reply-4');
+ await Promise.resolve();
+ vi.advanceTimersByTime(TARGETED_MESSAGE_FLASH_MS);
+ expect(controller.activeTargetMessageId()).toBeUndefined();
+ expect(controller.activeTargetMessageReplyId()).toBeUndefined();
+ dispose();
+ });
+
+ it('cancels the flash when navigation moves to a new target', async () => {
+ vi.useFakeTimers();
+ let dispose = () => {};
+ let controller!: ReturnType<typeof createTargetMessageController>;
+
+ createRoot((rootDispose) => {
+ dispose = rootDispose;
+ controller = createController({
+ messageKeys: ['message-1', 'message-2'],
+ }).controller;
+ });
+ await Promise.resolve();
+
+ controller.goToMessage('message-1');
+ controller.completePendingScroll('message-1');
+ controller.goToMessage('message-2');
+ vi.advanceTimersByTime(TARGETED_MESSAGE_FLASH_MS);
+ expect(controller.activeTargetMessageId()).toBe('message-2');
+
+ controller.completePendingScroll('message-2');
+ await Promise.resolve();
+ vi.advanceTimersByTime(TARGETED_MESSAGE_FLASH_MS);
+ expect(controller.activeTargetMessageId()).toBeUndefined();
+ dispose();
+ });
+
it('copies around-target query data into the default query key', () => {
const aroundData = {
pageParams: [null],
diff --git a/apps/web/src/features/channel/Message/Root.tsx b/apps/web/src/features/channel/Message/Root.tsx
index c53dc0ae29..c4907c2b80 100644
--- a/apps/web/src/features/channel/Message/Root.tsx
+++ b/apps/web/src/features/channel/Message/Root.tsx
@@ -1,8 +1,16 @@
+import { stickyGate } from '@core/util/debounce';
import { cn } from '@ui';
import { type JSX, splitProps } from 'solid-js';
import { MessageActionsProvider, MessageProvider } from './context';
import type { MessageActions, MessageData } from './types';
+/**
+ * How long the accent background fades once the message stops being
+ * targeted. Mirrors the `targeted-message-accent-fade-out` animation
+ * duration in index.css.
+ */
+const TARGETED_FADE_OUT_MS = 500;
+
type RootProps = JSX.HTMLAttributes<HTMLDivElement> & {
message: MessageData;
actions?: MessageActions;
@@ -25,6 +33,16 @@ export function Root(props: RootProps) {
'targeted',
]);
+ // When the message stops being targeted, the accent fades out instead of
+ // cutting off: the sticky gate holds for the fade window after `targeted`
+ // falls, so the fading flag is true exactly during that window.
+ // Re-targeting mid-fade re-opens the gate, which cancels the fade.
+ const targetedSticky = stickyGate(
+ () => !!local.targeted,
+ TARGETED_FADE_OUT_MS
+ );
+ const targetFading = () => targetedSticky() && !local.targeted;
+
return (
<div
class={cn('group/message relative touch:no-select-children', local.class)}
@@ -32,6 +50,7 @@ export function Root(props: RootProps) {
data-message-id={local.message.id}
data-selected={local.selected ? '' : undefined}
data-targeted={local.targeted ? '' : undefined}
+ data-targeted-fading={targetFading() ? '' : undefined}
{...rest}
>
<div class="absolute h-full w-1 left-0 top-0 bg-accent opacity-0 message-accent-bar" />
diff --git a/apps/web/src/features/channel/Thread/ChannelThread.tsx b/apps/web/src/features/channel/Thread/ChannelThread.tsx
index 3e3d9b8850..1253209600 100644
--- a/apps/web/src/features/channel/Thread/ChannelThread.tsx
+++ b/apps/web/src/features/channel/Thread/ChannelThread.tsx
@@ -244,7 +244,6 @@ export function ChannelThread(props: ThreadProps) {
],
([activeTargetReplyId, _targetReplyId, replies]) => {
if (!activeTargetReplyId) {
- if (replySelection.selectedId()) replySelection.clear();
return;
}
const found = replies.some((r) => r.id === activeTargetReplyId);
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index e2ed29aaeb..20bc20e817 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -776,6 +776,40 @@ html:not([data-touch-device="true"]) [data-message][data-targeted]:hover{
@apply bg-accent/40 rounded-sm;
}
+/* A released target fades its accent out instead of cutting off. Duration
+ mirrors TARGETED_FADE_OUT_MS in features/channel/Message/Root.tsx. */
+[data-message][data-targeted-fading] {
+ animation: targeted-message-accent-fade-out 500ms ease-out both;
+}
+
+/* A selected message keeps its selection after release, so its fade starts
+ from the selected accent and lands on the selection gray. */
+[data-message][data-selected][data-targeted-fading] {
+ animation-name: targeted-message-accent-fade-out-selected;
+}
+
+@keyframes targeted-message-accent-fade-out {
+ from {
+ background-color: oklch(from var(--color-accent) l c h / 30%);
+ border-radius: var(--radius-sm);
+ }
+ to {
+ background-color: oklch(from var(--color-accent) l c h / 0%);
+ border-radius: var(--radius-sm);
+ }
+}
+
+@keyframes targeted-message-accent-fade-out-selected {
+ from {
+ background-color: oklch(from var(--color-accent) l c h / 40%);
+ border-radius: var(--radius-sm);
+ }
+ to {
+ background-color: oklch(from var(--color-ink) l c h / 5%);
+ border-radius: var(--radius-sm);
+ }
+}
+
@keyframes long-press-message-highlight {
from {
background-color: oklch(from var(--color-active) l c h / 0%);
diff --git a/apps/web/src/lib/core/util/debounce.ts b/apps/web/src/lib/core/util/debounce.ts
index 0e420a4efb..1bacbbfc4f 100644
--- a/apps/web/src/lib/core/util/debounce.ts
+++ b/apps/web/src/lib/core/util/debounce.ts
@@ -111,7 +111,7 @@ export function deferredGate(
* @param delay the delay time in ms
* @returns a derived signal
*/
-function _stickyGate(source: () => boolean, delay = 300): () => boolean {
+export function stickyGate(source: () => boolean, delay = 300): () => boolean {
const [follow, setFollow] = createSignal(source());
const down = solidDebounce(() => setFollow(false), delay);
createEffect(() => {
@@ -123,5 +123,6 @@ function _stickyGate(source: () => boolean, delay = 300): () => boolean {
down();
}
});
+ onCleanup(() => down.clear());
return follow;
}
diff --git a/apps/web/tests/e2e/local-channel-thread-navigation.spec.ts b/apps/web/tests/e2e/local-channel-thread-navigation.spec.ts
index b34b37e244..8a64feff68 100644
--- a/apps/web/tests/e2e/local-channel-thread-navigation.spec.ts
+++ b/apps/web/tests/e2e/local-channel-thread-navigation.spec.ts
@@ -45,6 +45,10 @@ async function expectTargetedMessage(
const target = page.locator(targetSelector(messageId));
await expect(target).toContainText(text, { timeout: 30_000 });
await expect(target).toHaveAttribute('data-targeted', '');
+ // The accent highlight flashes and auto-releases once the target settles.
+ await expect(target).not.toHaveAttribute('data-targeted', '', {
+ timeout: 30_000,
+ });
return target;
}