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(email): stars flashing during row actions (#7041)

teo5250ef3a2f89
diff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsx
index 4b4648cfc8..d4dd66c508 100644
--- a/apps/web/src/features/email-view/components/EmailList.tsx
+++ b/apps/web/src/features/email-view/components/EmailList.tsx
@@ -55,6 +55,7 @@ import {
DEFAULT_EMAIL_LIST_STATE,
type EmailListStateSnapshot,
} from '../persistence';
+import { createEmailRowActionState } from '../primitives/row-action-state';
import type { EmailDataSourceItem } from '../queries/use-email-query';
import { useEmailListHotkeys } from '../use-email-list-hotkeys';
import { EmailDateGroupHeader } from './EmailDateGroupHeader';
@@ -288,28 +289,27 @@ export function EmailList(props: EmailListProps) {
list.selection.setAnchor(row.rowId);
}
- const [isRowActionPending, setRowActionPending] = createSignal(false);
+ const rowActionState = createEmailRowActionState();
async function runRowAction(
row: EmailActionRow,
actionId: 'favorite' | 'mark-done' | 'mark-not-done'
) {
- if (isRowActionPending()) return;
const action = actionGroupsFor(row)
.flatMap((group) => group.items)
.find((item) => item.id === actionId);
if (!action || action.disabled) return;
- focusActionRow(row);
- setRowActionPending(true);
- try {
- await action.onClick();
- } catch {
- // Entity actions own their rollback and failure notification.
- } finally {
- setRowActionPending(false);
- grid()?.focus();
- }
+ await rowActionState.run(row.rowId, async () => {
+ focusActionRow(row);
+ try {
+ await action.onClick();
+ } catch {
+ // Entity actions own their rollback and failure notification.
+ } finally {
+ grid()?.focus();
+ }
+ });
}
function RowActions(props: { row: EmailActionRow }) {
@@ -320,7 +320,7 @@ export function EmailList(props: EmailListProps) {
<EmailRowActions
archived={archived()}
canArchive={entityActionViewContext().supportsMarkDone}
- pending={isRowActionPending()}
+ pending={rowActionState.isPending(props.row.rowId)}
onFocus={() => focusActionRow(props.row)}
onArchive={() =>
void runRowAction(
@@ -568,7 +568,9 @@ export function EmailList(props: EmailListProps) {
starred={isFavorited(
entityRow().entity
)}
- pending={isRowActionPending()}
+ pending={rowActionState.isPending(
+ entityRow().id
+ )}
onFocus={() =>
focusActionRow({
entity: entityRow().entity,
diff --git a/apps/web/src/features/email-view/primitives/row-action-state.test.tsx b/apps/web/src/features/email-view/primitives/row-action-state.test.tsx
new file mode 100644
index 0000000000..c6183e2ff5
--- /dev/null
+++ b/apps/web/src/features/email-view/primitives/row-action-state.test.tsx
@@ -0,0 +1,68 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { EmailStarAction } from '../components/EmailRowActions';
+import { createEmailRowActionState } from './row-action-state';
+
+vi.mock('@ui', async () => ({
+ Button: (await import('@app/components/ui/components/Button')).Button,
+ cn: (await import('@app/components/ui/utils/classname')).cn,
+}));
+
+afterEach(cleanup);
+
+describe('email row action state', () => {
+ it('keeps other stars enabled while a row mutation is pending', async () => {
+ const mutation = Promise.withResolvers<void>();
+ let complete: Promise<void> | undefined;
+ render(() => {
+ const actions = createEmailRowActionState();
+ return (
+ <>
+ <EmailStarAction
+ starred={false}
+ pending={actions.isPending('clicked-row')}
+ onFocus={() => {}}
+ onStar={() => {
+ complete = actions.run('clicked-row', () => mutation.promise);
+ }}
+ />
+ <EmailStarAction
+ starred
+ pending={actions.isPending('other-row')}
+ onFocus={() => {}}
+ onStar={() => {}}
+ />
+ </>
+ );
+ });
+
+ const clicked = screen.getByRole('button', { name: 'Star email' });
+ const other = screen.getByRole('button', { name: 'Unstar email' });
+ fireEvent.click(clicked);
+
+ expect(clicked.hasAttribute('data-disabled')).toBe(true);
+ expect(other.hasAttribute('data-disabled')).toBe(false);
+ expect(other.getAttribute('aria-pressed')).toBe('true');
+
+ mutation.resolve();
+ await complete;
+ expect(clicked.hasAttribute('data-disabled')).toBe(false);
+ });
+
+ it('prevents overlapping writes and clears pending state after failure', async () => {
+ const actions = createEmailRowActionState();
+ const mutation = Promise.withResolvers<void>();
+ const first = actions.run('first', () => mutation.promise);
+ const duplicate = vi.fn(async () => {});
+ await actions.run('first', duplicate);
+ await actions.run('second', duplicate);
+ expect(duplicate).not.toHaveBeenCalled();
+
+ const failed = expect(first).rejects.toThrow('Update failed');
+ mutation.reject(new Error('Update failed'));
+ await failed;
+ expect(actions.isPending('first')).toBe(false);
+ await actions.run('second', duplicate);
+ expect(duplicate).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/web/src/features/email-view/primitives/row-action-state.ts b/apps/web/src/features/email-view/primitives/row-action-state.ts
new file mode 100644
index 0000000000..65cefe594d
--- /dev/null
+++ b/apps/web/src/features/email-view/primitives/row-action-state.ts
@@ -0,0 +1,20 @@
+import { createSignal } from 'solid-js';
+
+/** Serialize writes without dimming controls on unrelated email rows. */
+export function createEmailRowActionState() {
+ const [pendingRowId, setPendingRowId] = createSignal<string>();
+
+ return {
+ isPending: (rowId: string) => pendingRowId() === rowId,
+ async run(rowId: string, action: () => Promise<void>) {
+ if (pendingRowId() !== undefined) return;
+
+ setPendingRowId(rowId);
+ try {
+ await action();
+ } finally {
+ setPendingRowId(undefined);
+ }
+ },
+ };
+}