Normalize SoapboxConfig
This commit is contained in:
parent
2c0ce084c3
commit
483b28988f
8 changed files with 113 additions and 3 deletions
Binary file not shown.
|
@ -24,7 +24,7 @@ interface ISiteWallet {
|
|||
|
||||
const SiteWallet: React.FC<ISiteWallet> = ({ limit }): JSX.Element => {
|
||||
const addresses: ImmutableList<Address> =
|
||||
useSoapboxConfig().get('cryptoAddresses').map(normalizeAddress);
|
||||
useSoapboxConfig().cryptoAddresses.map(normalizeAddress);
|
||||
|
||||
const coinList = typeof limit === 'number' ? addresses.take(limit) : addresses;
|
||||
|
||||
|
|
Binary file not shown.
|
@ -1,9 +1,9 @@
|
|||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||
import { useAppSelector } from 'soapbox/hooks';
|
||||
|
||||
import type { Map as ImmutableMap } from 'immutable';
|
||||
import type { SoapboxConfig } from 'soapbox/types/soapbox';
|
||||
|
||||
/** Get the Soapbox config from the store */
|
||||
export const useSoapboxConfig = (): ImmutableMap<string, any> => {
|
||||
export const useSoapboxConfig = (): SoapboxConfig => {
|
||||
return useAppSelector((state) => getSoapboxConfig(state));
|
||||
};
|
||||
|
|
|
@ -7,3 +7,5 @@ export { MentionRecord, normalizeMention } from './mention';
|
|||
export { NotificationRecord, normalizeNotification } from './notification';
|
||||
export { PollRecord, PollOptionRecord, normalizePoll } from './poll';
|
||||
export { StatusRecord, normalizeStatus } from './status';
|
||||
|
||||
export { SoapboxConfigRecord, normalizeSoapboxConfig } from './soapbox/soapbox_config';
|
||||
|
|
BIN
app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.js
Normal file
BIN
app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.js
Normal file
Binary file not shown.
103
app/soapbox/normalizers/soapbox/soapbox_config.ts
Normal file
103
app/soapbox/normalizers/soapbox/soapbox_config.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
import {
|
||||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
const DEFAULT_COLORS = ImmutableMap({
|
||||
gray: ImmutableMap({
|
||||
50: '#f9fafb',
|
||||
100: '#f3f4f6',
|
||||
200: '#e5e7eb',
|
||||
300: '#d1d5db',
|
||||
400: '#9ca3af',
|
||||
500: '#6b7280',
|
||||
600: '#4b5563',
|
||||
700: '#374151',
|
||||
800: '#1f2937',
|
||||
900: '#111827',
|
||||
}),
|
||||
success: ImmutableMap({
|
||||
50: '#f0fdf4',
|
||||
100: '#dcfce7',
|
||||
200: '#bbf7d0',
|
||||
300: '#86efac',
|
||||
400: '#4ade80',
|
||||
500: '#22c55e',
|
||||
600: '#16a34a',
|
||||
700: '#15803d',
|
||||
800: '#166534',
|
||||
900: '#14532d',
|
||||
}),
|
||||
danger: ImmutableMap({
|
||||
50: '#fef2f2',
|
||||
100: '#fee2e2',
|
||||
200: '#fecaca',
|
||||
300: '#fca5a5',
|
||||
400: '#f87171',
|
||||
500: '#ef4444',
|
||||
600: '#dc2626',
|
||||
700: '#b91c1c',
|
||||
800: '#991b1b',
|
||||
900: '#7f1d1d',
|
||||
}),
|
||||
'gradient-purple': '#b8a3f9',
|
||||
'gradient-blue': '#9bd5ff',
|
||||
'sea-blue': '#2feecc',
|
||||
});
|
||||
|
||||
export const SoapboxConfigRecord = ImmutableRecord({
|
||||
logo: '',
|
||||
banner: '',
|
||||
brandColor: '', // Empty
|
||||
accentColor: '',
|
||||
colors: ImmutableMap(),
|
||||
copyright: `♥${new Date().getFullYear()}. Copying is an act of love. Please copy and share.`,
|
||||
customCss: ImmutableList<string>(),
|
||||
defaultSettings: ImmutableMap(),
|
||||
extensions: ImmutableMap(),
|
||||
greentext: false,
|
||||
promoPanel: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
}),
|
||||
navlinks: ImmutableMap({
|
||||
homeFooter: ImmutableList(),
|
||||
}),
|
||||
allowedEmoji: ImmutableList<string>([
|
||||
'👍',
|
||||
'❤️',
|
||||
'😆',
|
||||
'😮',
|
||||
'😢',
|
||||
'😩',
|
||||
]),
|
||||
verifiedIcon: '',
|
||||
verifiedCanEditName: false,
|
||||
displayFqn: true,
|
||||
cryptoAddresses: ImmutableList<ImmutableMap<string, any>>(),
|
||||
cryptoDonatePanel: ImmutableMap({
|
||||
limit: 1,
|
||||
}),
|
||||
aboutPages: ImmutableMap(),
|
||||
betaPages: ImmutableMap(),
|
||||
mobilePages: ImmutableMap(),
|
||||
authenticatedProfile: true,
|
||||
singleUserMode: false,
|
||||
singleUserModeProfile: '',
|
||||
}, 'SoapboxConfig');
|
||||
|
||||
type SoapboxConfigMap = ImmutableMap<string, any>;
|
||||
|
||||
const normalizeColors = (soapboxConfig: SoapboxConfigMap): SoapboxConfigMap => {
|
||||
const colors = DEFAULT_COLORS.mergeDeep(soapboxConfig.get('colors'));
|
||||
return soapboxConfig.set('colors', colors);
|
||||
};
|
||||
|
||||
export const normalizeSoapboxConfig = (soapboxConfig: Record<string, any>) => {
|
||||
return SoapboxConfigRecord(
|
||||
ImmutableMap(fromJS(soapboxConfig)).withMutations(soapboxConfig => {
|
||||
normalizeColors(soapboxConfig);
|
||||
}),
|
||||
);
|
||||
};
|
5
app/soapbox/types/soapbox.ts
Normal file
5
app/soapbox/types/soapbox.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { SoapboxConfigRecord } from 'soapbox/normalizers';
|
||||
|
||||
type SoapboxConfig = ReturnType<typeof SoapboxConfigRecord>;
|
||||
|
||||
export { SoapboxConfig };
|
Loading…
Reference in a new issue