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): all pages refetching on filter change (#1669)

dev-rb62e7505e053c
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
index e4ab0da73b..2c66d39e66 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
@@ -35,6 +35,10 @@ import {
useContext,
} from 'solid-js';
import { matchesTaskSubFilters } from './task-sub-filter-matcher';
+import { useQueryClient } from '@queries/client';
+import { soupKeys } from '@queries/soup/keys';
+import type { InfiniteData } from '@tanstack/solid-query';
+import type { SoupPage } from '@service-storage/generated/schemas';
type Row<T> = {
original: T;
@@ -102,6 +106,9 @@ export const SoupViewContextProvider: FlowComponent<
SoupViewContextProviderProps
> = (props) => {
const soup = props.soup ?? createSoupState();
+
+ const queryClient = useQueryClient();
+
const soupParams = createMemo(
(): SoupParams => ({
limit: 100,
@@ -109,7 +116,7 @@ export const SoupViewContextProvider: FlowComponent<
})
);
- const [internalQueryFilters, setQueryFilters] =
+ const [internalQueryFilters, setInternalQueryFilters] =
createSignal<SoupItemsQueryFilters>({});
const [statusFilter, setStatusFilter] = createSignal<string | undefined>();
@@ -214,6 +221,32 @@ export const SoupViewContextProvider: FlowComponent<
})
);
+ const setQueryFilters: Setter<SoupItemsQueryFilters> = (next) => {
+ // To avoid fetching all pages again when coming back to the current query filters,
+ // we set the query cache to only contain the first page of data which is the only
+ // one to be refetched
+ queryClient.setQueryData(
+ soupKeys.items({
+ params: soupParams(),
+ body: soupBody(),
+ }).queryKey,
+ (prev: InfiniteData<SoupPage> | SoupPage) => {
+ if (!prev) return;
+
+ if ('pages' in prev) {
+ // Just to avoid spreading and new array creation, works the same but slightly
+ // better performance
+ prev.pages.splice(1, prev.pages.length);
+ return prev;
+ }
+
+ return prev;
+ }
+ );
+
+ setInternalQueryFilters(next);
+ };
+
const items = createMemo<SoupEntity[]>(
(prev) => {
const searching = search.isSearching();
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 360fbae001..dddc79711b 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
@@ -314,7 +314,12 @@ export const SoupViewList = (props: SoupViewListProps) => {
});
const debouncedFetchMore = debounce(() => {
- if (source.isFetchingNextPage() || !source.hasNextPage()) return;
+ if (
+ source.isFetching() ||
+ source.isFetchingNextPage() ||
+ !source.hasNextPage()
+ )
+ return;
source.fetchNextPage();
}, 15);
@@ -573,6 +578,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
class="overflow-hidden flex min-w-0"
virtualizerRef={registerVirtualizerHandler}
onScrollBottom={debouncedFetchMore}
+ scrollBottomOffset={300}
rows={rows()}
>
{(row, i) => {
@@ -590,12 +596,6 @@ export const SoupViewList = (props: SoupViewListProps) => {
}
};
- createEffect(() => {
- if (i() === Math.floor(rows().length * 0.8)) {
- debouncedFetchMore();
- }
- });
-
return (
<>
<Show when={i() === 0 && featuredCount() > 0}>