From ee328186c801e4b9f22311f06fc4f7284af64dba Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Wed, 9 Mar 2022 23:39:04 +0100 Subject: [PATCH] fix(client): add safety check on path.id split --- .gitignore | 3 +++ app/app/.gitignore | 3 ++- app/app/src/main/java/me/rxresu/app/MainActivity.kt | 2 ++ client/components/build/LeftSidebar/sections/Section.tsx | 4 ++-- client/components/shared/Heading.tsx | 2 +- client/store/resume/resumeSlice.ts | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1ff43cbc..bd682b05 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ # Project Dependencies node_modules + +# macOS +.DS_Store \ No newline at end of file diff --git a/app/app/.gitignore b/app/app/.gitignore index 42afabfd..956c004d 100644 --- a/app/app/.gitignore +++ b/app/app/.gitignore @@ -1 +1,2 @@ -/build \ No newline at end of file +/build +/release \ No newline at end of file diff --git a/app/app/src/main/java/me/rxresu/app/MainActivity.kt b/app/app/src/main/java/me/rxresu/app/MainActivity.kt index 9d8ad884..24b47e9c 100644 --- a/app/app/src/main/java/me/rxresu/app/MainActivity.kt +++ b/app/app/src/main/java/me/rxresu/app/MainActivity.kt @@ -30,6 +30,8 @@ class MainActivity : AppCompatActivity() { webView.settings.javaScriptEnabled = true webView.settings.userAgentString = "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Mobile Safari/537.36" + WebView.setWebContentsDebuggingEnabled(true) + swipeLayout.setOnRefreshListener { webView.reload() diff --git a/client/components/build/LeftSidebar/sections/Section.tsx b/client/components/build/LeftSidebar/sections/Section.tsx index 385c68f6..ec2ce615 100644 --- a/client/components/build/LeftSidebar/sections/Section.tsx +++ b/client/components/build/LeftSidebar/sections/Section.tsx @@ -41,14 +41,14 @@ const Section: React.FC = ({ const visibility = useAppSelector((state) => get(state.resume, `${path}.visible`, true)); const handleAdd = () => { - const id = path.split('.').at(-1) as string; + const id = path ? (path.split('.').at(-1) as string) : ''; const modal: ModalName = validate(id) ? 'builder.sections.custom' : `builder.${path}`; dispatch(setModalState({ modal, state: { open: true, payload: { path } } })); }; const handleEdit = (item: ListItem) => { - const id = path.split('.').at(-1) as string; + const id = path ? (path.split('.').at(-1) as string) : ''; const modal: ModalName = validate(id) ? 'builder.sections.custom' : `builder.${path}`; const payload = validate(id) ? { path, item } : { item }; diff --git a/client/components/shared/Heading.tsx b/client/components/shared/Heading.tsx index 88c4f1a7..7c9db164 100644 --- a/client/components/shared/Heading.tsx +++ b/client/components/shared/Heading.tsx @@ -37,7 +37,7 @@ const Heading: React.FC = ({ const [editMode, setEditMode] = useState(false); - const id = useMemo(() => path && path.split('.').at(-1), [path]); + const id = useMemo(() => (path ? path.split('.').at(-1) : ''), [path]); const icon = sections.find((x) => x.id === id)?.icon || ; diff --git a/client/store/resume/resumeSlice.ts b/client/store/resume/resumeSlice.ts index 1d044a83..a369a2db 100644 --- a/client/store/resume/resumeSlice.ts +++ b/client/store/resume/resumeSlice.ts @@ -82,7 +82,7 @@ export const resumeSlice = createSlice({ }, deleteSection: (state: Resume, action: PayloadAction) => { const { path } = action.payload; - const id = path && path.split('.').at(-1); + const id = path ? path.split('.').at(-1) : ''; const sections = Object.keys(state.sections).filter((x) => x !== id); const layout = state.metadata.layout.map((pages) => pages.map((list) => list.filter((x) => x !== id)));