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.

10.5 KB
Raw Blame
import '@fontsource-variable/inter';
import '../../../index.css';
import { ViewShell } from '@app/components/view-shell';
import type { SettingsTab } from '@core/constant/SettingsState';
import { SETTINGS_TAB_GROUPS } from '@core/constant/settingsTabsConfig';
import { UserContextProvider } from '@core/context/user';
import { authKeys } from '@queries/auth/keys';
import { teamKeys } from '@queries/team/keys';
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
import { ToggleSwitch } from '@ui';
import { createMemo, createSignal, For, onMount, Show } from 'solid-js';
import { render } from 'solid-js/web';
import { macroDarkTheme } from '../../theme/themes/macro-dark';
import { macroLightTheme } from '../../theme/themes/macro-light';
import { themeCssVars } from '../../theme/utils/themeCssVars';
import { Appearance } from '../Appearance';
import { AppInfo } from '../components/app-info';
import { SettingsSearchTarget } from '../components/settings-search-target';
import { SettingsSidebar } from '../components/settings-sidebar';
import { SignatureForm } from '../components/signature-form';
import {
  type SettingsSearchResult,
  searchSettings,
} from '../core/settings-search';
import { DesktopApp } from '../DesktopApp';
import { MobileSettingsSheet } from '../MobileSettingsSheet';
import {
  SettingsButton as Button,
  SettingsCard,
  SettingsPage,
  SettingsRow,
  SettingsSection,
} from '../primitives';
import { Shortcuts } from '../Shortcuts';

