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(block-email): add Done and Trash buttons to thread top bar (#2028)

Evan Hutnik2df45e02a666
diff --git a/js/app/packages/block-email/component/TopBar.tsx b/js/app/packages/block-email/component/TopBar.tsx
index c470b04b56..5d6a5b478f 100644
--- a/js/app/packages/block-email/component/TopBar.tsx
+++ b/js/app/packages/block-email/component/TopBar.tsx
@@ -1,3 +1,8 @@
+import { useMaybeSoup } from '@app/component/next-soup/soup-context';
+import {
+ openEntityInSplitFromUnifiedList,
+ trashEmails,
+} from '@app/component/next-soup/utils';
import { useDrawerControl } from '@app/component/split-layout/components/SplitDrawerContext';
import type { BlockTool } from '@app/component/ResponsiveBlockToolbar';
import { ResponsiveBlockToolbar } from '@app/component/ResponsiveBlockToolbar';
@@ -10,13 +15,19 @@ import {
ShareTrigger,
useShareDialogContext,
} from '@core/component/TopBar/ShareButton';
+import { toast } from '@core/component/Toast/Toast';
import { ENABLE_EMAIL_SHARING } from '@core/constant/featureFlags';
+import { TOKENS } from '@core/hotkey/tokens';
+import { getActiveCommandByToken, runCommand } from '@core/hotkey/utils';
+import CheckIcon from '@icon/regular/check.svg';
import IconShared from '@icon/regular/share.svg';
import TagIcon from '@icon/regular/tag.svg';
+import TrashIcon from '@icon/regular/trash.svg';
import {
EmailPropertiesButton,
PROPERTIES_DRAWER_ID,
} from './EmailPropertiesModal';
+import { useEmailContext } from './EmailContext';
export function TopBar(props: {
id: string;
@@ -25,8 +36,67 @@ export function TopBar(props: {
}) {
const propertiesControl = useDrawerControl(PROPERTIES_DRAWER_ID);
const shareCtx = useShareDialogContext();
+ const emailCtx = useEmailContext();
+ const soup = useMaybeSoup();
+
+ const trashThread = () => {
+ const thread = emailCtx.thread();
+ if (!thread?.db_id) return;
+
+ // Calculate next entity before trashing so we can navigate to it
+ const nextEntity = (() => {
+ if (!soup) return undefined;
+ const currentIndex = soup.focus.index();
+ return soup.items.at(currentIndex + 1) ?? soup.items.at(currentIndex - 1);
+ })();
+
+ const handle = trashEmails([thread.db_id]);
+
+ if (soup && nextEntity) {
+ soup.selection.clear();
+ soup.focus.set(nextEntity.id);
+ openEntityInSplitFromUnifiedList(nextEntity, {});
+ }
+
+ const toastId = toast.success(
+ 'Moved to Trash',
+ undefined,
+ {
+ text: 'Undo',
+ onClick: () => {
+ if (toastId != null) toast.dismiss(toastId);
+ handle.undo().then(
+ () => toast.success('Restored from Trash'),
+ () => toast.failure('Failed to restore from Trash')
+ );
+ },
+ },
+ 10_000
+ );
+
+ handle.done.catch(() => {
+ toast.failure('Failed to move to Trash');
+ });
+ };
const tools: BlockTool[] = [
+ {
+ label: 'Done',
+ icon: CheckIcon,
+ action: () => {
+ const command = getActiveCommandByToken(TOKENS.entity.action.markDone);
+ if (command) {
+ runCommand(command);
+ } else {
+ emailCtx.archiveThread();
+ }
+ },
+ },
+ {
+ label: 'Trash',
+ icon: TrashIcon,
+ action: trashThread,
+ },
{
label: 'Properties',
icon: TagIcon,