Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore: move resize observer into list layout provider (#1725)
gbirman5a2a35c33776
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsxindex b12edb6796..f3d9a681f6 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx@@ -37,6 +37,7 @@ import { useIsKeyPressActive } from '@core/util/useIsKeyPressActive';import {type EntityData,ListEntity,+ ListLayoutProvider,type SearchLocation,type ProjectEntity,} from '@entity';@@ -561,141 +562,145 @@ export const SoupViewList = (props: SoupViewListProps) => {<EmptyState search={!!searchText()} /></Match><Match when={rows().length}>- <EntityRowProvider- container={localEntityListRef}- canSwipeLeft={(entityId) => {- const entity = entityById().get(entityId);- if (!entity) return false;- return markDoneAction.canExecute(entity.original);- }}- onSwipeLeft={(entityId) => {- const entity = entityById().get(entityId);- if (!entity) return;- markDoneAction.executeWithSoup([entity.original], soup);- }}- setCollapseEntity={soup.collapseEntity.set}- >- <SoupList- cache={stateCache.get(getCacheKey())?.virtualCache}- ref={setLocalEntityListRef}- virtualizerClass="scrollbar-hidden"- class="overflow-hidden flex min-w-0"- virtualizerRef={registerVirtualizerHandler}- onScrollBottom={debouncedFetchMore}- scrollBottomOffset={300}- rows={rows()}+ <ListLayoutProvider ref={localEntityListRef}>+ <EntityRowProvider+ container={localEntityListRef}+ canSwipeLeft={(entityId) => {+ const entity = entityById().get(entityId);+ if (!entity) return false;+ return markDoneAction.canExecute(entity.original);+ }}+ onSwipeLeft={(entityId) => {+ const entity = entityById().get(entityId);+ if (!entity) return;+ markDoneAction.executeWithSoup([entity.original], soup);+ }}+ setCollapseEntity={soup.collapseEntity.set}>- {(row, i) => {- const timestamp = () => {- const sort_ = soup.sort.active();- if (!sort_.length) return;-- switch (sort_[0].id) {- case 'viewed_at':- return row.original.viewedAt;- case 'created_at':- return row.original.createdAt;- case 'updated_at':- return row.original.updatedAt;- }- };-- return (- <>- <Show when={i() === 0 && featuredCount() > 0}>- <div class="px-3 py-1.5 text-xs text-text-muted font-medium">- Featured Results- </div>- </Show>- <Show- when={i() === featuredCount() && featuredCount() > 0}- >- <div class="px-3 py-1.5 text-xs text-text-muted font-medium border-t border-edge-muted mt-1">- More Results- </div>- </Show>- <EntityRow- entityId={row.original.id}- swipeLeftColor="bg-success"- swipeLeftRevealedComponent={- <CheckIcon class="size-8 text-panel" />- }- >- <SoupEntityContextMenu- entity={row.original}- entityTimestamp={timestamp()}+ <SoupList+ cache={stateCache.get(getCacheKey())?.virtualCache}+ ref={setLocalEntityListRef}+ virtualizerClass="scrollbar-hidden"+ class="overflow-hidden flex min-w-0"+ virtualizerRef={registerVirtualizerHandler}+ onScrollBottom={debouncedFetchMore}+ scrollBottomOffset={300}+ rows={rows()}+ >+ {(row, i) => {+ const timestamp = () => {+ const sort_ = soup.sort.active();+ if (!sort_.length) return;++ switch (sort_[0].id) {+ case 'viewed_at':+ return row.original.viewedAt;+ case 'created_at':+ return row.original.createdAt;+ case 'updated_at':+ return row.original.updatedAt;+ }+ };++ return (+ <>+ <Show when={i() === 0 && featuredCount() > 0}>+ <div class="px-3 py-1.5 text-xs text-text-muted font-medium">+ Featured Results+ </div>+ </Show>+ <Show+ when={+ i() === featuredCount() && featuredCount() > 0+ }+ >+ <div class="px-3 py-1.5 text-xs text-text-muted font-medium border-t border-edge-muted mt-1">+ More Results+ </div>+ </Show>+ <EntityRow+ entityId={row.original.id}+ swipeLeftColor="bg-success"+ swipeLeftRevealedComponent={+ <CheckIcon class="size-8 text-panel" />+ }>- <ListEntity+ <SoupEntityContextMenuentity={row.original}- timestamp={timestamp()}- highlighted={- panel.isPanelActive() && row.isFocused()- }- onMouseMove={() => {- if (isKeypressActive()) return;- if (soup.previewEntity()) return;- soup.focus.set(row.original.id);- }}- showUnrollNotifications={- soup.filters.isActive('signal') &&- !soup.filters.isActive('noise')- }- checked={row.isSelected()}- onChecked={(next: boolean, shiftKey: boolean) =>- handleMultiSelectChecked({- entity: row.original,- entityIndex: i(),- next,- shiftKey: shiftKey ?? false,- })- }- onClick={(event: MouseEvent) => {- onEntityClick({- type: 'entity',- entity: row.original,- event,- location: undefined,- });- }}- onProjectClick={(projectEntity, event) => {- onEntityClick({- type: 'project',- projectEntity,- entity: row.original,- event,- location: undefined,- });- }}- onContentHitClick={(- e: PointerEvent | MouseEvent,- location?: SearchLocation- ) => {- onEntityClick({- type: 'entity',- entity: row.original,- event: e,- location,- });- }}- />- </SoupEntityContextMenu>- </EntityRow>- <Show- when={- i() === rows().length - 1 &&- isSearchServiceLoading()- }- >- <div class="flex items-center gap-2 px-3 py-3 text-xs text-text-muted">- <Spinner class="size-3 animate-spin" />- Searching...- </div>- </Show>- </>- );- }}- </SoupList>- </EntityRowProvider>+ entityTimestamp={timestamp()}+ >+ <ListEntity+ entity={row.original}+ timestamp={timestamp()}+ highlighted={+ panel.isPanelActive() && row.isFocused()+ }+ onMouseMove={() => {+ if (isKeypressActive()) return;+ if (soup.previewEntity()) return;+ soup.focus.set(row.original.id);+ }}+ showUnrollNotifications={+ soup.filters.isActive('signal') &&+ !soup.filters.isActive('noise')+ }+ checked={row.isSelected()}+ onChecked={(next: boolean, shiftKey: boolean) =>+ handleMultiSelectChecked({+ entity: row.original,+ entityIndex: i(),+ next,+ shiftKey: shiftKey ?? false,+ })+ }+ onClick={(event: MouseEvent) => {+ onEntityClick({+ type: 'entity',+ entity: row.original,+ event,+ location: undefined,+ });+ }}+ onProjectClick={(projectEntity, event) => {+ onEntityClick({+ type: 'project',+ projectEntity,+ entity: row.original,+ event,+ location: undefined,+ });+ }}+ onContentHitClick={(+ e: PointerEvent | MouseEvent,+ location?: SearchLocation+ ) => {+ onEntityClick({+ type: 'entity',+ entity: row.original,+ event: e,+ location,+ });+ }}+ />+ </SoupEntityContextMenu>+ </EntityRow>+ <Show+ when={+ i() === rows().length - 1 &&+ isSearchServiceLoading()+ }+ >+ <div class="flex items-center gap-2 px-3 py-3 text-xs text-text-muted">+ <Spinner class="size-3 animate-spin" />+ Searching...+ </div>+ </Show>+ </>+ );+ }}+ </SoupList>+ </EntityRowProvider>+ </ListLayoutProvider><Show when={!props.customScrollbarHidden}><CustomScrollbardiff --git a/js/app/packages/entity/src/composed/ListEntity.tsx b/js/app/packages/entity/src/composed/ListEntity.tsxindex 75778352cb..047f891191 100644--- a/js/app/packages/entity/src/composed/ListEntity.tsx+++ b/js/app/packages/entity/src/composed/ListEntity.tsx@@ -17,13 +17,17 @@ import {isTaskEntity,} from '../types/entity';import {+ type Accessor,+ createContext,+ createEffect,createSignal,Match,onCleanup,- onMount,Show,Switch,+ useContext,type Ref,+ type JSX,} from 'solid-js';import {getStreamState,@@ -55,6 +59,37 @@ import { mergeRefs } from '@solid-primitives/refs';const WIDE_BREAKPOINT = 512; // @lg container query = 32rem+interface ListLayoutContextValue {+ isWide: Accessor<boolean>;+}++const ListLayoutContext = createContext<ListLayoutContextValue>();++export function ListLayoutProvider(props: {+ ref: Accessor<HTMLElement | undefined>;+ children: JSX.Element;+}) {+ const [isWide, setIsWide] = createSignal(true);++ createEffect(() => {+ const el = props.ref();+ if (!el) return;+ const observer = new ResizeObserver((entries) => {+ setIsWide((entries[0]?.contentRect.width ?? 0) >= WIDE_BREAKPOINT);+ });+ observer.observe(el);+ onCleanup(() => observer.disconnect());+ });++ return (+ <ListLayoutContext.Provider value={{ isWide }}>+ {props.children}+ </ListLayoutContext.Provider>+ );+}++const useListLayout = () => useContext(ListLayoutContext);+const hasSearchContentHits = (entity: EntityData) =>isSearchEntity(entity) && !!entity.search.contentHitData?.length;@@ -414,16 +449,7 @@ export function ListEntity(props: ListEntityProps) {splitId: useSplitPanel()?.handle?.id,});- let rootEl!: HTMLElement;- const [isWide, setIsWide] = createSignal(true);-- onMount(() => {- const observer = new ResizeObserver((entries) => {- setIsWide((entries[0]?.contentRect.width ?? 0) >= WIDE_BREAKPOINT);- });- observer.observe(rootEl);- onCleanup(() => observer.disconnect());- });+ const isWide = useListLayout()?.isWide ?? (() => true);return (<Entity.Root@@ -435,9 +461,7 @@ export function ListEntity(props: ListEntityProps) {}props.onClick?.(e);}}- ref={mergeRefs(props.ref, draggable, (el) => {- rootEl = el;- })}+ ref={mergeRefs(props.ref, draggable)}class={cn('@container/entity w-full min-h-10 relative group/narrow', {'bg-accent/5': props.checked,'hover:bg-hover/30':diff --git a/js/app/packages/entity/src/index.ts b/js/app/packages/entity/src/index.tsindex b4773aa31b..f17d9e7144 100644--- a/js/app/packages/entity/src/index.ts+++ b/js/app/packages/entity/src/index.ts@@ -9,7 +9,7 @@ export { Entity } from './entity';export { createEntityDraggable } from './utils/draggable';export { InlineEntity } from './composed/InlineEntity';-export { ListEntity } from './composed/ListEntity';+export { ListEntity, ListLayoutProvider } from './composed/ListEntity';export { UnreadIndicator } from './components/UnreadIndicator';export { MultiSelectCheckbox } from './components/MultiSelectCheckbox';