Skip to content

Commit 6d68369

Browse files
committed
update package.json
1 parent b27bfab commit 6d68369

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

Mobile-Expensify

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
4747
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
4848
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
49-
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=311 --cache --cache-location=node_modules/.cache/eslint",
49+
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=310 --cache --cache-location=node_modules/.cache/eslint",
5050
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
5151
"lint-watch": "npx eslint-watch --watch --changed",
5252
"shellcheck": "./scripts/shellCheck.sh",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// eslint-disable-next-line no-restricted-imports
2+
import React, {createContext, useMemo} from 'react';
3+
import useOnyx from '@hooks/useOnyx';
4+
import ExpensiMark from '@libs/Parser';
5+
import ONYXKEYS from '@src/ONYXKEYS';
6+
7+
type Extras = {
8+
reportIDToName?: Record<string, string>;
9+
accountIDToName?: Record<string, string>;
10+
cacheVideoAttributes?: (vidSource: string, attrs: string) => void;
11+
videoAttributeCache?: Record<string, string>;
12+
};
13+
type ParserContextProps = {
14+
htmlToMarkdown: (htmlString: string, extras?: Extras) => string;
15+
htmlToText: (htmlString: string, extras?: Extras) => string;
16+
};
17+
type ParserContextProviderProps = {children: React.ReactNode};
18+
const ParserContext = createContext<ParserContextProps>({
19+
htmlToMarkdown: () => '',
20+
htmlToText: () => '',
21+
});
22+
23+
function ParserContextProvider({children}: ParserContextProviderProps) {
24+
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
25+
const [personalDetailsList] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
26+
27+
const reportIDToNameMap = useMemo(() => {
28+
const map: Record<string, string> = {};
29+
Object.values(reports ?? {}).forEach((report) => {
30+
if (!report) {
31+
return;
32+
}
33+
map[report.reportID] = report.reportName ?? report.reportID;
34+
});
35+
return map;
36+
}, [reports]);
37+
38+
const accountIDToNameMap = useMemo(() => {
39+
const map: Record<string, string> = {};
40+
Object.values(personalDetailsList ?? {}).forEach((personalDetails) => {
41+
if (!personalDetails) {
42+
return;
43+
}
44+
map[personalDetails.accountID] = personalDetails.login ?? personalDetails.displayName ?? '';
45+
});
46+
return map;
47+
}, [personalDetailsList]);
48+
49+
const Parser = React.useMemo<ParserContextProps>(() => {
50+
const parser = ExpensiMark as unknown as Record<string, unknown>;
51+
52+
return {
53+
...parser,
54+
htmlToMarkdown: (htmlString: string, extras?: Extras) =>
55+
(parser.htmlToMarkdown as (htmlString: string, extras?: Extras) => string)(htmlString, {
56+
reportIDToName: extras?.reportIDToName ?? reportIDToNameMap,
57+
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
58+
cacheVideoAttributes: extras?.cacheVideoAttributes,
59+
}),
60+
htmlToText: (htmlString: string, extras?: Extras) =>
61+
(parser.htmlToText as (htmlString: string, extras?: Extras) => string)(htmlString, {
62+
reportIDToName: extras?.reportIDToName ?? reportIDToNameMap,
63+
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
64+
cacheVideoAttributes: extras?.cacheVideoAttributes,
65+
}),
66+
};
67+
}, [reportIDToNameMap, accountIDToNameMap]);
68+
69+
const contextValue = useMemo<ParserContextProps>(() => Parser, [Parser]);
70+
71+
return <ParserContext.Provider value={contextValue}>{children}</ParserContext.Provider>;
72+
}
73+
74+
ParserContextProvider.displayName = 'ParserContextProvider';
75+
76+
export {ParserContext, ParserContextProvider};

0 commit comments

Comments
 (0)