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.

6.4 KB
Raw Blame
import { cn } from '@ui';
import { Match, Show, Switch } from 'solid-js';
import { MultiSelectCheckbox } from '../../components/MultiSelectCheckbox';
import { UnreadIndicator } from '../../components/UnreadIndicator';
import { Entity } from '../../entity';
import {
  isCallEntity,
  isChannelEntity,
  isChannelMessageEntity,
  isEmailEntity,
  isTaskEntity,
} from '../../types/entity';
import { isWithNotification } from '../../types/notification';
import { isSearchEntity } from '../../types/search';
import {
  filterNotDoneNotifications,
  filterValidNotifications,
} from '../../utils/notification';
import { CallNarrowBody } from './call';
import {
  ChannelLatestMessageNarrowBody,
  ChannelMessageNarrowBody,
} from './channel';
import { EmailIdentity, EmailInboxChip, EmailNarrowBody } from './email';
import { InboxDivider, type LayoutProps } from './shared';
import { TaskNarrowBody } from './task';

export function NarrowInboxLayout(props: LayoutProps) {
  const isDirectMessage = () =>
    isChannelEntity(props.entity) &&
    props.entity.channelType === 'direct_message';

  const firstNotification = () => {
    if (!isWithNotification(props.entity)) return undefined;
    return filterNotDoneNotifications(
      filterValidNotifications(props.entity.notifications?.())
    )[0];
  };

  return (
    <Entity.Layout
      class="w-full text-sm grid"
      style={{
        // A scheduled send's badge is wider than a date, so it sizes its column.
        'grid-template-columns':
          props.leadingAction ||
          props.referenceProperties ||
          props.scheduleStatus ||
          (isEmailEntity(props.entity) && props.entity.scheduledSendTime)
            ? 'auto 1fr auto'
            : 'auto 1fr 8ch',
        'grid-template-rows': 'auto auto auto',
        'grid-template-areas':
          '"icon title timestamp" "icon body body" "icon body body"',
      }}
    >
      <Entity.Slot
        placement="icon"
        class="flex items-center self-center pr-(--soup-inbox-icon-padding-r)"
      >
        <UnreadIndicator
          class="mx-(--soup-inbox-unread-indicator-padding-x) size-(--soup-inbox-unread-indicator-diameter)"
          active={props.unread}
        />
        <div class="relative size-(--soup-inbox-icon-diameter) shrink-0 group">
          <Show when={props.hideCheckbox || !props.checked}>
            <div
              class={cn(
                'absolute inset-0 grid place-items-center transition-opacity',
                { 'group-hover:opacity-0': !props.hideCheckbox }
              )}
            >
              <Show
                when={isDirectMessage()}
                fallback={
                  <div class="size-(--soup-inbox-icon-diameter) bg-edge-muted rounded-full flex items-center justify-center">
                    <div class="size-[calc(var(--soup-inbox-icon-diameter)*var(--soup-inbox-icon-factor))]">
                      <Entity.Icon
                        entity={props.entity}
                        streamState={props.streamState}
                      />
                    </div>
                  </div>
                }
              >
                <div class="size-11">
                  <Entity.Icon
                    entity={props.entity}
                    streamState={props.streamState}
                    class="bg-edge-muted text-ink"
                  />
                </div>
              </Show>
            </div>
          </Show>
          <Show when={!props.hideCheckbox}>
            {/* TODO: make multiselect work on mobile */}
            <div
              class={cn(
                'absolute inset-0 grid place-items-center opacity-0 group-hover:opacity-100 transition-opacity',
                { 'opacity-100': props.checked }
              )}
            >
              <MultiSelectCheckbox
                checked={props.checked}
                onChecked={props.onChecked}
              />
            </div>
          </Show>
        </div>
      </Entity.Slot>

      <Entity.Slot
        placement="title"
        class="ph-no-capture flex items-center gap-2 truncate font-semibold pt-3"
      >
        <Show
          when={isEmailEntity(props.entity) && props.entity}
          fallback={<Entity.Title entity={props.entity} />}
        >
          {(entity) => (
            <>
              <EmailIdentity entity={entity()} />
              <EmailInboxChip entity={entity()} class="ml-auto" />
            </>
          )}
        </Show>
      </Entity.Slot>

      <Entity.Slot
        placement="timestamp"
        class="flex items-center justify-end gap-1 text-xs text-right text-ink-extra-muted font-light pt-3 pr-4"
      >
        {props.leadingAction}
        {props.referenceProperties}
        {props.scheduleStatus}
        <Show
          when={
            !props.hasNotifications &&
            !(isChannelEntity(props.entity) && isSearchEntity(props.entity))
          }
        >
          <Entity.Timestamp entity={props.entity} />
        </Show>
      </Entity.Slot>

      <Switch>
        <Match when={isChannelMessageEntity(props.entity) && props.entity}>
          {(entity) => <ChannelMessageNarrowBody entity={entity()} />}
        </Match>
        <Match
          when={isChannelEntity(props.entity) && props.entity.latestMessage}
        >
          {(msg) => <ChannelLatestMessageNarrowBody message={msg()} />}
        </Match>
        <Match when={isEmailEntity(props.entity) && props.entity}>
          {(entity) => (
            <EmailNarrowBody
              entity={entity()}
              chars={props.chars}
              showHitSnippet={props.showHitSnippet}
              setContainerRef={props.setSnippetContainerRef}
              previewLeading={props.previewLeading}
            />
          )}
        </Match>
        <Match when={isTaskEntity(props.entity)}>
          <TaskNarrowBody
            entity={props.entity}
            notification={firstNotification()}
          />
        </Match>
        <Match when={isCallEntity(props.entity) && props.entity}>
          {(entity) => (
            <CallNarrowBody
              entity={entity()}
              showAttendanceBadge={props.showCalendarAttendance !== false}
              setContainerRef={props.setSnippetContainerRef}
              chars={props.chars}
            />
          )}
        </Match>
        <Match when={true}>
          <Entity.Slot placement="body" class="pb-2 min-h-[2lh] pr-4" />
        </Match>
      </Switch>
      <InboxDivider />
    </Entity.Layout>
  );
}