All files / src/components/settings/section SettingsSectionUI.tsx

0% Statements 0/24
0% Branches 0/2
0% Functions 0/6
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                                                                                                                                                                                                                 
import React, { useCallback } from "react";
import Path from "path";
import l10n from "shared/lib/lang/l10n";
import settingsActions from "store/features/settings/settingsActions";
import { CardAnchor, CardHeading } from "ui/cards/Card";
import { SearchableSettingRow } from "ui/form/SearchableSettingRow";
import { SettingRowInput, SettingRowLabel } from "ui/form/SettingRow";
import { SearchableCard } from "ui/cards/SearchableCard";
import { FontSelect } from "components/forms/FontSelect";
import electronActions from "store/features/electron/electronActions";
import { UIAssetPreview } from "components/forms/UIAssetPreviewButton";
import { useAppDispatch, useAppSelector } from "store/hooks";
 
interface SettingsSectionUIProps {
  searchTerm: string;
}
 
export const SettingsSectionUI = ({ searchTerm }: SettingsSectionUIProps) => {
  const dispatch = useAppDispatch();
 
  const defaultFontId = useAppSelector(
    (state) => state.project.present.settings.defaultFontId,
  );
 
  const onChangeDefaultFontId = useCallback(
    (e: string) =>
      dispatch(
        settingsActions.editSettings({
          defaultFontId: e,
        }),
      ),
    [dispatch],
  );
 
  const openAsset = useCallback(
    (path: string) => {
      dispatch(
        electronActions.openFile({
          filename: Path.join("assets", path),
          type: "image",
        }),
      );
    },
    [dispatch],
  );
 
  return (
    <SearchableCard
      searchTerm={searchTerm}
      searchMatches={[
        l10n("FIELD_DEFAULT_FONT"),
        l10n("FIELD_CURSOR_IMAGE"),
        l10n("FIELD_FRAME_IMAGE"),
      ]}
    >
      <CardAnchor id="settingsUI" />
      <CardHeading>{l10n("MENU_UI_ELEMENTS")}</CardHeading>
 
      <SearchableSettingRow
        searchTerm={searchTerm}
        searchMatches={[l10n("FIELD_DEFAULT_FONT")]}
      >
        <SettingRowLabel>{l10n("FIELD_DEFAULT_FONT")}</SettingRowLabel>
        <SettingRowInput>
          <FontSelect
            name="defaultFont"
            value={defaultFontId || ""}
            onChange={onChangeDefaultFontId}
          />
        </SettingRowInput>
      </SearchableSettingRow>
 
      <SearchableSettingRow
        searchTerm={searchTerm}
        searchMatches={[l10n("FIELD_CURSOR_IMAGE")]}
      >
        <SettingRowLabel>{l10n("FIELD_CURSOR_IMAGE")}</SettingRowLabel>
        <SettingRowInput>
          <UIAssetPreview
            path="ui/cursor.png"
            onClick={() => {
              openAsset("ui/cursor.png");
            }}
          />
        </SettingRowInput>
      </SearchableSettingRow>
 
      <SearchableSettingRow
        searchTerm={searchTerm}
        searchMatches={[l10n("FIELD_FRAME_IMAGE")]}
      >
        <SettingRowLabel>{l10n("FIELD_FRAME_IMAGE")}</SettingRowLabel>
        <SettingRowInput>
          <UIAssetPreview
            path="ui/frame.png"
            onClick={() => {
              openAsset("ui/frame.png");
            }}
          />
        </SettingRowInput>
      </SearchableSettingRow>
    </SearchableCard>
  );
};