Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

4.5 KB
Raw Blame
'use client';

import { isDesktop } from '@lobechat/const';
import { Flexbox } from '@lobehub/ui';

import SkeletonBar from '../../Bar';
import { SettingsFormSkeleton, SWITCH_CONTROL } from '../Section';
import { useSkeletonText } from '../useSkeletonText';
import type { SettingsTabSkeleton } from './types';

/** The idle auto-save hint ("loaded the latest version") on the right of a group head. */
const SAVE_HINT = <SkeletonBar height={20} width={102} />;

/** A `Select` at 50% of the 335px control column, right-aligned as the loaded one. */
const HALF_SELECT = (
  <Flexbox horizontal justify={'flex-end'} width={'100%'}>
    <SkeletonBar height={32} width={'50%'} />
  </Flexbox>
);

/** General: theme picker, language, motion and density. */
export const CommonSectionSkeleton = () => {
  const text = useSkeletonText('setting');

  return (
    <SettingsFormSkeleton
      groups={[
        {
          extra: SAVE_HINT,
          items: [
            {
              control: { height: 86, radius: 8, width: 332 },
              label: text('settingCommon.themeMode.title', 32, 14),
              minWidth: undefined,
            },
            { control: HALF_SELECT, label: text('settingCommon.lang.title', 32, 14) },
            {
              control: { height: 38, radius: 8, width: 230 },
              label: text('settingAppearance.animationMode.title', 64, 14),
              minWidth: undefined,
            },
            {
              control: { height: 38, radius: 8, width: 165 },
              label: text('settingAppearance.density.title', 64, 14),
              minWidth: undefined,
            },
          ],
          title: text('settingCommon.title', 72),
        },
      ]}
    />
  );
};

/** Theme: the 332x200 preview, then the primary and neutral swatch rows. */
export const AppearanceSectionSkeleton = () => {
  const text = useSkeletonText('setting');

  return (
    <SettingsFormSkeleton
      groups={[
        {
          extra: SAVE_HINT,
          items: [
            {
              control: { height: 200, radius: 8, width: 332 },
              label: text('settingAppearance.preview.title', 48, 14),
              minWidth: undefined,
            },
            {
              control: { height: 24, radius: 12, width: 425 },
              label: text('settingAppearance.primaryColor.title', 48, 14),
              minWidth: undefined,
            },
            {
              control: { height: 24, radius: 12, width: 174 },
              label: text('settingAppearance.neutralColor.title', 48, 14),
              minWidth: undefined,
            },
          ],
          title: text('settingAppearance.title', 72),
        },
      ]}
    />
  );
};

/** Electron only: the tray-icon switch. */
const DesktopSectionSkeleton = () => {
  const text = useSkeletonText('setting');
  if (!isDesktop) return null;

  return (
    <SettingsFormSkeleton
      groups={[
        {
          items: [
            {
              control: SWITCH_CONTROL,
              label: text('settingAppearance.appTray.title', 96, 14),
              minWidth: undefined,
            },
          ],
          title: text('settingAppearance.desktop.title', 48),
        },
      ]}
    />
  );
};

/** Fonts: the four font-stack rows (Electron only) and antialiasing. */
export const FontSectionSkeleton = () => {
  const text = useSkeletonText('setting');
  const fontRow = (key: string) => ({
    control: { height: 32, width: 320 },
    desc: text(`settingAppearance.font.${key}.desc`, 240, 12),
    label: text(`settingAppearance.font.${key}.title`, 96, 14),
    minWidth: undefined,
  });

  return (
    <SettingsFormSkeleton
      groups={[
        {
          extra: SAVE_HINT,
          items: [
            ...(isDesktop
              ? ['fontFamily', 'fallback', 'monospace', 'monospaceFallback'].map(fontRow)
              : []),
            {
              control: SWITCH_CONTROL,
              desc: text('settingAppearance.font.antialiasing.desc', 360, 12),
              label: text('settingAppearance.font.antialiasing.title', 72, 14),
              minWidth: undefined,
            },
          ],
          title: text('settingAppearance.font.title', 32),
        },
      ]}
    />
  );
};

/** The four appearance sections, as direct children of the 36px-gap settings container. */
const Body = () => (
  <>
    <CommonSectionSkeleton />
    <AppearanceSectionSkeleton />
    <DesktopSectionSkeleton />
    <FontSectionSkeleton />
  </>
);

const AppearanceSkeleton: SettingsTabSkeleton = { Body };

export default AppearanceSkeleton;