function Fixture() {
  const [tab, setTab] = createSignal<SettingsTab>('Email');
  const [query, setQuery] = createSignal('');
  const [selected, setSelected] = createSignal<SettingsSearchResult>();
  const [desktop, setDesktop] = createSignal(false);
  const [dark, setDark] = createSignal(false);
  const [narrow, setNarrow] = createSignal(false);
  const [mobile, setMobile] = createSignal(false);
  const [mobilePage, setMobilePage] = createSignal<SettingsTab>();
  const applyTheme = (value: boolean) => {
    setDark(value);
    for (const [key, token] of Object.entries(
      themeCssVars(value ? macroDarkTheme : macroLightTheme)
    ))
      document.documentElement.style.setProperty(key, token);
    document.documentElement.style.colorScheme = value ? 'dark' : 'light';
    document.documentElement.dataset.themeLight = String(!value);
  };
  onMount(() => applyTheme(false));
  const groups = SETTINGS_TAB_GROUPS.filter(
    (group) => !group.items.some((item) => item.tab === 'Admin')
  ).map((group) => ({
    ...group,
    items: group.items.filter((item) => !item.searchOnly),
  }));
  const results = createMemo(() =>
    searchSettings(SETTINGS_TAB_GROUPS, query())
  );
  const title = (page: SettingsTab) =>
    SETTINGS_TAB_GROUPS.flatMap((group) => group.items).find(
      (item) => item.tab === page
    )?.label ?? page;
  const sampleContent = (page: SettingsTab) => (
    <Show
      when={page === 'Email'}
      fallback={
        <SettingsPage
          title={title(page)}
          description="Sample settings for navigation and layout verification."
        >
          <SettingsSection title="Profile">
            <SettingsCard>
              <SettingsRow label="Name">Alex Morgan</SettingsRow>
            </SettingsCard>
          </SettingsSection>
          <SettingsSection title="Color Theme">
            <SettingsCard>
              <SettingsRow label="Dark mode">
                <ToggleSwitch checked={dark()} onChange={applyTheme} />
              </SettingsRow>
            </SettingsCard>
          </SettingsSection>
          <SettingsSection title="Delivery">
            <SettingsCard>
              <SettingsRow
                label="Email digest"
                description="Get a summary of your notifications."
              >
                <ToggleSwitch />
              </SettingsRow>
            </SettingsCard>
          </SettingsSection>
        </SettingsPage>
      }
    >
      <SettingsPage
        title="Email"
        description="Manage your inboxes and the signature you send with each account."
      >
        <SettingsSection
          title="Accounts"
          description="Connect email accounts and manage their sync with Macro."
        >
          <SettingsCard>
            <For each={['[email protected]', '[email protected]']}>
              {(email) => (
                <SettingsRow label={email} description="Up to date">
                  <Show when={email === '[email protected]'}>
                    <Button variant="secondary" size="md">
                      Enable calendar
                    </Button>
                  </Show>
                  <Button variant="ghost" size="md">
                    Remove
                  </Button>
                </SettingsRow>
              )}
            </For>
            <SettingsRow
              label="Add another inbox"
              description="Connect Gmail, Outlook.com, or Microsoft 365."
            >
              <Button variant="secondary" size="md">
                Add account
              </Button>
            </SettingsRow>
          </SettingsCard>
        </SettingsSection>
        <SettingsSection
          title="Signatures"
          description="Create a signature for each of your email accounts. Format text, add links, or insert an image below."
        >
          <For each={['[email protected]', '[email protected]']}>
            {(email) => <FixtureSignature email={email} />}
          </For>
        </SettingsSection>
      </SettingsPage>
    </Show>
  );
  const content = (page: SettingsTab) => (
    <Show when={page !== 'Appearance'} fallback={<Appearance />}>
      <Show when={page !== 'Shortcuts'} fallback={<Shortcuts />}>
        <Show
          when={page !== 'Desktop App'}
          fallback={
            <Show when={desktop()} fallback={<DesktopApp />}>
              <AppInfo
                title="Desktop App (Alpha)"
                description="Your installed version of Macro Alpha."
                version="2.5.0"
                buildDate={new Date('2026-10-01T16:30:00Z')}
                bundleDate={new Date('2026-10-27T09:15:00Z')}
              />
            </Show>
          }
        >
          {sampleContent(page)}
        </Show>
      </Show>
    </Show>
  );
  return (
    <div class="h-dvh bg-panel text-ink flex flex-col">
      <Show when={narrow()}>
        <style>{`.mobile-settings-sheet {max-width:390px; margin-inline:auto;}`}</style>
      </Show>
      <div class="p-2 flex items-center gap-3 border-b border-edge-muted text-xs">
        <span>Local fixture · changes stay in this preview</span>
        <Button size="sm" onClick={() => setNarrow(!narrow())}>
          Narrow layout
        </Button>
        <Button size="sm" onClick={() => applyTheme(!dark())}>
          Toggle theme
        </Button>
        <Button size="sm" onClick={() => setDesktop(!desktop())}>
          {desktop() ? 'Preview web app' : 'Preview desktop app'}
        </Button>
        <Button size="sm" onClick={() => setMobile(true)}>
          Mobile settings
        </Button>
      </div>
      <div class="min-h-0 flex-1">
        <ViewShell.Root main={{ preferredWidth: 960 }}>
          <ViewShell.Aside>
            <SettingsSidebar
              groups={groups}
              results={results()}
              selectedResultId={selected()?.id}
              searchQuery={query()}
              onSearchQueryChange={setQuery}
              isItemActive={(item) => item === tab()}
              onSelect={(page) => {
                setSelected(undefined);
                setTab(page);
              }}
              onSelectResult={(result) => {
                setTab(result.tab);
                setSelected({ ...result });
              }}
            />
          </ViewShell.Aside>
          <ViewShell.Main>
            <div class="h-full min-h-0">
              <SettingsSearchTarget result={selected()}>
                {content(tab())}
              </SettingsSearchTarget>
            </div>
          </ViewShell.Main>
        </ViewShell.Root>
      </div>
      <MobileSettingsSheet
        open={mobile()}
        page={mobilePage()}
        groups={groups}
        searchGroups={SETTINGS_TAB_GROUPS}
        name="Alex Morgan"
        email="[email protected]"
        avatar="A"
        onClose={() => {
          setMobile(false);
          setMobilePage(undefined);
        }}
        onNavigate={setMobilePage}
        onLogout={() => {}}
        renderPage={content}
      />
    </div>
  );
}
function FixtureSignature(props: { email: string }) {
  const [saved, setSaved] = createSignal('<p>Alex Morgan</p>');
  const [value, setValue] = createSignal(saved());
  const [replies, setReplies] = createSignal(true);
  const [status, setStatus] = createSignal('');
  const [importing, setImporting] = createSignal(false);
  let api: { setContent: (html: string) => void } | undefined;
  return (
    <>
      <SignatureForm
        email={props.email}
        value={value()}
        onInput={setValue}
        onReady={(editor) => {
          api = editor;
        }}
        onSave={() => {
          setSaved(value());
          setStatus('Signature saved');
        }}
        onClear={() => {
          setValue('');
          setSaved('');
          api?.setContent('');
          setStatus('Signature cleared');
        }}
        onImport={() => {
          setImporting(true);
          setTimeout(() => {
            const imported = `<p><strong>Alex Morgan</strong></p><p>Product Lead · <a href="https://example.com">example.com</a></p>`;
            setValue(imported);
            setSaved(imported);
            api?.setContent(imported);
            setImporting(false);
            setStatus('Signature imported from Gmail');
          }, 600);
        }}
        importing={importing()}
        dirty={saved() !== value()}
        hasContent={!!value()}
        pending={false}
        replies={replies()}
        onRepliesChange={setReplies}
        mobile={false}
      />
      <Show when={status()}>
        <p role="status" class="text-sm text-ink-muted">
          {status()}
        </p>
      </Show>
    </>
  );
}
const root = document.getElementById('root');
// Appearance's Language section reads these; the fixture has no backend.
const queryClient = new QueryClient({
  defaultOptions: { queries: { staleTime: Infinity, retry: false } },
});
queryClient.setQueryData(authKeys.userLanguage.queryKey, { language: null });
queryClient.setQueryData(teamKeys.currentTeam.queryKey, null);
if (root)
  render(
    () => (
      <QueryClientProvider client={queryClient}>
        <UserContextProvider>
          <Fixture />
        </UserContextProvider>
      </QueryClientProvider>
    ),
    root
  );