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[mobile]: soup create button (#2649)

Peter Chinmandea0bced2cfb
diff --git a/js/app/packages/app/component/mobile/MobileDock.tsx b/js/app/packages/app/component/mobile/MobileDock.tsx
index 79f9090a03..012b4c4e84 100644
--- a/js/app/packages/app/component/mobile/MobileDock.tsx
+++ b/js/app/packages/app/component/mobile/MobileDock.tsx
@@ -5,24 +5,15 @@ import { AnimatedStarIcon } from '@macro-icons/wide/animating/star';
import { AnimatedEmailIcon } from '@macro-icons/wide/animating/email';
import { AnimatedFileMdIcon } from '@macro-icons/wide/animating/fileMd';
import { AnimatedTaskIcon } from '@macro-icons/wide/animating/task';
-import { AnimatedPlusIcon } from '@macro-icons/wide/animating/plus';
import { hapticImpact } from '@core/mobile/haptics';
-import {
- type Component,
- createMemo,
- createSignal,
- type JSX,
- Show,
-} from 'solid-js';
+import { type Component, createSignal, type JSX, Show } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { cn } from '@ui/utils/classname';
import { useSplitLayout } from '../split-layout/layout';
-import { type ListView, isListViewID } from '@app/constants/list-views';
+import type { ListView } from '@app/constants/list-views';
import { globalSplitManager } from '@app/signal/splitLayout';
import { SearchState } from './mobileSearchState';
-import { runCreateAction, setCreateMenuOpen } from '../Launcher';
import { useLocation } from '@solidjs/router';
-import { useAnalytics } from '@app/component/analytics-context';
const ICON_ANIMATION_DURATION_MS = 500;
@@ -69,95 +60,6 @@ function MobileDockButton(props: MobileDockButtonProps) {
);
}
-type IconComponent = MobileDockButtonProps['icon'];
-
-const VIEW_CREATE_ICONS: Partial<Record<ListView, IconComponent>> = {
- agents: AnimatedStarIcon,
- mail: AnimatedEmailIcon,
- documents: AnimatedPlusIcon,
- tasks: AnimatedTaskIcon,
- channels: AnimatedChannelIcon,
- inbox: AnimatedPlusIcon,
-};
-
-function FloatingCreateButton(props: {
- activeView: () => ListView | undefined;
-}) {
- const analytics = useAnalytics();
- const [animating, setAnimating] = createSignal(false);
-
- const VIEW_CREATE_ACTIONS: Partial<Record<ListView, () => void>> = {
- agents: () => {
- analytics.track('create_entity', {
- entityType: 'chat',
- source: 'mobile_dock',
- });
- runCreateAction('chat');
- },
- mail: () => {
- analytics.track('create_entity', {
- entityType: 'email',
- source: 'mobile_dock',
- });
- runCreateAction('email');
- },
- documents: () => {
- analytics.track('create_menu_open', { from: 'mobile_dock' });
- setCreateMenuOpen(true);
- },
- tasks: () => {
- analytics.track('create_entity', {
- entityType: 'task',
- source: 'mobile_dock',
- });
- runCreateAction('task');
- },
- channels: () => {
- analytics.track('create_entity', {
- entityType: 'channel',
- source: 'mobile_dock',
- });
- runCreateAction('channel');
- },
- };
-
- const createAction = createMemo(() => {
- const view = props.activeView();
- if (!view || view === 'search') return undefined;
- return (
- VIEW_CREATE_ACTIONS[view] ??
- (() => {
- analytics.track('create_menu_open', { from: 'mobile_dock' });
- setCreateMenuOpen(true);
- })
- );
- });
-
- const createIcon = createMemo<IconComponent>(() => {
- const view = props.activeView();
- return (view && VIEW_CREATE_ICONS[view]) ?? AnimatedPlusIcon;
- });
-
- return (
- <Show when={createAction()}>
- <button
- type="button"
- class="absolute bottom-full right-4 mb-14 w-11 h-11 rounded-full bg-panel text-accent flex items-center justify-center shadow-lg"
- onPointerDown={() => {
- hapticImpact('light');
- setAnimating(true);
- setTimeout(() => setAnimating(false), ICON_ANIMATION_DURATION_MS);
- createAction()?.();
- }}
- >
- <div class="w-5 h-5 [&_svg]:size-5">
- <Dynamic component={createIcon()} triggerAnimation={animating()} />
- </div>
- </button>
- </Show>
- );
-}
-
export function MobileDock() {
const { openWithSplit } = useSplitLayout();
const location = useLocation();
@@ -171,16 +73,6 @@ export function MobileDock() {
return activeContent.id === id;
};
- const activeView = createMemo<ListView | undefined>(() => {
- const activeContent = globalSplitManager()?.activeSplit()?.content();
- if (activeContent?.type === 'component' && isListViewID(activeContent.id)) {
- return activeContent.id;
- }
- const segments = location.pathname.split('/').filter(Boolean);
- const last = segments[segments.length - 1];
- return isListViewID(last) ? last : undefined;
- });
-
const navigate = (id: ListView) => {
// If we're already on a soup/component view, replace in-place (mergeHistory)
// so the tab switch doesn't push a new entry into the swipe-back BG slot.
@@ -194,7 +86,6 @@ export function MobileDock() {
return (
<div class="relative z-mobile-nav-bar flex flex-row justify-between">
<div class="-z-1 absolute left-0 top-0 right-0 w-screen h-40 bg-panel" />
- <FloatingCreateButton activeView={activeView} />
<MobileDockButton
icon={AnimatedInboxIcon}
active={isActive('inbox')}
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-mobile-create-button.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-mobile-create-button.tsx
new file mode 100644
index 0000000000..6ab1182e78
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-mobile-create-button.tsx
@@ -0,0 +1,116 @@
+import { AnimatedStarIcon } from '@macro-icons/wide/animating/star';
+import { AnimatedEmailIcon } from '@macro-icons/wide/animating/email';
+import { AnimatedChannelIcon } from '@macro-icons/wide/animating/channel';
+import { AnimatedTaskIcon } from '@macro-icons/wide/animating/task';
+import { AnimatedPlusIcon } from '@macro-icons/wide/animating/plus';
+import { hapticImpact } from '@core/mobile/haptics';
+import {
+ type Component,
+ createMemo,
+ createSignal,
+ type JSX,
+ Show,
+} from 'solid-js';
+import { Dynamic } from 'solid-js/web';
+import type { ListView } from '@app/constants/list-views';
+import { runCreateAction, setCreateMenuOpen } from '../../Launcher';
+import { useAnalytics } from '@app/component/analytics-context';
+import { cn } from '@ui/utils/classname';
+import { isThemeDark } from '@block-theme/utils/themeUtils';
+
+const ICON_ANIMATION_DURATION_MS = 500;
+
+type IconComponent = Component<
+ JSX.SvgSVGAttributes<SVGSVGElement> | { triggerAnimation?: boolean }
+>;
+
+const VIEW_CREATE_ICONS: Partial<Record<ListView, IconComponent>> = {
+ agents: AnimatedStarIcon,
+ mail: AnimatedEmailIcon,
+ documents: AnimatedPlusIcon,
+ tasks: AnimatedTaskIcon,
+ channels: AnimatedChannelIcon,
+ inbox: AnimatedPlusIcon,
+};
+
+export function SoupViewMobileCreateButton(props: {
+ activeView: () => ListView | undefined;
+}) {
+ const analytics = useAnalytics();
+ const [animating, setAnimating] = createSignal(false);
+
+ const VIEW_CREATE_ACTIONS: Partial<Record<ListView, () => void>> = {
+ agents: () => {
+ analytics.track('create_entity', {
+ entityType: 'chat',
+ source: 'mobile_dock',
+ });
+ runCreateAction('chat');
+ },
+ mail: () => {
+ analytics.track('create_entity', {
+ entityType: 'email',
+ source: 'mobile_dock',
+ });
+ runCreateAction('email');
+ },
+ documents: () => {
+ analytics.track('create_menu_open', { from: 'mobile_dock' });
+ setCreateMenuOpen(true);
+ },
+ tasks: () => {
+ analytics.track('create_entity', {
+ entityType: 'task',
+ source: 'mobile_dock',
+ });
+ runCreateAction('task');
+ },
+ channels: () => {
+ analytics.track('create_entity', {
+ entityType: 'channel',
+ source: 'mobile_dock',
+ });
+ runCreateAction('channel');
+ },
+ };
+
+ const createAction = createMemo(() => {
+ const view = props.activeView();
+ if (!view || view === 'search') return undefined;
+ return (
+ VIEW_CREATE_ACTIONS[view] ??
+ (() => {
+ analytics.track('create_menu_open', { from: 'mobile_dock' });
+ setCreateMenuOpen(true);
+ })
+ );
+ });
+
+ const createIcon = createMemo<IconComponent>(() => {
+ const view = props.activeView();
+ return (view && VIEW_CREATE_ICONS[view]) ?? AnimatedPlusIcon;
+ });
+
+ return (
+ <Show when={createAction()}>
+ <button
+ type="button"
+ class={cn(
+ 'absolute bottom-4 right-4 z-10 pl-3 pr-4 py-2 rounded-full bg-menu text-accent flex items-center justify-center gap-2 shadow-lg',
+ isThemeDark() && 'border border-accent/30'
+ )}
+ onPointerDown={() => {
+ hapticImpact('light');
+ setAnimating(true);
+ setTimeout(() => setAnimating(false), ICON_ANIMATION_DURATION_MS);
+ createAction()?.();
+ }}
+ >
+ <div class="w-5 h-5 [&_svg]:size-5">
+ <Dynamic component={createIcon()} triggerAnimation={animating()} />
+ </div>
+ <div>Create</div>
+ </button>
+ </Show>
+ );
+}
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 d86a0ae3b1..c7ff7cd482 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
@@ -96,6 +96,7 @@ import { SoupViewCreateButton } from '@app/component/next-soup/soup-view/soup-vi
import { MobileFilterDrawer } from '@app/component/next-soup/soup-view/filters-bar/mobile-filter-drawer';
import { SettingsButton } from '@app/component/settings/SettingsButton';
import { isListViewID, type ListView } from '@app/constants/list-views';
+import { SoupViewMobileCreateButton } from '@app/component/next-soup/soup-view/soup-view-mobile-create-button';
import {
SplitHeaderLeft,
SplitHeaderRight,
@@ -217,6 +218,11 @@ export const SoupView = (props: SoupViewProps) => {
return component() === listView;
};
+ const activeListView = createMemo<ListView | undefined>(() => {
+ const id = component();
+ return id && isListViewID(id) ? id : undefined;
+ });
+
const [narrowSearchExpanded, setNarrowSearchExpanded] = createSignal(false);
const [searchIsCollapsed, setSearchIsCollapsed] = createSignal(false);
@@ -360,6 +366,9 @@ export const SoupView = (props: SoupViewProps) => {
/>
</SoupViewFileDropzone>
</Suspense>
+ <Show when={isMobile()}>
+ <SoupViewMobileCreateButton activeView={activeListView} />
+ </Show>
</div>
<Show when={isMobile()}>
<MobileSoupViewTabs />
diff --git a/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx b/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx
index f978157b6a..4367780936 100644
--- a/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx
+++ b/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx
@@ -168,10 +168,17 @@ export function MobileSwipeBackContainer(props: MobileSwipeBackContainerProps) {
<Show when={slotAData()}>
{(a) => (
<div
- class={cn('absolute inset-0', {
- 'z-10 shadow-xl': mobileSwipeLayout.fgIsSlotA(),
- 'z-0 pointer-events-none': !mobileSwipeLayout.fgIsSlotA(),
- })}
+ class={cn(
+ 'absolute inset-0',
+ {
+ 'z-10 shadow-xl': mobileSwipeLayout.fgIsSlotA(),
+ 'z-0 pointer-events-none': !mobileSwipeLayout.fgIsSlotA(),
+ },
+ !mobileSwipeLayout.fgIsSlotA() &&
+ !isDragging() &&
+ !isAnimatingOut &&
+ 'hidden'
+ )}
style={mobileSwipeLayout.fgIsSlotA() ? fgStyle() : bgStyle()}
>
{/*
@@ -199,10 +206,17 @@ export function MobileSwipeBackContainer(props: MobileSwipeBackContainerProps) {
<Show when={slotBData()}>
{(b) => (
<div
- class={cn('absolute inset-0', {
- 'z-10 shadow-xl': !mobileSwipeLayout.fgIsSlotA(),
- 'z-0 pointer-events-none': mobileSwipeLayout.fgIsSlotA(),
- })}
+ class={cn(
+ 'absolute inset-0',
+ {
+ 'z-1 shadow-xl': !mobileSwipeLayout.fgIsSlotA(),
+ '-z-1 pointer-events-none': mobileSwipeLayout.fgIsSlotA(),
+ },
+ mobileSwipeLayout.fgIsSlotA() &&
+ !isDragging() &&
+ !isAnimatingOut() &&
+ 'hidden'
+ )}
style={!mobileSwipeLayout.fgIsSlotA() ? fgStyle() : bgStyle()}
>
<Show when={b().split.content.id} keyed>
diff --git a/js/app/packages/block-theme/utils/themeUtils.ts b/js/app/packages/block-theme/utils/themeUtils.ts
index b9c6a91b79..4c6993f700 100644
--- a/js/app/packages/block-theme/utils/themeUtils.ts
+++ b/js/app/packages/block-theme/utils/themeUtils.ts
@@ -140,6 +140,11 @@ export function deleteTheme(id: string): void{
setCurrentThemeId('');
}
+/** Returns true when the current theme has a dark background (ink lightness > panel lightness). */
+export function isThemeDark(): boolean {
+ return themeReactive.c0.l[0]() > themeReactive.b0.l[0]();
+}
+
/** Checks if the theme contrast is too low, and if so, applies a readable theme. This is to prevent malicious actors sending "Theme Viruses" which make a user's theme unusable. */
export function ensureMinimalThemeContrast() {
const spec = themes().find((t) => t.id === currentThemeId())?.tokens;