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.

Jbecke/channel scroller with date (#163)

Jacob Beckerman49433a34a5ce
diff --git a/js/app/packages/block-channel/component/MessageList/MessageList.tsx b/js/app/packages/block-channel/component/MessageList/MessageList.tsx
index f35bc69823..87a72fa2bb 100644
--- a/js/app/packages/block-channel/component/MessageList/MessageList.tsx
+++ b/js/app/packages/block-channel/component/MessageList/MessageList.tsx
@@ -31,6 +31,7 @@ import {
Match,
mapArray,
on,
+ onCleanup,
type Setter,
Show,
Switch,
@@ -38,11 +39,26 @@ import {
} from 'solid-js';
import { createStore, reconcile } from 'solid-js/store';
import { type VirtualizerHandle, VList } from 'virtua/solid';
+import { CustomScrollbar } from '../../../macro-entity/src/components/CustomScrollbar';
import { MessageContainer } from '../Message/MessageContainer';
import { ReplyInputsPortaler } from '../ReplyInputsPortaler';
false && observedSize;
+const SHORT_DATE_FORMATTER = new Intl.DateTimeFormat(undefined, {
+ month: 'short',
+ day: 'numeric',
+});
+
+const LONG_DATE_FORMATTER = new Intl.DateTimeFormat(undefined, {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+});
+
+const clampIndex = (value: number, minValue: number, maxValue: number) =>
+ Math.min(Math.max(value, minValue), maxValue);
+
export type MessageListProps = {
channelId: string;
messages: Message[];
@@ -76,7 +92,12 @@ function EmptyMessageList() {
export function MessageList(props: MessageListProps) {
const [containerRef, setContainerRef] = createSignal<HTMLDivElement>();
const [virtualHandle, setVirtualHandle] = createSignal<VirtualizerHandle>();
+ const [listContainerRef, setListContainerRef] =
+ createSignal<HTMLDivElement>();
+ const [scrollHintLabel, setScrollHintLabel] = createSignal<string>();
+ const [isScrollHintVisible, setIsScrollHintVisible] = createSignal(false);
const [newIndicatorShown, setNewIndicatorShown] = createSignal<number>();
+ const [hasUserScrolled, setHasUserScrolled] = createSignal(false);
const [messageListContext, setMessageListContext] =
createStore<MessageListContextLookup>({});
@@ -146,6 +167,44 @@ export function MessageList(props: MessageListProps) {
});
let scrollTimeoutId: ReturnType<typeof setTimeout> | undefined;
+ let scrollHintTimeoutId: ReturnType<typeof setTimeout> | undefined;
+
+ const formatScrollHintDate = (isoDate?: string) => {
+ if (!isoDate) return '';
+ const date = new Date(isoDate);
+ if (Number.isNaN(date.getTime())) return '';
+ const now = new Date();
+ const formatter =
+ date.getFullYear() === now.getFullYear()
+ ? SHORT_DATE_FORMATTER
+ : LONG_DATE_FORMATTER;
+ return formatter.format(date).toUpperCase();
+ };
+
+ const updateScrollHint = () => {
+ if (!hasUserScrolled()) return;
+ const handle = virtualHandle();
+ const list = props.orderedMessages();
+ if (!handle || !list || list.length === 0) return;
+
+ const endIndex = handle.findEndIndex?.();
+ if (endIndex === undefined) return;
+
+ const index = clampIndex(endIndex, 0, list.length - 1);
+ const message = list[index];
+ const label = formatScrollHintDate(message?.created_at);
+ if (!label) return;
+
+ if (scrollHintTimeoutId) {
+ clearTimeout(scrollHintTimeoutId);
+ }
+
+ setScrollHintLabel(label);
+ setIsScrollHintVisible(true);
+ scrollHintTimeoutId = setTimeout(() => {
+ setIsScrollHintVisible(false);
+ }, 300);
+ };
/**
* Scroll to the bottom of the document or the target message depending on the
@@ -423,6 +482,26 @@ export function MessageList(props: MessageListProps) {
const [size, setSize] = createSignal<DOMRect>();
const [initialized, setInitialized] = createSignal(false);
+ // Mark the scroll container with data attribute after VList mounts
+ createEffect(() => {
+ const container = listContainerRef();
+ const handle = virtualHandle();
+ if (!container || !handle) return;
+
+ // Use requestAnimationFrame to ensure VList has rendered
+ requestAnimationFrame(() => {
+ // Find the scroll container by looking for the element with overflow-y: scroll
+ const allElements = container.querySelectorAll('*');
+ for (const el of allElements) {
+ const styles = window.getComputedStyle(el);
+ if (styles.overflowY === 'scroll' || styles.overflowY === 'auto') {
+ (el as HTMLElement).setAttribute('data-channel-message-list', '');
+ break;
+ }
+ }
+ });
+ });
+
// scroll to bottom on size change, if the user is near the bottom
createEffect(
on(virtualHandle, () => {
@@ -441,6 +520,7 @@ export function MessageList(props: MessageListProps) {
// Handle vlistscroll events
const handleScroll = () => {
if (!initialScrollComplete()) return;
+ updateScrollHint();
const nearBottom = checkIfNearBottom();
setIsNearBottom(nearBottom);
@@ -484,6 +564,18 @@ export function MessageList(props: MessageListProps) {
() => !dismissUnviewedMessages() && !!unviewedMessages()?.length
);
+ onCleanup(() => {
+ if (scrollHintTimeoutId) {
+ clearTimeout(scrollHintTimeoutId);
+ }
+ });
+
+ const markUserScrolled = () => {
+ if (!hasUserScrolled()) {
+ setHasUserScrolled(true);
+ }
+ };
+
return (
<div
class="flex-1 overflow-y-hidden suppress-css-brackets"
@@ -491,6 +583,10 @@ export function MessageList(props: MessageListProps) {
>
<div
class="flex flex-col h-full relative"
+ ref={setListContainerRef}
+ onWheel={markUserScrolled}
+ onTouchMove={markUserScrolled}
+ onPointerDown={markUserScrolled}
use:observedSize={{
setSize: setSize,
setInitialized: setInitialized,
@@ -507,6 +603,8 @@ export function MessageList(props: MessageListProps) {
'overflow-x': 'hidden',
'overflow-y': 'scroll',
}}
+ class="scrollbar-hidden"
+ data-channel-message-list
data={rows() ?? []}
overscan={10}
keepMounted={keepMountedIndices()}
@@ -605,6 +703,46 @@ export function MessageList(props: MessageListProps) {
class="absolute top-4 left-1/2 -translate-x-1/2 transition-opacity duration-200"
/>
</Show>
+ <CustomScrollbar
+ scrollContainer={() => {
+ // Track the same readiness conditions as the virtualized list
+ const hasInitialized = initialized();
+ const viewport = size();
+ const hasMessages = props.messages.length > 0;
+ if (!hasInitialized || !viewport || !hasMessages) {
+ return undefined;
+ }
+
+ // Find the actual scroll container (VList creates its own scroll container)
+ const container = listContainerRef();
+ if (!container) return undefined;
+
+ // First try to find by data attribute
+ let scrollContainer = container.querySelector(
+ '[data-channel-message-list]'
+ ) as HTMLElement | null;
+
+ // Fallback: find the element with overflow-y: scroll style
+ if (!scrollContainer) {
+ const allElements = container.querySelectorAll<HTMLElement>('*');
+ for (const el of allElements) {
+ const styles = window.getComputedStyle(el);
+ if (
+ styles.overflowY === 'scroll' ||
+ styles.overflowY === 'auto'
+ ) {
+ scrollContainer = el;
+ break;
+ }
+ }
+ }
+
+ return scrollContainer || undefined;
+ }}
+ label={scrollHintLabel()}
+ showLabel={isScrollHintVisible()}
+ enabled={hasUserScrolled()}
+ />
</div>
<ReplyInputsPortaler
channelId={props.channelId}
diff --git a/js/app/packages/macro-entity/src/components/CustomScrollbar.tsx b/js/app/packages/macro-entity/src/components/CustomScrollbar.tsx
index 99dab494b8..7b1606704a 100644
--- a/js/app/packages/macro-entity/src/components/CustomScrollbar.tsx
+++ b/js/app/packages/macro-entity/src/components/CustomScrollbar.tsx
@@ -3,9 +3,21 @@ import { createEffect, createSignal, onCleanup, Show } from 'solid-js';
interface CustomScrollbarProps {
scrollContainer: () => HTMLElement | undefined;
class?: string;
+ label?: string;
+ showLabel?: boolean;
+ labelClass?: string;
+ enabled?: boolean;
}
export function CustomScrollbar(props: CustomScrollbarProps) {
+ return (
+ <Show when={props.enabled ?? true} fallback={null}>
+ <InnerCustomScrollbar {...props} />
+ </Show>
+ );
+}
+
+function InnerCustomScrollbar(props: CustomScrollbarProps) {
const [scrollTop, setScrollTop] = createSignal(0);
const [scrollHeight, setScrollHeight] = createSignal(0);
const [clientHeight, setClientHeight] = createSignal(0);
@@ -159,7 +171,7 @@ export function CustomScrollbar(props: CustomScrollbarProps) {
return (
<Show when={isVisible()}>
<div
- class={`absolute right-0 top-0 bottom-0 w-[2px] pointer-events-auto ${props.class || ''}`}
+ class={`absolute right-0 top-0 bottom-0 w-[2px] pointer-events-auto overflow-visible ${props.class || ''}`}
style={{
'background-color': 'transparent',
}}
@@ -182,6 +194,7 @@ export function CustomScrollbar(props: CustomScrollbarProps) {
height: `${thumbHeight()}px`,
width: '2px',
'background-color': 'var(--color-accent)',
+ 'transform-origin': 'right center',
opacity: (() => {
if (isDragging()) return 1;
if (isHovering()) return 0.8;
@@ -214,6 +227,17 @@ export function CustomScrollbar(props: CustomScrollbarProps) {
}}
onMouseDown={handleMouseDown}
/>
+ <Show when={props.label}>
+ <div
+ class={`absolute right-[calc(100%+8px)] -translate-y-1/2 whitespace-nowrap font-mono text-sm text-accent pointer-events-none select-none drop-shadow transition-opacity duration-200 ease-out ${props.labelClass || ''}`}
+ style={{
+ top: `${thumbTop() + thumbHeight() / 2}px`,
+ opacity: props.showLabel ? 1 : 0,
+ }}
+ >
+ {props.label}
+ </div>
+ </Show>
</div>
</Show>
);