diff --git a/web/components/admin/config/general/AppearanceConfig.tsx b/web/components/admin/config/general/AppearanceConfig.tsx index 2530b49da..baa25f2c2 100644 --- a/web/components/admin/config/general/AppearanceConfig.tsx +++ b/web/components/admin/config/general/AppearanceConfig.tsx @@ -1,4 +1,4 @@ -import React, { FC, useContext, useEffect, useState } from 'react'; +import React, { FC, useContext, useCallback, useEffect, useState } from 'react'; import { Button, Col, Collapse, Row, Slider, Space } from 'antd'; import Paragraph from 'antd/lib/typography/Paragraph'; @@ -24,6 +24,11 @@ interface AppearanceVariable { description: string; } +type ColorCollectionProps = { + variables: { name; description; value }[]; + updateColor: (variable: string, color: string, description: string) => void; +}; + const chatColorVariables = [ { name: 'theme-color-users-0', description: '' }, { name: 'theme-color-users-1', description: '' }, @@ -70,18 +75,18 @@ const allAvailableValues = [...componentColorVariables, ...chatColorVariables, . ); // eslint-disable-next-line react/function-component-definition -function ColorPicker({ - value, - name, - description, - onChange, -}: { - value: string; - name: string; - description: string; - onChange: (name: string, value: string, description: string) => void; -}) { - return ( +const ColorPicker = React.memo( + ({ + value, + name, + description, + onChange, + }: { + value: string; + name: string; + description: string; + onChange: (name: string, value: string, description: string) => void; + }) => (
{description}
- ); -} + ), +); + +const ColorCollection: FC = ({ variables, updateColor }) => { + const cc = variables.map(colorVar => { + const { name, description, value } = colorVar; + + return ( + + ); + }); + // eslint-disable-next-line react/jsx-no-useless-fragment + return <>{cc}; +}; // eslint-disable-next-line react/function-component-definition export default function Appearance() { @@ -144,12 +167,12 @@ export default function Appearance() { setCustomValues(c); }, [appearanceVariables]); - const updateColor = (variable: string, color: string, description: string) => { - setCustomValues({ - ...customValues, + const updateColor = useCallback((variable: string, color: string, description: string) => { + setCustomValues(oldCustomValues => ({ + ...oldCustomValues, [variable]: { value: color, description }, - }); - }; + })); + }, []); const reset = async () => { await postConfigUpdateToAPI({ @@ -193,34 +216,18 @@ export default function Appearance() { updateColor(variableName, `${value.toString()}px`, ''); }; - type ColorCollectionProps = { - variables: { name; description }[]; - }; - // eslint-disable-next-line react/no-unstable-nested-components - const ColorCollection: FC = ({ variables }) => { - const cc = variables.map(colorVar => { - const source = customValues?.[colorVar.name] ? customValues : defaultValues; - const { name, description } = colorVar; - const { value } = source[name]; - - return ( - - ); - }); - // eslint-disable-next-line react/jsx-no-useless-fragment - return <>{cc}; - }; - if (!defaultValues) { return
Loading...
; } + const transformToColorMap = variables => + variables.map(colorVar => { + const source = customValues?.[colorVar.name] ? customValues : defaultValues; + const { name, description } = colorVar; + const { value } = source[name]; + return { name, description, value }; + }); + return ( Customize Appearance @@ -232,15 +239,20 @@ export default function Appearance() { Certain sections of the interface can be customized by selecting new colors for them.

- + Chat User Colors} key="2"> - + - Other Settings} key="4"> How rounded should corners be?