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.

3.1 KB
Raw Blame
import { DebugSuspense } from '@channel/DebugSuspense';
import RefreshIcon from '@icon/system/regular/arrow-clockwise.svg';
import WarningIcon from '@icon/system/regular/warning.svg';
import { Button } from '@ui';
import { createSignal, ErrorBoundary, type JSX, Show } from 'solid-js';

interface HomeSectionBoundaryProps {
  title: string;
  children: JSX.Element;
  fallback?: JSX.Element;
}

interface HomeSectionErrorProps {
  error: Error;
  reset: () => void;
  title?: string;
}

function HomeSectionError(props: HomeSectionErrorProps) {
  const [showDetails, setShowDetails] = createSignal(false);

  return (
    <div class="rounded-xl border border-edge-muted bg-surface p-4">
      <div class="flex items-start gap-3">
        <div class="flex size-8 shrink-0 items-center justify-center rounded-full bg-failure/10 text-failure [&_svg]:size-4">
          <WarningIcon />
        </div>

        <div class="min-w-0 flex flex-1 flex-col">
          <p class="text-sm font-medium text-ink">
            {props.title
              ? `Failed to load ${props.title}`
              : 'Something went wrong'}
          </p>
          <p class="text-xs leading-5 text-ink-muted">
            We couldn’t load this section. Try again, or view details if the
            issue continues.
          </p>

          <Show when={showDetails()}>
            <p class="mt-2 break-words rounded-lg bg-hover/50 p-2 text-xs leading-5 text-ink-extra-muted">
              {props.error.message}
            </p>
          </Show>

          <div class="mt-2 flex gap-2">
            <Button
              variant="secondary"
              size="sm"
              class="w-fit bg-surface"
              onClick={props.reset}
            >
              <RefreshIcon class="size-3.5" />
              Try again
            </Button>
            <Button
              variant="ghost"
              size="sm"
              onClick={() => setShowDetails((value) => !value)}
              class="w-fit"
            >
              {showDetails() ? 'Hide details' : 'Show details'}
            </Button>
          </div>
        </div>
      </div>
    </div>
  );
}

function HomeSectionFallback() {
  return (
    <div class="space-y-3">
      <div class="skeleton-shimmer h-4 w-32 rounded-full bg-skeleton" />
      <div class="space-y-2">
        <div class="skeleton-shimmer h-12 rounded-xl bg-skeleton" />
        <div class="skeleton-shimmer h-12 rounded-xl bg-skeleton" />
      </div>
    </div>
  );
}

export function HomeSectionBoundary(props: HomeSectionBoundaryProps) {
  return (
    <ErrorBoundary
      fallback={(error, reset) => (
        <HomeSectionError
          error={error instanceof Error ? error : new Error(String(error))}
          reset={reset}
          title={props.title}
        />
      )}
    >
      <DebugSuspense
        name={`Home.section.${props.title}`}
        fallback={
          props.fallback === undefined ? (
            <HomeSectionFallback />
          ) : (
            props.fallback
          )
        }
      >
        {props.children}
      </DebugSuspense>
    </ErrorBoundary>
  );
}