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.

fix(soup): add scroll and state restoration (#1415)

dev-rb695aa7bd9e8d
diff --git a/js/app/packages/app/component/next-soup/create-sort-state.ts b/js/app/packages/app/component/next-soup/create-sort-state.ts
index 4db5983459..818526d739 100644
--- a/js/app/packages/app/component/next-soup/create-sort-state.ts
+++ b/js/app/packages/app/component/next-soup/create-sort-state.ts
@@ -1,7 +1,7 @@
import { type Accessor, createSignal } from 'solid-js';
-export type SortConfig<T> = {
- id: string;
+export type SortConfig<T, TId extends string = string> = {
+ id: TId;
fn: (a: T, b: T) => number;
desc?: boolean;
};
@@ -9,7 +9,7 @@ export type SortConfig<T> = {
/** Sort state return type with strongly typed IDs */
export type SortState<T, TId extends string = string> = {
/** Currently active sort configs (ordered by priority) */
- active: Accessor<SortConfig<T>[]>;
+ active: Accessor<SortConfig<T, TId>[]>;
isActive: (id: TId) => boolean;
/** Toggle a sort on/off */
toggle: (id: TId, value?: boolean) => void;
diff --git a/js/app/packages/app/component/next-soup/soup-view/sort-options.ts b/js/app/packages/app/component/next-soup/soup-view/sort-options.ts
index befa85a8c1..4b3070ff59 100644
--- a/js/app/packages/app/component/next-soup/soup-view/sort-options.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/sort-options.ts
@@ -64,10 +64,6 @@ export const SORT_CONFIGS = {
id: 'frecency',
fn: sortByFrecencyScore,
},
- notified_at: {
- id: 'notified_at',
- fn: sortByNotifiedAt,
- },
} satisfies Record<string, SortConfig<SoupEntity>>;
export const sortEntitiesForSearch = <T extends EntityData>(
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.tsx
index ba75cd5bde..c0f87be8c9 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
@@ -85,6 +85,7 @@ import { EmptyState } from '@app/component/next-soup/soup-view/empty-states';
import { SoupChatInput } from '@app/component/SoupChatInput';
import { ENABLE_UNIFIED_LIST_AI_INPUT } from '@core/constant/featureFlags';
import { isMobile } from '@core/mobile/isMobile';
+import type { SystemSortOption } from '@app/component/next-soup/soup-view/sort-options';
const DEFAULT_ENTITY_HEIGHT = 40;
@@ -125,9 +126,14 @@ const useSoupNotificationInvalidators = () => {
);
};
-const cacheMap = new Map<
+const stateCache = new Map<
string,
{
+ soup: {
+ focus: string | undefined;
+ filters: string[];
+ sort: SystemSortOption[];
+ };
virtualCache: CacheSnapshot;
scrollOffset: number;
}
@@ -194,22 +200,27 @@ export const SoupViewList = (props: SoupViewListProps) => {
let initialLoad = true;
- createEffect(
- on(rows, () => {
- if (!initialLoad || source.isLoading()) return;
- focusFirstEntity();
- initialLoad = false;
- })
- );
+ const registerFocusEffects = (moveInitialFocus = true) => {
+ if (moveInitialFocus) {
+ createEffect(
+ on(rows, () => {
+ if (!initialLoad || source.isLoading()) return;
+ focusFirstEntity();
+ initialLoad = false;
+ })
+ );
+ }
- createEffect(
- on(
- () => [soup.filters.activeIds(), searchText()] as const,
- () => {
- focusFirstEntity();
- }
- )
- );
+ createEffect(
+ on(
+ () => [soup.filters.activeIds(), searchText()] as const,
+ () => {
+ focusFirstEntity();
+ },
+ { defer: true }
+ )
+ );
+ };
const previewPanel = useMaybePreviewPanel();
@@ -503,7 +514,12 @@ export const SoupViewList = (props: SoupViewListProps) => {
if (!virtualHandle) return;
- cacheMap.set(getCacheKey(), {
+ stateCache.set(getCacheKey(), {
+ soup: {
+ focus: soup.focus.id(),
+ filters: soup.filters.activeIds(),
+ sort: soup.sort.active().map((s) => s.id),
+ },
virtualCache: virtualHandle.cache,
scrollOffset: virtualHandle.scrollOffset,
});
@@ -514,11 +530,22 @@ export const SoupViewList = (props: SoupViewListProps) => {
) => {
setVirtualizerHandle(handle);
- const cached = cacheMap.get(getCacheKey());
+ const cached = stateCache.get(getCacheKey());
+
+ if (!cached) {
+ registerFocusEffects();
+ return;
+ }
+
+ soup.focus.set(cached.soup.focus);
+ for (const id of cached.soup.filters) {
+ soup.filters.toggle(id);
+ }
- if (!cached) return;
+ soup.sort.setAll(cached.soup.sort);
handle?.scrollTo(cached.scrollOffset);
+ registerFocusEffects(false);
};
return (
@@ -567,7 +594,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
setCollapseEntity={soup.collapseEntity.set}
>
<SoupList
- cache={cacheMap.get(getCacheKey())?.virtualCache}
+ cache={stateCache.get(getCacheKey())?.virtualCache}
ref={setLocalEntityListRef}
virtualizerClass="scrollbar-hidden"
class="overflow-hidden flex min-w-0"