From c81f4a6db89af42f9cdc59c222033a2bc581781e Mon Sep 17 00:00:00 2001 From: devcshort <13677134+devcshort@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:10:17 -0700 Subject: [PATCH] fix: Fix flags and html parsing --- .../favorites/components/favorite.tsx | 1 - src/shared/context/flags-context.ts | 13 +----------- src/shared/lib/parse-html.tsx | 4 +++- src/shared/lib/server-utils.ts | 20 +++++++++++-------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/features/favorites/components/favorite.tsx b/src/features/favorites/components/favorite.tsx index 54a4f0a6..e1867135 100644 --- a/src/features/favorites/components/favorite.tsx +++ b/src/features/favorites/components/favorite.tsx @@ -3,7 +3,6 @@ import { ReferralButton } from '@/shared/components/referral-button'; import { Card, CardContent, - CardDescription, CardFooter, CardHeader, CardTitle, diff --git a/src/shared/context/flags-context.ts b/src/shared/context/flags-context.ts index 7e6a6787..bd3f052b 100644 --- a/src/shared/context/flags-context.ts +++ b/src/shared/context/flags-context.ts @@ -11,17 +11,6 @@ export type Flags = { requireUserLocation: boolean; }; -const defaultContext: Flags = { - showResourceCategories: true, - showResourceLastAssuredDate: true, - showHomePageTour: true, - showResourceAttribution: true, - showSearchAndResourceServiceName: true, - showSuggestionListTaxonomyBadge: true, - showUseMyLocationButtonOnDesktop: true, - requireUserLocation: false, -}; - -const flagsContext = createContext(defaultContext); +const flagsContext = createContext(null); export { flagsContext }; diff --git a/src/shared/lib/parse-html.tsx b/src/shared/lib/parse-html.tsx index f906d8cc..0bf0bf83 100644 --- a/src/shared/lib/parse-html.tsx +++ b/src/shared/lib/parse-html.tsx @@ -2,8 +2,10 @@ import parse from 'html-react-parser'; export function parseHtml( html: string, - config?: { parseLineBreaks?: boolean } + config?: { parseLineBreaks?: boolean }, ) { + if (!(html && typeof html === 'string')) return false; + if (config?.parseLineBreaks) { html = html.replace(/\n/g, '
'); } diff --git a/src/shared/lib/server-utils.ts b/src/shared/lib/server-utils.ts index 17a16162..6c4287c2 100644 --- a/src/shared/lib/server-utils.ts +++ b/src/shared/lib/server-utils.ts @@ -4,6 +4,7 @@ import { GetServerSidePropsContext } from 'next'; import { Flags } from '../context/flags-context'; import { stringToBooleanOrUndefined } from './utils'; import _ from 'lodash'; +import { shake } from 'radash'; let config = undefined; export async function serverSideAppConfig() { @@ -71,14 +72,17 @@ export async function serverSideFlags() { try { await fs.stat(path.resolve('./.norse/flags.json')); rawData = await fs.readFile(path.resolve('./.norse/flags.json')); - flags = _.merge( - {}, - JSON.parse(rawData.toString()), - defaultFlags, - (objValue, srcValue) => { - return objValue !== undefined ? objValue : srcValue; - }, - ); + flags = _.omitBy( + _.merge( + {}, + JSON.parse(rawData.toString()), + defaultFlags, + (objValue, srcValue) => { + return objValue !== undefined ? objValue : srcValue; + }, + ), + (value) => value == null, + ) as Flags; } catch (_err) { // file doesn't exist OR issue parsing JSON. Save a default flags object flags = defaultFlags;