From 483b28988f1859552ff096863915a675588feda3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 28 Mar 2022 14:58:50 -0500 Subject: [PATCH] Normalize SoapboxConfig --- app/soapbox/actions/soapbox.js | Bin 5246 -> 3557 bytes .../crypto_donate/components/site_wallet.tsx | 2 +- app/soapbox/features/soapbox_config/index.js | Bin 25704 -> 25407 bytes app/soapbox/hooks/useSoapboxConfig.ts | 4 +- app/soapbox/normalizers/index.ts | 2 + .../soapbox/__tests__/soapbox_config-test.js | Bin 0 -> 349 bytes .../normalizers/soapbox/soapbox_config.ts | 103 ++++++++++++++++++ app/soapbox/types/soapbox.ts | 5 + 8 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.js create mode 100644 app/soapbox/normalizers/soapbox/soapbox_config.ts create mode 100644 app/soapbox/types/soapbox.ts diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index 2871e2aae56ab3e0bca8ecbd27117ffb9798a64d..bc3bdc82fd24695bf25d7a972e0bc465771814bb 100644 GIT binary patch delta 123 zcmeyT@l<-kdXs8}y!@iv#GK5k)ZqNYf~5Qk=ls01%yflXg|wplTm|)Fh^RhXSyA!E trKZf2nOM9hFXQx?tih!-xrqC*8eAU57!9a)O}*UIqV!aa&9yv?901EmF4h15 delta 1818 zcmaKs&x;&I6vq))5YOJs;emmf#m!`@e@+i1AiD_!jIM}?myp+0uVxy%tD5fWHA52S zUkL2UKfr@05&szPqImLO5UZ!FXKL20bDQsb_1>#bef$0S(Ld8SKmYRgC-2_nTD1l? zgbh3ZMc=~(8k(NYR%9M`W%;cQOs_vY`C?n@m0rSRa`pk(Uye#q7QP-0dd4wCIo8?Q2JsL`@-$e?$AHz7L67n{PC`#l z2R%$97Bf#@3_6oR7N(w_Ii0aZaL`|$_Q?DG&~}z&dmFSpn7I@(^6EM;f=f<^x&RJL zp37AD_i->r3?uY(2ZqIqc_=)61d}9j=wHBs z+4fJ)qBsl=2L>`d7=dcl+wrYt+H)Zp$iQni8ipt!Uw2$2apdFJyZbvZl4FdqSIBXZ zi@<|?;9MrOzejw z3j6WhtGlKyY0^{77Z}QHpMA*5%WlZXauLhD^gimd^-Vg8rxt3TW5Z(CqoJ z3>99Lh5GJhyK$MVbw!W0Hb(}%alPwjCtuF5s3~MY;)z|#ht)c&=cpcu!hDVuEkR=0 z()CX#f%PSCHnq{83enizK>iedlOgLuE4$zS?;XmbDl8c`Ty1<_%ynljadlL_-`HD6 zJ|}~3i@R{8^P;qU|69N%U}x6Wrvz10QT8sc}=#Kq7 zj$`}7lgagOCx1;_jdiYH%qnVDbU{>qQ<(L1s?R{3!h?sP;ngcpXYlJE@4fT>zpD7y AoB#j- diff --git a/app/soapbox/features/crypto_donate/components/site_wallet.tsx b/app/soapbox/features/crypto_donate/components/site_wallet.tsx index af59647967..f0b6accd7d 100644 --- a/app/soapbox/features/crypto_donate/components/site_wallet.tsx +++ b/app/soapbox/features/crypto_donate/components/site_wallet.tsx @@ -24,7 +24,7 @@ interface ISiteWallet { const SiteWallet: React.FC = ({ limit }): JSX.Element => { const addresses: ImmutableList
= - useSoapboxConfig().get('cryptoAddresses').map(normalizeAddress); + useSoapboxConfig().cryptoAddresses.map(normalizeAddress); const coinList = typeof limit === 'number' ? addresses.take(limit) : addresses; diff --git a/app/soapbox/features/soapbox_config/index.js b/app/soapbox/features/soapbox_config/index.js index 84d80eea3566f7d9aefeed88f9ba000724ef65ca..16cff42f3c031b0a21f1f15f33afd9f39631d4bf 100644 GIT binary patch delta 504 zcmaEHf^q*b#tny=CNb-(Dmdrol;-9s)GDME<>xA>7w0DyB;{A=C+FuDd?KJ}v1lG36)g=#JZAjr(i zEXhpFaY-ymv{EQ8Ni0d#gW55q5N@4-IG#L2T4OH{qfDG&LkYDJa_7D&X+$R0S23Fgll4=GfN7fiL|Ae1R^cjXxJ4xy znZ+-Xe?Onm>w23jjTnmYELn1T?^;L^b*020&yd2Z(C1L78=;Qdp$r zChrneKr&Z!@@LUX7=Lqtm>J9DXhnWrNI=1C+9Rb7SMpqH9W%%+z<{k*fP2V6QJS+F z?y`>}q9)J)MT%`_um?0?dNlQNQ;X7pNg=gB17^`7xoL7xwt}Lqtpb){sgqZMxn;7R wf()i|RHr|bw}mO+tfWxED3l3wyRCY1e!99sMrvY8W?uSaMgzIcdlj1;0si#$0ssI2 diff --git a/app/soapbox/hooks/useSoapboxConfig.ts b/app/soapbox/hooks/useSoapboxConfig.ts index 2e51e59233..92a1ddc212 100644 --- a/app/soapbox/hooks/useSoapboxConfig.ts +++ b/app/soapbox/hooks/useSoapboxConfig.ts @@ -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 => { +export const useSoapboxConfig = (): SoapboxConfig => { return useAppSelector((state) => getSoapboxConfig(state)); }; diff --git a/app/soapbox/normalizers/index.ts b/app/soapbox/normalizers/index.ts index c4a34d66c2..613de53313 100644 --- a/app/soapbox/normalizers/index.ts +++ b/app/soapbox/normalizers/index.ts @@ -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'; diff --git a/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.js b/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.js new file mode 100644 index 0000000000000000000000000000000000000000..f564fd17dd1c1315925a941281ce27ca4c6e8061 GIT binary patch literal 349 zcmZ{gv2MdK3`BQ-#ch&+LivCo9h#|Y`T>Px(S-oXG(;H)V&vaz$M%q-8MxftI}(g} z;8HQ+LM@j7C-}^Htj;Ieq&vF887l6&IyOz*xt>dQDcua_GvthN2^Z=JN%lrZkGj#I+ literal 0 HcmV?d00001 diff --git a/app/soapbox/normalizers/soapbox/soapbox_config.ts b/app/soapbox/normalizers/soapbox/soapbox_config.ts new file mode 100644 index 0000000000..0696eb314c --- /dev/null +++ b/app/soapbox/normalizers/soapbox/soapbox_config.ts @@ -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(), + defaultSettings: ImmutableMap(), + extensions: ImmutableMap(), + greentext: false, + promoPanel: ImmutableMap({ + items: ImmutableList(), + }), + navlinks: ImmutableMap({ + homeFooter: ImmutableList(), + }), + allowedEmoji: ImmutableList([ + '👍', + '❤️', + '😆', + '😮', + '😢', + '😩', + ]), + verifiedIcon: '', + verifiedCanEditName: false, + displayFqn: true, + cryptoAddresses: ImmutableList>(), + cryptoDonatePanel: ImmutableMap({ + limit: 1, + }), + aboutPages: ImmutableMap(), + betaPages: ImmutableMap(), + mobilePages: ImmutableMap(), + authenticatedProfile: true, + singleUserMode: false, + singleUserModeProfile: '', +}, 'SoapboxConfig'); + +type SoapboxConfigMap = ImmutableMap; + +const normalizeColors = (soapboxConfig: SoapboxConfigMap): SoapboxConfigMap => { + const colors = DEFAULT_COLORS.mergeDeep(soapboxConfig.get('colors')); + return soapboxConfig.set('colors', colors); +}; + +export const normalizeSoapboxConfig = (soapboxConfig: Record) => { + return SoapboxConfigRecord( + ImmutableMap(fromJS(soapboxConfig)).withMutations(soapboxConfig => { + normalizeColors(soapboxConfig); + }), + ); +}; diff --git a/app/soapbox/types/soapbox.ts b/app/soapbox/types/soapbox.ts new file mode 100644 index 0000000000..865a6567c9 --- /dev/null +++ b/app/soapbox/types/soapbox.ts @@ -0,0 +1,5 @@ +import { SoapboxConfigRecord } from 'soapbox/normalizers'; + +type SoapboxConfig = ReturnType; + +export { SoapboxConfig };