Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

4.0 KB
Raw Blame
import { Box, Flex, HStack, Spacer, Stack } from '@chakra-ui/react';
import { GALLERY_BOARD_PANEL_MAX_WIDTH_PX, GALLERY_BOARD_PANEL_MIN_WIDTH_PX } from '@features/gallery/core/settings';
import { ResizeHandle } from '@platform/ui/ResizeHandle';
import { segmentTabsPanelId, segmentTabsTabId } from '@platform/ui/SegmentTabs';
import { useCallback, useId, useRef } from 'react';
import { useTranslation } from 'react-i18next';

import { GalleryBoardsPanel } from './GalleryBoardsPanel';
import { GalleryImageGrid } from './GalleryImageGrid';
import { GalleryItemFilterMenu } from './GalleryItemFilterMenu';
import { GalleryItemSearch } from './GalleryItemSearch';
import { GallerySelectionBar } from './GallerySelectionBar';
import { GalleryStarredFilterToggle } from './GalleryStarredFilterToggle';
import { GalleryUploadButton } from './GalleryUploadButton';
import { GalleryViewTabs } from './GalleryViewTabs';
import { useGalleryWidget } from './GalleryWidgetContext';

const CHROME_INSET_PADDING_TOP = 'calc(var(--chakra-spacing-2) + var(--wb-center-chrome-inset, 0px))';
const CENTER_HANDLE_INSET = { pb: '2', pt: CHROME_INSET_PADDING_TOP } as const;

export const GalleryWideLayout = () => {
  const { t } = useTranslation();
  const { actions, gallery, region } = useGalleryWidget();
  const { boardPanelCollapsed, boardPanelWidthPx } = gallery.settings;
  const viewTabsIdBase = useId();
  const boardPanelRef = useRef<HTMLDivElement>(null);

  // The grid's "Show all media" hands focus here when it removes itself.
  const mediaFilterTriggerRef = useRef<HTMLButtonElement>(null);

  const handleCommitWidth = useCallback(
    (boardPanelWidthPx: number) => actions.updateSettings({ boardPanelWidthPx }),
    [actions]
  );

  return (
    <Flex h="full" maxW="full" minH="0" minW="0" w="full">
      {boardPanelCollapsed ? null : (
        <>
          <Flex
            ref={boardPanelRef}
            flexShrink={0}
            minH="0"
            overflow="hidden"
            pb="2"
            pe="2"
            ps="2"
            pt={CHROME_INSET_PADDING_TOP}
            w={`${boardPanelWidthPx}px`}
          >
            <GalleryBoardsPanel />
          </Flex>
          {/* The handle is the sidebar's edge. A docked or floating frame closes its header with a rule, so the line
              runs from that rule to the bottom edge. In the center it paints above the floating chrome islands, so
              it is inset like the panel instead of crossing them. */}
          <Flex flexShrink={0} {...(region === 'center' ? CENTER_HANDLE_INSET : null)}>
            <ResizeHandle
              label={t('widgets.gallery.resizeBoardPanel')}
              max={GALLERY_BOARD_PANEL_MAX_WIDTH_PX}
              min={GALLERY_BOARD_PANEL_MIN_WIDTH_PX}
              orientation="vertical"
              pane="before"
              paneRef={boardPanelRef}
              value={boardPanelWidthPx}
              onCommit={handleCommitWidth}
            />
          </Flex>
        </>
      )}
      <Stack flex="1" gap="0" minH="0" minW="0">
        <HStack gap="1" minW="0" pb="2" pe="3" ps="3" pt={CHROME_INSET_PADDING_TOP}>
          <GalleryViewTabs idBase={viewTabsIdBase} />
          <Spacer />
          <Box flex="1" maxW="22rem" minW="9rem">
            <GalleryItemSearch />
          </Box>
          <GalleryStarredFilterToggle />
          <GalleryItemFilterMenu triggerRef={mediaFilterTriggerRef} />
          <GalleryUploadButton
            boards={gallery.boards}
            selectedBoardId={gallery.listingBoardId}
            onUploadFiles={actions.uploadFiles}
          />
        </HStack>
        <Box
          aria-labelledby={segmentTabsTabId(viewTabsIdBase, gallery.galleryView)}
          flex="1"
          id={segmentTabsPanelId(viewTabsIdBase)}
          minH="0"
          minW="0"
          pb="2"
          pe="3"
          ps="3"
          role="tabpanel"
        >
          <GalleryImageGrid mediaFilterTriggerRef={mediaFilterTriggerRef} />
        </Box>
        <GallerySelectionBar />
      </Stack>
    </Flex>
  );
};