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.

feat(search): cache channel filters (#2498)

gbirmanc1699437f87a
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
index df9a19361b..50d8d51a45 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
@@ -6,10 +6,33 @@ import { useQuickAccess } from '@core/context/quickAccess';
import { useUserId } from '@core/context/user';
import { QUERY_FILTERS } from '@app/component/next-soup/filters/query-filters';
import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
+import { soupViewCacheKey } from '@app/component/next-soup/soup-view/soup-view-cache-key';
+import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import type { SoupBody } from '@queries/soup/items';
-import { batch, createMemo, Show } from 'solid-js';
+import { batch, createEffect, createMemo, Show } from 'solid-js';
import { FilterCombobox, FilterSelect, type Option } from './filter-primitives';
import type { FilterID } from '@app/component/next-soup/filters/configs';
+import type { ChannelFilters } from '@service-storage/generated/schemas';
+
+type ChannelSubFilters = Pick<ChannelFilters, 'channel_ids' | 'sender_ids'>;
+
+function getCachedChannelSubFilters(contentId: string): ChannelSubFilters {
+ try {
+ const raw = localStorage.getItem(
+ soupViewCacheKey(contentId, 'channel-sub-filters')
+ );
+ return raw ? JSON.parse(raw) : {};
+ } catch {
+ return {};
+ }
+}
+
+function cacheChannelSubFilters(contentId: string, filters: ChannelSubFilters) {
+ localStorage.setItem(
+ soupViewCacheKey(contentId, 'channel-sub-filters'),
+ JSON.stringify(filters)
+ );
+}
export const INDEX_OPTIONS: (Option & { queryFilters: SoupBody })[] = [
{
@@ -61,7 +84,9 @@ const INDEX_SELECT_OPTIONS: Option[] = INDEX_OPTIONS.map((o) => ({
}));
export const SearchIndexFilter = () => {
- const { soup, setQueryFilters } = useSoupView();
+ const { soup, queryFilters, setQueryFilters } = useSoupView();
+ const panel = useSplitPanelOrThrow();
+ const contentId = panel.handle.content().id;
const activeIndex = createMemo((): Option[] => {
const found = INDEX_OPTIONS.find((opt) => soup.filters.isActive(opt.value));
@@ -70,6 +95,18 @@ export const SearchIndexFilter = () => {
: [];
});
+ const isChannelsActive = () =>
+ activeIndex().some((o) => o.value === 'channels');
+
+ createEffect(() => {
+ if (!isChannelsActive()) return;
+ const cf = queryFilters().channel_filters;
+ const sub: ChannelSubFilters = {};
+ if (cf?.channel_ids?.length) sub.channel_ids = cf.channel_ids;
+ if (cf?.sender_ids?.length) sub.sender_ids = cf.sender_ids;
+ cacheChannelSubFilters(contentId, sub);
+ });
+
const handleChange = (selected: Option[]) => {
batch(() => {
for (const opt of INDEX_OPTIONS) {
@@ -82,9 +119,20 @@ export const SearchIndexFilter = () => {
const opt = INDEX_OPTIONS.find((o) => o.value === selected[0].value);
if (opt) {
soup.filters.toggle({ or: [opt.value as FilterID] });
- setQueryFilters({
- ...opt.queryFilters,
- });
+ if (opt.value === 'channels') {
+ const cached = getCachedChannelSubFilters(contentId);
+ setQueryFilters({
+ ...opt.queryFilters,
+ channel_filters: {
+ ...opt.queryFilters.channel_filters,
+ ...cached,
+ },
+ });
+ } else {
+ setQueryFilters({
+ ...opt.queryFilters,
+ });
+ }
}
} else {
setQueryFilters({
@@ -99,9 +147,6 @@ export const SearchIndexFilter = () => {
return active.length > 0 ? active[0].label : 'All';
});
- const isChannelsActive = () =>
- activeIndex().some((o) => o.value === 'channels');
-
return (
<div class="flex items-center gap-1.5">
<FilterSelect
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-cache-key.ts b/js/app/packages/app/component/next-soup/soup-view/soup-view-cache-key.ts
new file mode 100644
index 0000000000..1cd3953012
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-cache-key.ts
@@ -0,0 +1,4 @@
+export function soupViewCacheKey(contentId: string, suffix?: string): string {
+ const base = `macro:soup-view:${contentId}`;
+ return suffix ? `${base}:${suffix}` : base;
+}
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 ceb1100fef..d137889e89 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
@@ -17,6 +17,7 @@ import {
SoupViewContextProvider,
useSoupView,
} from '@app/component/next-soup/soup-view/soup-view-context';
+import { soupViewCacheKey } from '@app/component/next-soup/soup-view/soup-view-cache-key';
import { useSoupNavigationHotkeys } from './use-soup-navigation-hotkeys';
import { useSoupViewHotkeys } from './use-soup-view-hotkeys';
import { useSplitLayout } from '@app/component/split-layout/layout';
@@ -647,7 +648,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
const [persistedState, setPersistedState] = makePersisted(
createSignal<PersistedSoupViewState>(),
- { name: `macro:soup-view:${contentId}` }
+ { name: soupViewCacheKey(contentId) }
);
const cacheKey = `soup-view-${panel.handle.id}-${contentId}${previewPanel ? '-preview' : ''}`;