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
fix: unified empty state clean up (#698)
gbirman9202fb2909ca
diff --git a/js/app/packages/app/component/UnifiedListEmptyState.tsx b/js/app/packages/app/component/UnifiedListEmptyState.tsxindex cef3c9c73c..c693433ead 100644--- a/js/app/packages/app/component/UnifiedListEmptyState.tsx+++ b/js/app/packages/app/component/UnifiedListEmptyState.tsx@@ -7,12 +7,16 @@ import { isTouchDevice } from '@core/mobile/isTouchDevice';import { isMobileWidth } from '@core/mobile/mobileWidth';import type { DefaultView, ViewId } from '@core/types/view';import { handleFolderSelect } from '@core/util/upload';-import { createMemo, Match, onMount, Show, Switch } from 'solid-js';+import { createMemo, Match, onCleanup, onMount, Show, Switch } from 'solid-js';import { useSplitPanelOrThrow } from './split-layout/layoutUtils';false && fileSelector;false && folderSelector;+const EMPTY_STATE_HELP_DRAWER_TIMEOUT_MS = 2000;++const DEFAULT_EMPTY_MESSAGE = 'No items to show.';+function EmptyStateHelpDrawer(props: {message?: string;helpDrawer: DefaultView;@@ -21,24 +25,42 @@ function EmptyStateHelpDrawer(props: {const {unifiedListContext: { setShowHelpDrawer },} = useSplitPanelOrThrow();++ let timeoutId: ReturnType<typeof setTimeout> | undefined;++ // because the empty state can sometimes be mounted and unmounted rapidly, we need to+ // ensure that the help drawer is only shown when this state is stableonMount(() => {- setShowHelpDrawer((prev) => new Set([...prev, props.helpDrawer]));+ timeoutId = setTimeout(() => {+ setShowHelpDrawer((prev) => new Set([...prev, props.helpDrawer]));+ }, EMPTY_STATE_HELP_DRAWER_TIMEOUT_MS);+ });+ onCleanup(() => {+ clearTimeout(timeoutId);});+return (<EmptyStateInner- emptyMessage={props.message}+ message={props.message}showDropZone={props.showDropZone}/>);}-export function EmptyState(props: { viewId?: ViewId; search?: boolean }) {+export function EmptyState(props: {+ viewId?: ViewId;+ search?: boolean;+ hasRefinementsFromBase?: boolean;+}) {const emailActive = useEmailLinksStatus();return (<Switch><Match when={props.search}>- <EmptyStateInner emptyMessage={'No results.'} />+ <EmptyStateInner message={'No results.'} />+ </Match>+ <Match when={props.hasRefinementsFromBase}>+ <EmptyStateInner /></Match><Match when={props.viewId === 'noise' && !emailActive()}><EmptyStateHelpDrawer@@ -52,7 +74,7 @@ export function EmptyState(props: { viewId?: ViewId; search?: boolean }) {emailActive()}>- <EmptyStateInner emptyMessage={'Inbox zero.'} />+ <EmptyStateInner message={'Inbox zero.'} /></Match><Match when={props.viewId === 'signal' && !emailActive()}><EmptyStateHelpDrawer@@ -93,14 +115,14 @@ export function EmptyState(props: { viewId?: ViewId; search?: boolean }) {/></Match><Match when={true}>- <EmptyStateInner emptyMessage={'No items to show.'} showDropZone />+ <EmptyStateInner /></Match></Switch>);}export interface EmptyStateInnerProps {- emptyMessage?: string;+ message?: string;showDropZone?: boolean;cta?: {label: string;@@ -123,9 +145,9 @@ export function EmptyStateInner(props: EmptyStateInnerProps) {return (<div class="size-full flex items-center justify-center p-4 text-ink-muted"><div class="panel w-full flex flex-col size-full">- <Show when={props.emptyMessage}>- <p class="text-ink-muted font-mono">{props.emptyMessage}</p>- </Show>+ <p class="text-ink-muted font-mono">+ {props.message ?? DEFAULT_EMPTY_MESSAGE}+ </p><Show when={props.cta}>{(cta) => (<div class="w-full flex justify-start pt-4">diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsxindex 3d7cdb47e2..47744d5aec 100644--- a/js/app/packages/app/component/UnifiedListView.tsx+++ b/js/app/packages/app/component/UnifiedListView.tsx@@ -134,7 +134,6 @@ import {} from './split-layout/components/SplitToolbar';import { useSplitLayout } from './split-layout/layout';import { useSplitPanelOrThrow } from './split-layout/layoutUtils';-import { EmptyState } from './UnifiedListEmptyState';import {applyClientFilters,type DisplayOptions,@@ -1511,13 +1510,9 @@ export function UnifiedListView(props: UnifiedListViewProps) {<UnifiedListComponententityListRef={setLocalEntityListRef}virtualizerHandle={setVirtualizerHandle}- emptyState={- <EmptyState- viewId={view()?.id}- search={searchText().length > 0}- />- }- hasRefinementsFromBase={isViewConfigChanged}+ viewId={view()?.id}+ searchText={searchText()}+ hasRefinementsFromBase={isViewConfigChanged()}>{(innerProps) => {const displayDoneButton = () => {diff --git a/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx b/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsxindex a7fa55ecd1..dedf7471c8 100644--- a/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx+++ b/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx@@ -1,5 +1,7 @@import { useSuspenseContext } from '@app/component/SuspenseContext';+import { EmptyState } from '@app/component/UnifiedListEmptyState';import { CustomScrollbar } from '@core/component/CustomScrollbar';+import type { ViewId } from '@core/types/view';import Fragment from '@core/util/Fragment';import { onElementConnect } from '@solid-primitives/lifecycle';import { debounce } from '@solid-primitives/scheduled';@@ -10,7 +12,6 @@ import {createMemo,createRenderEffect,createSignal,- type JSX,Match,on,onCleanup,@@ -376,29 +377,6 @@ export function createUnifiedInfiniteList<T extends EntityData>({});});- const [showNoResults, setShowNoResults] = createSignal(false);- let noResultsTimeoutId: ReturnType<typeof setTimeout> | undefined;- createEffect(- on(- [() => sortedEntities().length, debouncedIsLoading],- ([entitiesLength, loading]) => {- if (noResultsTimeoutId) clearTimeout(noResultsTimeoutId);-- if (!loading && entitiesLength === 0) {- noResultsTimeoutId = setTimeout(() => {- setShowNoResults(true);- }, DEBOUNCE_LOADING_STATE_MS + 50);- } else if (entitiesLength > 0) {- setShowNoResults(false);- }- }- )- );-- onCleanup(() => {- if (noResultsTimeoutId) clearTimeout(noResultsTimeoutId);- });-let isFetchingMore = false;const fetchMoreData = async () => {if (disableFetchMore?.() || isFetchingMore) return;@@ -426,8 +404,9 @@ export function createUnifiedInfiniteList<T extends EntityData>({children?: EntityRenderer<T>;entityListRef?: (ref: HTMLDivElement | undefined) => void;virtualizerHandle?: Setter<VirtualizerHandle | undefined>;- emptyState?: JSX.Element;- hasRefinementsFromBase?: Accessor<boolean>;+ hasRefinementsFromBase?: boolean;+ viewId?: ViewId;+ searchText?: string;}) => {const [listRef, setListRef] = createSignal<HTMLDivElement>();let containerSizeObserver: ResizeObserver | null = null;@@ -538,22 +517,48 @@ export function createUnifiedInfiniteList<T extends EntityData>({));+ // stable empty state+ const entityCount = createMemo(() => sortedEntities().length);+ const [showEmptyState, setShowEmptyState] = createSignal<boolean>(false);+ const [loadFinished, setLoadFinished] = createSignal<boolean>(false);+ createEffect(() => {+ if (entityCount() === 0) {+ setLoadFinished(false);+ let count = 0;+ const timeoutId = setInterval(() => {+ const countExceeded = ++count > 10;+ if (countExceeded) {+ console.warn('Too many interval iterations');+ }++ if (loadFinished() || countExceeded) clearInterval(timeoutId);+ if (entityCount() === 0 && !debouncedIsLoading()) {+ setLoadFinished(true);+ }+ }, 500);+ }+ });+ createEffect(() => {+ if (hasFinishedInitialLoad() && !debouncedIsLoading()) {+ setLoadFinished(true);+ }+ });+ createEffect(() => {+ if (entityCount() > 0) {+ setShowEmptyState(false);+ return;+ }+ setShowEmptyState(loadFinished());+ });+return (<Switch>- <Match- when={- hasFinishedInitialLoad() &&- !props.hasRefinementsFromBase?.() &&- sortedEntities().length === 0- }- >- {props.emptyState}- </Match>- <Match when={showNoResults() && props.hasRefinementsFromBase?.()}>- <div class="flex size-full p-4">- <span class="font-mono text-ink-muted">No results found</span>- </div>- {/* TODO: Filtered Empty State */}+ <Match when={showEmptyState()}>+ <EmptyState+ viewId={props.viewId}+ search={!!props.searchText}+ hasRefinementsFromBase={props.hasRefinementsFromBase}+ /></Match><Match when={true}><div class="flex size-full relative" ref={setListRef}>