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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import React, { useCallback } from "react"; import { SingleValue } from "react-select"; import l10n from "shared/lib/lang/l10n"; import { Alert } from "ui/alerts/Alert"; import { Button } from "ui/buttons/Button"; import { CardAnchor, CardButtons, CardHeading } from "ui/cards/Card"; import { SearchableCard } from "ui/cards/SearchableCard"; import { Checkbox } from "ui/form/Checkbox"; import { SearchableSettingRow } from "ui/form/SearchableSettingRow"; import { SettingRowInput, SettingRowLabel } from "ui/form/SettingRow"; import { Select } from "ui/form/Select"; import settingsActions from "store/features/settings/settingsActions"; import { CartType } from "store/features/settings/settingsState"; import { useAppDispatch, useAppSelector } from "store/hooks"; interface SettingsSectionCartProps { searchTerm: string; } interface CartTypeOption { value: CartType; label: string; } const cartOptions: CartTypeOption[] = [ { value: "mbc5", label: "MBC5", }, { value: "mbc3", label: "MBC3", }, ]; export const SettingsSectionCart = ({ searchTerm, }: SettingsSectionCartProps) => { const dispatch = useAppDispatch(); const cartType = useAppSelector((state) => state.project.present.settings.cartType) || "mbc5"; const batterylessEnabled = useAppSelector( (state) => state.project.present.settings.batterylessEnabled, ); const onChangeCartType = useCallback( (cartType: CartType) => { dispatch(settingsActions.editSettings({ cartType })); }, [dispatch], ); const onToggleBatteryless = useCallback(() => { dispatch( settingsActions.editSettings({ batterylessEnabled: !batterylessEnabled }), ); }, [dispatch, batterylessEnabled]); const onRestoreDefault = useCallback(() => { dispatch( settingsActions.editSettings({ cartType: undefined, batterylessEnabled: false, }), ); }, [dispatch]); const currentValue = cartOptions.find((option) => option.value === cartType) || cartOptions[0]; return ( <SearchableCard searchTerm={searchTerm} searchMatches={[l10n("SETTINGS_CART_TYPE")]} > <CardAnchor id="settingsCartType" /> <CardHeading>{l10n("SETTINGS_CART_TYPE")}</CardHeading> <SearchableSettingRow searchTerm={searchTerm} searchMatches={[l10n("SETTINGS_CART_TYPE")]} > <SettingRowLabel>{l10n("SETTINGS_CART_TYPE")}</SettingRowLabel> <SettingRowInput> <Select value={currentValue} options={cartOptions} onChange={(newValue: SingleValue<CartTypeOption>) => { Iif (newValue) { onChangeCartType(newValue.value); } }} /> </SettingRowInput> </SearchableSettingRow> <SearchableSettingRow searchTerm={searchTerm} searchMatches={[l10n("FIELD_CART_BATTERYLESS")]} > <SettingRowLabel>{l10n("FIELD_CART_BATTERYLESS")}</SettingRowLabel> <SettingRowInput> <Checkbox id="batterylessEnabled" name="batterylessEnabled" checked={batterylessEnabled} onChange={onToggleBatteryless} /> {batterylessEnabled && ( <div style={{ marginTop: 3 }}> <Alert variant="warning"> <p>{l10n("FIELD_CART_BATTERYLESS_MORE_INFO_1")}</p> <p>{l10n("FIELD_CART_BATTERYLESS_MORE_INFO_2")}</p> <p>{l10n("FIELD_CART_BATTERYLESS_MORE_INFO_3")}</p> </Alert> </div> )} </SettingRowInput> </SearchableSettingRow> {!searchTerm && ( <CardButtons> <Button onClick={onRestoreDefault}> {l10n("FIELD_RESTORE_DEFAULT")} </Button> </CardButtons> )} </SearchableCard> ); }; |