Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): Recipient selector losing focus on mount (#642)
dev-rbcbfad3079f16
diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsxindex 424ca0126a..5739ceee35 100644--- a/js/app/packages/app/component/Launcher.tsx+++ b/js/app/packages/app/component/Launcher.tsx@@ -43,7 +43,7 @@ const createBlock = async (spec: {const { replaceSplit, insertSplit } = useSplitLayout();const { blockName, createFn, loading } = spec;- setCreateMenuOpen(false);+ setCreateMenuOpen(false, false);if (!loading) {const id = await createFn();@@ -71,7 +71,7 @@ const createComponent = async (spec: {componentId: string;shouldInsert?: boolean;}) => {- setCreateMenuOpen(false);+ setCreateMenuOpen(false, false);const { replaceSplit, insertSplit } = useSplitLayout();if (spec.shouldInsert) {insertSplit({ type: 'component', id: spec.componentId });@@ -378,7 +378,7 @@ const LauncherMenuItem = (props: LauncherMenuItemProps) => {};type LauncherInnerProps = {- onClose: () => void;+ onClose: (shouldReturnFocus?: boolean) => void;};const LauncherInner = (props: LauncherInnerProps) => {@@ -431,7 +431,7 @@ const LauncherInner = (props: LauncherInnerProps) => {description: item.description,keyDownHandler: () => {item.keyDownHandler();- props.onClose();+ props.onClose(false);return true;},});@@ -566,7 +566,7 @@ const LauncherInner = (props: LauncherInnerProps) => {type LauncherProps = {open: boolean;- onOpenChange: (open: boolean) => void;+ onOpenChange: (open: boolean, shouldReturnFocus?: boolean) => void;};export const Launcher = (props: LauncherProps) => {@@ -598,7 +598,11 @@ export const Launcher = (props: LauncherProps) => {<Dialog.Content><div class="fixed inset-0 z-modal w-screen h-screen flex items-center justify-center">- <LauncherInner onClose={() => props.onOpenChange(false)} />+ <LauncherInner+ onClose={(shouldReturnFocus) =>+ props.onOpenChange(false, shouldReturnFocus)+ }+ /></div></Dialog.Content></Dialog.Portal>diff --git a/js/app/packages/core/email-link/index.ts b/js/app/packages/core/email-link/index.tsindex 8be37dff52..8e9a7688eb 100644--- a/js/app/packages/core/email-link/index.ts+++ b/js/app/packages/core/email-link/index.ts@@ -7,8 +7,9 @@ import { openEmailAuthPopup } from '@core/auth/email';import { isErr } from '@core/util/maybeResult';import { queryKeys } from '@macro-entity';import { emailClient } from '@service-email/client';+import type { Link } from '@service-email/generated/schemas';import { updateUserInfo } from '@service-gql/client';-import { useQuery } from '@tanstack/solid-query';+import { type UseQueryResult, useQuery } from '@tanstack/solid-query';import { err, okAsync, ResultAsync } from 'neverthrow';import { createMemo, createSignal } from 'solid-js';import { queryClient } from '../../macro-entity/src/queries/client';@@ -36,13 +37,17 @@ export function useEmailLinksQuery() {}));}+function hasEmailLinks(query: UseQueryResult<Link[], Error>) {+ if (!query.data || query.error) {+ return false;+ }+ return query.data.length > 0;+}+export function useEmailLinksStatus() {const links = useEmailLinksQuery();return createMemo(() => {- if (!links.data || links.error) {- return false;- }- return links.data.length > 0;+ return hasEmailLinks(links);});}@@ -161,7 +166,7 @@ export function useEmailLinks() {return {query: query,- status: useEmailLinksStatus(),+ isConnected: () => hasEmailLinks(query),initEmailLink: () =>initEmailLink().map(startEmailPolling).map(invalidations),connect: () =>diff --git a/js/app/packages/core/util/createControlledOpenSignal.ts b/js/app/packages/core/util/createControlledOpenSignal.tsindex 2e43f88202..85dac3fdaa 100644--- a/js/app/packages/core/util/createControlledOpenSignal.ts+++ b/js/app/packages/core/util/createControlledOpenSignal.ts@@ -1,44 +1,50 @@import { DEV_MODE_ENV } from '@core/constant/featureFlags';-import { createSignal, type Setter } from 'solid-js';+import { createSignal } from 'solid-js';import { attributesToSelector } from './attributeToSelector';let previouslyFocusedElement = document.activeElement;export const createControlledOpenSignal = (value?: boolean) => {const [createMenuOpen, setCreateMenuOpen] = createSignal(value ?? false);- const customSetter: Setter<boolean> = (prev) => {+ const customSetter = (+ next: boolean | ((prev: boolean) => boolean),+ shouldReturnFocusToPreviousElement = true+ ) => {const activeElement = document.activeElement;- const isOpenResult = setCreateMenuOpen(prev);+ const isOpenResult = setCreateMenuOpen(next);if (isOpenResult) {previouslyFocusedElement = activeElement;if (DEV_MODE_ENV)console.info('Borrowing focus from', previouslyFocusedElement);- } else {- // has to fire two tasks after to prevent Kobalte menus stealing focus and opening menu on up/down keypress- // i guess not - until it does once again- setTimeout(() => {- if (previouslyFocusedElement instanceof HTMLElement) {- if (previouslyFocusedElement.isConnected) {- previouslyFocusedElement.focus();- } else {- // This only works for restoring previously focused entity in UnifiedList, this a workaround previous focused Entity nodes being removed from the dom and focusing to body+ return;+ }++ if (!shouldReturnFocusToPreviousElement) return;- // attributeToSelector still doesn't guarentee node is unique for all cases- // new rendered node might have different arribute value- previouslyFocusedElement = document.querySelector(- attributesToSelector(previouslyFocusedElement)- ) as HTMLElement;- if (previouslyFocusedElement instanceof HTMLElement) {- previouslyFocusedElement.focus();- if (DEV_MODE_ENV)- console.info('returning focus to', previouslyFocusedElement);- }+ // has to fire two tasks after to prevent Kobalte menus stealing focus and opening menu on up/down keypress+ // i guess not - until it does once again+ setTimeout(() => {+ if (previouslyFocusedElement instanceof HTMLElement) {+ if (previouslyFocusedElement.isConnected) {+ previouslyFocusedElement.focus();+ } else {+ // This only works for restoring previously focused entity in UnifiedList, this a workaround previous focused Entity nodes being removed from the dom and focusing to body++ // attributeToSelector still doesn't guarentee node is unique for all cases+ // new rendered node might have different arribute value+ previouslyFocusedElement = document.querySelector(+ attributesToSelector(previouslyFocusedElement)+ ) as HTMLElement;+ if (previouslyFocusedElement instanceof HTMLElement) {+ previouslyFocusedElement.focus();+ if (DEV_MODE_ENV)+ console.info('returning focus to', previouslyFocusedElement);}}- });- }+ }+ });};return [createMenuOpen, customSetter] as const;};