diff --git a/app/soapbox/features/soapbox_config/index.tsx b/app/soapbox/features/soapbox_config/index.tsx index c3ca22147..676656e5c 100644 --- a/app/soapbox/features/soapbox_config/index.tsx +++ b/app/soapbox/features/soapbox_config/index.tsx @@ -6,10 +6,9 @@ import { updateConfig } from 'soapbox/actions/admin'; import { uploadMedia } from 'soapbox/actions/media'; import snackbar from 'soapbox/actions/snackbar'; import Icon from 'soapbox/components/icon'; -import { Column, HStack, Input } from 'soapbox/components/ui'; +import { Column, Form, FormActions, Button, HStack, Input } from 'soapbox/components/ui'; import Streamfield, { StreamfieldComponent } from 'soapbox/components/ui/streamfield/streamfield'; import { - SimpleForm, FieldsGroup, TextInput, SimpleInput, @@ -29,7 +28,7 @@ import IconPicker from './components/icon-picker'; import SitePreview from './components/site-preview'; import type { ColorChangeHandler, ColorResult } from 'react-color'; -import type { CryptoAddress } from 'soapbox/types/soapbox'; +import type { CryptoAddress, PromoPanelItem } from 'soapbox/types/soapbox'; const messages = defineMessages({ heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' }, @@ -67,6 +66,43 @@ const templates: Record = { cryptoAddress: ImmutableMap({ ticker: '', address: '', note: '' }), }; +const PromoPanelInput: StreamfieldComponent = ({ value, onChange }) => { + const intl = useIntl(); + + const handleIconChange = (icon: any) => { + onChange(value.set('icon', icon.id)); + }; + + const handleChange = (key: 'text' | 'url'): React.ChangeEventHandler => { + return e => { + onChange(value.set(key, e.currentTarget.value)); + }; + }; + + return ( + + + + + + + ); +}; + const SoapboxConfig: React.FC = () => { const intl = useIntl(); const dispatch = useAppDispatch(); @@ -153,13 +189,13 @@ const SoapboxConfig: React.FC = () => { }; }; - const handleDeleteItem = (path: ConfigPath) => { - return () => { - const newData = data.deleteIn(path); - setData(newData); - }; + const deleteItem = (path: ConfigPath) => { + const newData = data.deleteIn(path); + setData(newData); }; + const handleDeleteItem = (path: ConfigPath) => () => deleteItem(path); + const handleItemChange = ( path: Array, key: string, @@ -175,10 +211,23 @@ const SoapboxConfig: React.FC = () => { ); }; - const handlePromoItemChange = (index: number, key: string, field: any, getValue?: ValueGetter) => { - return handleItemChange( - ['promoPanel', 'items', index], key, field, templates.promoPanelItem, getValue, - ); + const handleStreamItemChange = (path: ConfigPath) => { + return (values: any[]) => { + setConfig(path, ImmutableList(values)); + }; + }; + + const addStreamItem = (path: ConfigPath, template: Template) => { + return () => { + const items = data.getIn(path); + setConfig(path, items.push(template)); + }; + }; + + const deleteStreamItem = (path: ConfigPath) => { + return (i: number) => { + deleteItem([...path, i]); + }; }; const handleHomeFooterItemChange = (index: number, key: string, field: any, getValue?: ValueGetter) => { @@ -187,20 +236,6 @@ const SoapboxConfig: React.FC = () => { ); }; - const handleCryptoAdressChange = (values: CryptoAddress[]) => { - setConfig(['cryptoAddresses'], ImmutableList(values)); - }; - - const addCryptoAddress = () => { - const cryptoAddresses = data.get('cryptoAddresses'); - setConfig(['cryptoAddresses'], cryptoAddresses.push(templates.cryptoAddress)); - }; - - const removeCryptoAddress = (i: number) => { - const cryptoAddresses = data.get('cryptoAddresses'); - setConfig(['cryptoAddresses'], cryptoAddresses.delete(i)); - }; - const handleEditJSON: React.ChangeEventHandler = e => { setRawJSON(e.target.value); }; @@ -226,7 +261,7 @@ const SoapboxConfig: React.FC = () => { return ( - +
@@ -318,48 +353,17 @@ const SoapboxConfig: React.FC = () => { /> )} - -
- - - - - - {intl.formatMessage(messages.promoPanelIconsLink)} }} /> - - { - soapbox.promoPanel.items.map((field, i) => ( -
- val.id)} - /> - - - -
- )) - } -
-
- - -
-
-
-
+ + } + hint={} + component={PromoPanelInput} + values={soapbox.promoPanel.items.toArray()} + onChange={handleStreamItemChange(['promoPanel', 'items'])} + onAddItem={addStreamItem(['promoPanel', 'items'], templates.promoPanel)} + onRemoveItem={deleteStreamItem(['promoPanel', 'items'])} + /> +
@@ -399,9 +403,9 @@ const SoapboxConfig: React.FC = () => { hint={} component={CryptoAddressInput} values={soapbox.cryptoAddresses.toArray()} - onChange={handleCryptoAdressChange} - onAddItem={addCryptoAddress} - onRemoveItem={removeCryptoAddress} + onChange={handleStreamItemChange(['cryptoAddresses'])} + onAddItem={addStreamItem(['cryptoAddresses'], templates.cryptoAddress)} + onRemoveItem={deleteStreamItem(['cryptoAddresses'])} /> @@ -431,12 +435,12 @@ const SoapboxConfig: React.FC = () => {
-
- -
- + + +
); };