Skip to content

Commit

Permalink
fix: Fix flags and html parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
devcshort committed Oct 1, 2024
1 parent 3fa62a7 commit c81f4a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/features/favorites/components/favorite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ReferralButton } from '@/shared/components/referral-button';
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
Expand Down
13 changes: 1 addition & 12 deletions src/shared/context/flags-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Flags>(defaultContext);
const flagsContext = createContext<Flags>(null);

export { flagsContext };
4 changes: 3 additions & 1 deletion src/shared/lib/parse-html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<br />');
}
Expand Down
20 changes: 12 additions & 8 deletions src/shared/lib/server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c81f4a6

Please sign in to comment.