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-task-view): add single click header logic (#3266)

Seamusb9b59220d4fc
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 818526d739..1b047647e6 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
@@ -4,6 +4,8 @@ export type SortConfig<T, TId extends string = string> = {
id: TId;
fn: (a: T, b: T) => number;
desc?: boolean;
+ /** True when the comparator output is negated relative to its natural order. */
+ reversed?: boolean;
};
/** Sort state return type with strongly typed IDs */
@@ -13,8 +15,10 @@ export type SortState<T, TId extends string = string> = {
isActive: (id: TId) => boolean;
/** Toggle a sort on/off */
toggle: (id: TId, value?: boolean) => void;
- /** Set multiple sorts by IDs (in priority order) */
+ /** Set multiple sorts by IDs (in priority order); resets reversed state */
setAll: (ids: TId[]) => void;
+ /** Negate the comparator for an active sort. No-op if not active. */
+ flip: (id: TId) => void;
clear: () => void;
/** Available sort configs */
available: Record<TId, SortConfig<T>>;
@@ -28,27 +32,36 @@ export const createSortState = <
initialSortIds?: (keyof TConfigs & string)[]
): SortState<T, keyof TConfigs & string> => {
type TId = keyof TConfigs & string;
+ type Entry = { id: TId; reversed: boolean };
- const initialSorts = (initialSortIds ?? [])
- .map((id) => configs[id])
- .filter((c) => c !== undefined);
+ const initialEntries: Entry[] = (initialSortIds ?? [])
+ .filter((id) => configs[id] !== undefined)
+ .map((id) => ({ id, reversed: false }));
- const [activeSorts, setActiveSorts] =
- createSignal<SortConfig<T>[]>(initialSorts);
+ const [entries, setEntries] = createSignal<Entry[]>(initialEntries);
- const isActive = (id: TId): boolean =>
- activeSorts().some((s) => s.id === configs[id]?.id);
+ const buildConfig = (entry: Entry): SortConfig<T, TId> => {
+ const base = configs[entry.id];
+ if (!entry.reversed) return base;
+ return {
+ ...base,
+ fn: (a, b) => -base.fn(a, b),
+ reversed: true,
+ };
+ };
+
+ const active = () => entries().map(buildConfig);
+
+ const isActive = (id: TId): boolean => entries().some((e) => e.id === id);
const add = (id: TId) => {
- const config = configs[id];
- if (!config || isActive(id)) return;
- setActiveSorts((prev) => [...prev, config]);
+ if (!configs[id] || isActive(id)) return;
+ setEntries((prev) => [...prev, { id, reversed: false }]);
};
const remove = (id: TId) => {
- const config = configs[id];
- if (!config || !isActive(id)) return;
- setActiveSorts((prev) => prev.filter((s) => s.id !== config.id));
+ if (!configs[id] || !isActive(id)) return;
+ setEntries((prev) => prev.filter((e) => e.id !== id));
};
const toggle = (id: TId, value?: boolean) => {
@@ -64,19 +77,26 @@ export const createSortState = <
};
const setAll = (ids: TId[]) => {
- const newSorts = ids
- .map((id) => configs[id])
- .filter((c) => c !== undefined);
- setActiveSorts(newSorts);
+ const newEntries = ids
+ .filter((id) => configs[id] !== undefined)
+ .map((id) => ({ id, reversed: false }));
+ setEntries(newEntries);
+ };
+
+ const flip = (id: TId) => {
+ setEntries((prev) =>
+ prev.map((e) => (e.id === id ? { ...e, reversed: !e.reversed } : e))
+ );
};
- const clear = () => setActiveSorts([]);
+ const clear = () => setEntries([]);
return {
- active: activeSorts,
+ active,
isActive,
toggle,
setAll,
+ flip,
clear,
available: configs as Record<TId, SortConfig<T>>,
};
diff --git a/js/app/packages/app/component/next-soup/soup-view/views/tasks/TaskListHeader.tsx b/js/app/packages/app/component/next-soup/soup-view/views/tasks/TaskListHeader.tsx
index 7c1bfd4fd9..c00fc2f5e8 100644
--- a/js/app/packages/app/component/next-soup/soup-view/views/tasks/TaskListHeader.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/views/tasks/TaskListHeader.tsx
@@ -53,8 +53,14 @@ export function ResponsiveTaskListHeader(props: { class?: string }) {
*/
export function TaskListHeader(props: { class?: string }) {
const { soup } = useSoupView();
- const activeSortId = createMemo(() => soup.sort.active()[0]?.id);
- const setSort = (id: SystemSortOption) => soup.sort.setAll([id]);
+ const activeSort = createMemo(() => soup.sort.active()[0]);
+ const setSort = (id: SystemSortOption) => {
+ if (activeSort()?.id === id) {
+ soup.sort.flip(id);
+ } else {
+ soup.sort.setAll([id]);
+ }
+ };
return (
<div
@@ -81,7 +87,8 @@ export function TaskListHeader(props: { class?: string }) {
gridArea={col.id}
label={col.label}
sortKey={sortKey}
- active={sortKey !== undefined && activeSortId() === sortKey}
+ active={sortKey !== undefined && activeSort()?.id === sortKey}
+ reversed={activeSort()?.reversed ?? false}
onSort={setSort}
narrowIcon={COLUMN_ICONS[col.id]}
/>
@@ -98,7 +105,8 @@ export function TaskListHeader(props: { class?: string }) {
gridArea="timestamp"
label="Updated"
sortKey="updated_at"
- active={activeSortId() === 'updated_at'}
+ active={activeSort()?.id === 'updated_at'}
+ reversed={activeSort()?.reversed ?? false}
onSort={setSort}
align="end"
/>
@@ -111,6 +119,7 @@ function HeaderCell(props: {
label: string;
sortKey?: SystemSortOption;
active?: boolean;
+ reversed?: boolean;
onSort?: (id: SystemSortOption) => void;
narrowIcon?: () => JSX.Element;
align?: 'start' | 'end';
@@ -161,8 +170,9 @@ function HeaderCell(props: {
</span>
<ArrowDownIcon
class={cn(
- 'size-3 shrink-0 @max-[840px]/u-list:hidden',
- props.active ? 'text-ink' : 'text-ink-extra-muted'
+ 'size-3 shrink-0 @max-[840px]/u-list:hidden transition-transform',
+ props.active ? 'text-ink' : 'text-ink-extra-muted',
+ props.active && props.reversed && 'rotate-180'
)}
/>
</button>