From e6c2f4dae7352a1ced9119504ea18c02cae4d520 Mon Sep 17 00:00:00 2001 From: Julian Kwast Date: Thu, 25 Nov 2021 10:17:32 +0100 Subject: [PATCH 1/7] feat(nested info): added nested info screen - this screen handles a new json format that allows for an easy tree structure - each screen may include html content at the top - each screen includes a list of textlistitems at the bottom - added skip option to useStaticContent SVA-314 --- src/config/navigation/defaultStackConfig.tsx | 5 + src/hooks/staticContent.ts | 10 +- src/screens/NestedInfoScreen.tsx | 118 +++++++++++++++++++ src/screens/index.js | 1 + src/types/Navigation.ts | 1 + 5 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 src/screens/NestedInfoScreen.tsx diff --git a/src/config/navigation/defaultStackConfig.tsx b/src/config/navigation/defaultStackConfig.tsx index 5b504f0f7..071d51bab 100644 --- a/src/config/navigation/defaultStackConfig.tsx +++ b/src/config/navigation/defaultStackConfig.tsx @@ -21,6 +21,7 @@ import { HtmlScreen, IndexScreen, LunchScreen, + NestedInfoScreen, OParlCalendarScreen, OParlDetailScreen, OParlOrganizationsScreen, @@ -174,6 +175,10 @@ export const defaultStackConfig = ({ routeName: ScreenName.Lunch, screenComponent: LunchScreen }, + { + routeName: ScreenName.NestedInfo, + screenComponent: NestedInfoScreen + }, { routeName: ScreenName.OParlCalendar, screenComponent: OParlCalendarScreen diff --git a/src/hooks/staticContent.ts b/src/hooks/staticContent.ts index 8028239f9..79122a688 100644 --- a/src/hooks/staticContent.ts +++ b/src/hooks/staticContent.ts @@ -12,6 +12,7 @@ type StaticContentArgs = { refreshTimeKey?: string; refreshInterval?: string; fetchPolicy?: 'cache-first' | 'cache-only' | 'network-only'; + skip?: boolean; } & ( | { type: 'json'; @@ -24,12 +25,13 @@ type StaticContentArgs = { ); export const useStaticContent = ({ + fetchPolicy: overrideFetchPolicy, name, - type, parseFromJson, refreshInterval, refreshTimeKey, - fetchPolicy: overrideFetchPolicy + skip, + type }: StaticContentArgs): { data?: T; error: boolean; @@ -54,7 +56,7 @@ export const useStaticContent = ({ { variables: { name }, fetchPolicy, - skip: !refreshTime + skip: !refreshTime || skip } ); @@ -85,7 +87,7 @@ export const useStaticContent = ({ error: error || !!queryError, // add the extra condition to avoid weird rendering states, where loading is false, but the publicFileData is not yet set. // this way we can safely manipulate data and then update the publicFileData with it, after the query has finished loading. - loading: loading || (publicFileData === undefined && !error), + loading: loading || (publicFileData === undefined && !error && !skip), refetch: refetchCallback }; }; diff --git a/src/screens/NestedInfoScreen.tsx b/src/screens/NestedInfoScreen.tsx new file mode 100644 index 000000000..3d001975d --- /dev/null +++ b/src/screens/NestedInfoScreen.tsx @@ -0,0 +1,118 @@ +import { StackScreenProps } from '@react-navigation/stack'; +import React, { useCallback, useContext, useState } from 'react'; +import { ActivityIndicator, RefreshControl, SectionList } from 'react-native'; + +import { + HtmlView, + LoadingContainer, + LoadingSpinner, + SafeAreaViewFlex, + SectionHeader, + Wrapper, + WrapperWithOrientation +} from '../components'; +import { colors } from '../config'; +import { useStaticContent } from '../hooks'; +import { useRenderItem } from '../hooks/listHooks'; +import { NetworkContext } from '../NetworkProvider'; +import { QUERY_TYPES } from '../queries'; + +type NestedInfo = { + content?: string; + title: string; + children: Array<{ + title: string; + routeName: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + params?: any; + }>; +}; + +const ListHeaderComponent = ({ loading, html }: { loading: boolean; html?: string }) => { + if (loading) { + return ; + } + + if (!html?.length) { + return null; + } + + return ( + + {/* @ts-expect-error HtmlView uses memo in js, which is not inferred correctly */} + + + ); +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const NestedInfoScreen = ({ navigation, route }: StackScreenProps) => { + const { isConnected } = useContext(NetworkContext); + const [refreshing, setRefreshing] = useState(false); + const name = route.params?.name; + const rootRouteName = route.params?.rootRouteName; + const navigationTitle = route.params?.title; + const { data, loading, refetch } = useStaticContent({ name, type: 'json' }); + const { data: dataHtml, loading: loadingHtml, refetch: refetchHtml } = useStaticContent({ + name: data?.content ?? '', + type: 'html', + skip: !data?.content + }); + + const onRefresh = useCallback(async () => { + setRefreshing(true); + if (isConnected) { + await refetch?.(); + await refetchHtml?.(); + } + setRefreshing(false); + }, [isConnected, refetch]); + + const renderItem = useRenderItem(QUERY_TYPES.PUBLIC_JSON_FILE, navigation); + + if (loading && !data) + return ( + + + + ); + + // aggregate current rootRouteName and title for navigation, if they are not present in params of children + const sectionData = [ + { + title: data.title, + data: data.children?.map((child) => { + return { + ...child, + params: { + ...child.params, + rootRouteName: child.params?.rootRouteName ?? rootRouteName, + title: child.params?.title ?? navigationTitle + } + }; + }) + } + ]; + + return ( + + + + } + ListHeaderComponent={} + sections={sectionData} + renderSectionHeader={({ section: { title } }) => } + renderItem={renderItem} + keyExtractor={(item) => item.title} + /> + + + ); +}; diff --git a/src/screens/index.js b/src/screens/index.js index 834e27ed7..949135ae1 100644 --- a/src/screens/index.js +++ b/src/screens/index.js @@ -16,6 +16,7 @@ export * from './HomeScreen'; export * from './HtmlScreen'; export * from './IndexScreen'; export * from './LunchScreen'; +export * from './NestedInfoScreen'; export * from './OParl'; export * from './SettingsScreen'; export * from './SurveyDetailScreen'; diff --git a/src/types/Navigation.ts b/src/types/Navigation.ts index dd165258a..a04754bef 100644 --- a/src/types/Navigation.ts +++ b/src/types/Navigation.ts @@ -24,6 +24,7 @@ export enum ScreenName { Html = 'Html', Index = 'Index', Lunch = 'Lunch', + NestedInfo = 'NestedInfo', OParlCalendar = 'OParlCalendar', OParlDetail = 'OParlDetail', OParlOrganizations = 'OParlOrganizations', From 772ae2e8891381a4979de806e570ab9842e1f749 Mon Sep 17 00:00:00 2001 From: Daniel Molnar Date: Tue, 30 Nov 2021 19:00:23 +0100 Subject: [PATCH 2/7] refactor(nested info): move `WrapperWithOrientation` in list header - avoided wrapped/centered scroll area on the screen in landscape mode SVA-314 --- src/screens/NestedInfoScreen.tsx | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/screens/NestedInfoScreen.tsx b/src/screens/NestedInfoScreen.tsx index 3d001975d..19a536ef8 100644 --- a/src/screens/NestedInfoScreen.tsx +++ b/src/screens/NestedInfoScreen.tsx @@ -38,10 +38,12 @@ const ListHeaderComponent = ({ loading, html }: { loading: boolean; html?: strin } return ( - - {/* @ts-expect-error HtmlView uses memo in js, which is not inferred correctly */} - - + + + {/* @ts-expect-error HtmlView uses memo in js, which is not inferred correctly */} + + + ); }; @@ -96,23 +98,21 @@ export const NestedInfoScreen = ({ navigation, route }: StackScreenProps) = return ( - - - } - ListHeaderComponent={} - sections={sectionData} - renderSectionHeader={({ section: { title } }) => } - renderItem={renderItem} - keyExtractor={(item) => item.title} - /> - + + } + ListHeaderComponent={} + sections={sectionData} + renderSectionHeader={({ section: { title } }) => } + renderItem={renderItem} + keyExtractor={(item) => item.title} + /> ); }; From f62936e70ada8b7881c46be0ac27fef0f4948c93 Mon Sep 17 00:00:00 2001 From: Daniel Molnar Date: Tue, 30 Nov 2021 13:42:04 +0100 Subject: [PATCH 3/7] refactor: hooks imports - made adjustment in `Image` to avoid require cycle SVA-306 --- src/components/ConnectedImagesCarousel.js | 3 +-- src/components/EventList.js | 2 +- src/components/HomeSection.tsx | 2 +- src/components/HorizontalList.js | 2 +- src/components/Image.js | 2 +- src/components/VerticalList.js | 2 +- src/components/screens/About.js | 4 +--- src/components/screens/Service.js | 3 +-- src/components/widgets/ConstructionSiteNewsWidget.tsx | 3 +-- src/components/widgets/ConstructionSiteWidget.tsx | 3 +-- src/components/widgets/EventWidget.tsx | 3 +-- src/components/widgets/LunchWidget.tsx | 3 +-- src/components/widgets/SurveyWidget.tsx | 3 +-- src/components/widgets/WeatherWidget.tsx | 2 +- src/hooks/index.js | 2 ++ src/screens/BookmarkCategoryScreen.js | 3 +-- 16 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/components/ConnectedImagesCarousel.js b/src/components/ConnectedImagesCarousel.js index e7176ebec..6d56dd277 100644 --- a/src/components/ConnectedImagesCarousel.js +++ b/src/components/ConnectedImagesCarousel.js @@ -6,8 +6,7 @@ import { ActivityIndicator } from 'react-native'; import { colors } from '../config'; import { graphqlFetchPolicy, parsedImageAspectRatio } from '../helpers'; -import { useRefreshTime } from '../hooks'; -import { useHomeRefresh } from '../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../hooks'; import { NetworkContext } from '../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../queries'; import { SettingsContext } from '../SettingsProvider'; diff --git a/src/components/EventList.js b/src/components/EventList.js index 123b652c5..595bfe118 100644 --- a/src/components/EventList.js +++ b/src/components/EventList.js @@ -3,7 +3,7 @@ import React, { useState } from 'react'; import { SectionList } from 'react-native'; import { momentFormat } from '../helpers'; -import { useRenderItem } from '../hooks/listHooks'; +import { useRenderItem } from '../hooks'; import { QUERY_TYPES } from '../queries'; import { LoadingSpinner } from './LoadingSpinner'; diff --git a/src/components/HomeSection.tsx b/src/components/HomeSection.tsx index 4bdfdba7e..a770902f0 100644 --- a/src/components/HomeSection.tsx +++ b/src/components/HomeSection.tsx @@ -2,7 +2,7 @@ import { StackNavigationProp } from '@react-navigation/stack'; import React from 'react'; import { useQuery } from 'react-apollo'; -import { useHomeRefresh } from '../hooks/HomeRefresh'; +import { useHomeRefresh } from '../hooks'; import { getQuery } from '../queries'; import { DataListSection } from './DataListSection'; diff --git a/src/components/HorizontalList.js b/src/components/HorizontalList.js index 87d541644..4fc356d14 100644 --- a/src/components/HorizontalList.js +++ b/src/components/HorizontalList.js @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'; import React from 'react'; import { FlatList } from 'react-native'; -import { useRenderItem } from '../hooks/listHooks'; +import { useRenderItem } from '../hooks'; const keyExtractor = (item, index) => `index${index}-id${item.id}`; diff --git a/src/components/Image.js b/src/components/Image.js index adbbdab02..29485483c 100644 --- a/src/components/Image.js +++ b/src/components/Image.js @@ -7,7 +7,7 @@ import { Image as RNEImage } from 'react-native-elements'; import { consts, colors } from '../config'; import { imageHeight, imageWidth } from '../helpers'; import { SettingsContext } from '../SettingsProvider'; -import { useInterval } from '../hooks'; +import { useInterval } from '../hooks/TimeHooks'; import { ImageMessage } from './ImageMessage'; import { ImageRights } from './ImageRights'; diff --git a/src/components/VerticalList.js b/src/components/VerticalList.js index 75b2f0d52..ec3745db1 100644 --- a/src/components/VerticalList.js +++ b/src/components/VerticalList.js @@ -3,7 +3,7 @@ import React, { useRef, useState } from 'react'; import { ActivityIndicator, FlatList } from 'react-native'; import { colors, normalize } from '../config'; -import { useRenderItem } from '../hooks/listHooks'; +import { useRenderItem } from '../hooks'; import { BackToTop } from './BackToTop'; diff --git a/src/components/screens/About.js b/src/components/screens/About.js index 473f720e9..ce3e0beb9 100644 --- a/src/components/screens/About.js +++ b/src/components/screens/About.js @@ -5,15 +5,13 @@ import { ActivityIndicator, RefreshControl, SectionList } from 'react-native'; import { colors, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime, useRenderItem } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; import { SettingsContext } from '../../SettingsProvider'; import { LoadingContainer } from '../LoadingContainer'; import { SectionHeader } from '../SectionHeader'; import { VersionNumber } from '../VersionNumber'; -import { useRenderItem } from '../../hooks/listHooks'; export const About = ({ navigation, withHomeRefresh, withSettings }) => { const { isConnected, isMainserverUp } = useContext(NetworkContext); diff --git a/src/components/screens/Service.js b/src/components/screens/Service.js index e9ca08059..7fe873d43 100644 --- a/src/components/screens/Service.js +++ b/src/components/screens/Service.js @@ -5,8 +5,7 @@ import { StyleSheet, TouchableOpacity, View } from 'react-native'; import { colors, consts, device, Icon, normalize, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { OrientationContext } from '../../OrientationProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; diff --git a/src/components/widgets/ConstructionSiteNewsWidget.tsx b/src/components/widgets/ConstructionSiteNewsWidget.tsx index 0f6b5d065..136ccaaba 100644 --- a/src/components/widgets/ConstructionSiteNewsWidget.tsx +++ b/src/components/widgets/ConstructionSiteNewsWidget.tsx @@ -4,8 +4,7 @@ import { useQuery } from 'react-apollo'; import { consts, Icon, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; import { WidgetProps } from '../../types'; diff --git a/src/components/widgets/ConstructionSiteWidget.tsx b/src/components/widgets/ConstructionSiteWidget.tsx index 036fa8a91..f2eb3a934 100644 --- a/src/components/widgets/ConstructionSiteWidget.tsx +++ b/src/components/widgets/ConstructionSiteWidget.tsx @@ -2,8 +2,7 @@ import { useNavigation } from '@react-navigation/core'; import React, { useCallback } from 'react'; import { Icon, texts } from '../../config'; -import { useConstructionSites } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useConstructionSites, useHomeRefresh } from '../../hooks'; import { WidgetProps } from '../../types'; import { DefaultWidget } from './DefaultWidget'; diff --git a/src/components/widgets/EventWidget.tsx b/src/components/widgets/EventWidget.tsx index 7c0ed2a8e..8c4ff3eab 100644 --- a/src/components/widgets/EventWidget.tsx +++ b/src/components/widgets/EventWidget.tsx @@ -5,8 +5,7 @@ import { useQuery } from 'react-apollo'; import { consts, Icon, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; import { WidgetProps } from '../../types'; diff --git a/src/components/widgets/LunchWidget.tsx b/src/components/widgets/LunchWidget.tsx index 2e656c8ee..1afde5554 100644 --- a/src/components/widgets/LunchWidget.tsx +++ b/src/components/widgets/LunchWidget.tsx @@ -5,8 +5,7 @@ import { useQuery } from 'react-apollo'; import { consts, Icon, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; import { WidgetProps } from '../../types'; diff --git a/src/components/widgets/SurveyWidget.tsx b/src/components/widgets/SurveyWidget.tsx index 3441c6bf0..0bdc51d38 100644 --- a/src/components/widgets/SurveyWidget.tsx +++ b/src/components/widgets/SurveyWidget.tsx @@ -4,8 +4,7 @@ import { useQuery } from 'react-apollo'; import { consts, Icon, normalize, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useRefreshTime } from '../../hooks'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh, useRefreshTime } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { SURVEYS } from '../../queries/survey'; import { Survey, WidgetProps } from '../../types'; diff --git a/src/components/widgets/WeatherWidget.tsx b/src/components/widgets/WeatherWidget.tsx index f05944323..dcfea7ec4 100644 --- a/src/components/widgets/WeatherWidget.tsx +++ b/src/components/widgets/WeatherWidget.tsx @@ -6,7 +6,7 @@ import { TouchableOpacity } from 'react-native-gesture-handler'; import { consts, normalize, texts } from '../../config'; import { graphqlFetchPolicy } from '../../helpers'; -import { useHomeRefresh } from '../../hooks/HomeRefresh'; +import { useHomeRefresh } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; import { getQuery, QUERY_TYPES } from '../../queries'; import { WidgetProps } from '../../types'; diff --git a/src/hooks/index.js b/src/hooks/index.js index c870d69c4..f51cf19e3 100644 --- a/src/hooks/index.js +++ b/src/hooks/index.js @@ -2,7 +2,9 @@ export * from './apollo'; export * from './Bookmarks'; export * from './constructionSites'; export * from './encounter'; +export * from './HomeRefresh'; export * from './imagePicker'; +export * from './listHooks'; export * from './locationHooks'; export * from './matomoHooks'; export * from './NewsCategories'; diff --git a/src/screens/BookmarkCategoryScreen.js b/src/screens/BookmarkCategoryScreen.js index 0693867d9..79777fcb1 100644 --- a/src/screens/BookmarkCategoryScreen.js +++ b/src/screens/BookmarkCategoryScreen.js @@ -13,8 +13,7 @@ import { } from '../components'; import { colors, consts, texts } from '../config'; import { graphqlFetchPolicy, parseListItemsFromQuery } from '../helpers'; -import { useMatomoTrackScreenView, useRefreshTime } from '../hooks'; -import { useBookmarks } from '../hooks/Bookmarks'; +import { useBookmarks, useMatomoTrackScreenView, useRefreshTime } from '../hooks'; import { NetworkContext } from '../NetworkProvider'; import { getQuery } from '../queries'; From a30961e463b51cc5d7c5e9af5b7a8e727a45c8d5 Mon Sep 17 00:00:00 2001 From: Julian Kwast Date: Wed, 1 Dec 2021 18:25:37 +0100 Subject: [PATCH 4/7] refactor(about): use useStaticContent SVA-314 --- src/components/screens/About.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/components/screens/About.js b/src/components/screens/About.js index ce3e0beb9..8979868cf 100644 --- a/src/components/screens/About.js +++ b/src/components/screens/About.js @@ -1,37 +1,25 @@ import PropTypes from 'prop-types'; import React, { useContext, useState } from 'react'; -import { useQuery } from 'react-apollo'; import { ActivityIndicator, RefreshControl, SectionList } from 'react-native'; import { colors, texts } from '../../config'; -import { graphqlFetchPolicy } from '../../helpers'; -import { useHomeRefresh, useRefreshTime, useRenderItem } from '../../hooks'; +import { useHomeRefresh, useRenderItem, useStaticContent } from '../../hooks'; import { NetworkContext } from '../../NetworkProvider'; -import { getQuery, QUERY_TYPES } from '../../queries'; +import { QUERY_TYPES } from '../../queries'; import { SettingsContext } from '../../SettingsProvider'; import { LoadingContainer } from '../LoadingContainer'; import { SectionHeader } from '../SectionHeader'; import { VersionNumber } from '../VersionNumber'; export const About = ({ navigation, withHomeRefresh, withSettings }) => { - const { isConnected, isMainserverUp } = useContext(NetworkContext); + const { data: aboutData, loading, refetch } = useStaticContent({ + name: 'homeAbout', + type: 'json' + }); + const { isConnected } = useContext(NetworkContext); const { globalSettings } = useContext(SettingsContext); const [refreshing, setRefreshing] = useState(false); - const refreshTime = useRefreshTime('publicJsonFile-homeAbout'); - - const fetchPolicy = graphqlFetchPolicy({ - isConnected, - isMainserverUp, - refreshTime - }); - - const { data: aboutData, loading, refetch } = useQuery(getQuery(QUERY_TYPES.PUBLIC_JSON_FILE), { - variables: { name: 'homeAbout' }, - fetchPolicy, - skip: !refreshTime - }); - useHomeRefresh(withHomeRefresh ? refetch : undefined); const refresh = async (refetch) => { @@ -46,7 +34,7 @@ export const About = ({ navigation, withHomeRefresh, withSettings }) => { const renderItem = useRenderItem(QUERY_TYPES.PUBLIC_JSON_FILE, navigation); - if (!refreshTime || loading) + if (loading) return withHomeRefresh ? null : ( From bed95157c4924b3e960afb51df86c47270c5fe58 Mon Sep 17 00:00:00 2001 From: Julian Kwast Date: Thu, 2 Dec 2021 10:28:47 +0100 Subject: [PATCH 5/7] chore(about): add refreshTimeKey - add the refresh time key that was previously used SVA-314 --- src/components/screens/About.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/screens/About.js b/src/components/screens/About.js index 8979868cf..d435c2261 100644 --- a/src/components/screens/About.js +++ b/src/components/screens/About.js @@ -14,7 +14,8 @@ import { VersionNumber } from '../VersionNumber'; export const About = ({ navigation, withHomeRefresh, withSettings }) => { const { data: aboutData, loading, refetch } = useStaticContent({ name: 'homeAbout', - type: 'json' + type: 'json', + refreshTimeKey: 'publicJsonFile-homeAbout' }); const { isConnected } = useContext(NetworkContext); const { globalSettings } = useContext(SettingsContext); From 664f9c1bca08c6f9ce484bb9b2ef14d46060f7d6 Mon Sep 17 00:00:00 2001 From: Julian Kwast Date: Thu, 2 Dec 2021 10:49:40 +0100 Subject: [PATCH 6/7] fix(about): double parsing of json SVA-314 --- src/components/screens/About.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/components/screens/About.js b/src/components/screens/About.js index d435c2261..160c6ac71 100644 --- a/src/components/screens/About.js +++ b/src/components/screens/About.js @@ -12,7 +12,7 @@ import { SectionHeader } from '../SectionHeader'; import { VersionNumber } from '../VersionNumber'; export const About = ({ navigation, withHomeRefresh, withSettings }) => { - const { data: aboutData, loading, refetch } = useStaticContent({ + const { data, loading, refetch } = useStaticContent({ name: 'homeAbout', type: 'json', refreshTimeKey: 'publicJsonFile-homeAbout' @@ -42,15 +42,7 @@ export const About = ({ navigation, withHomeRefresh, withSettings }) => { ); - let publicJsonFileContent = []; - - try { - publicJsonFileContent = JSON.parse(aboutData?.publicJsonFile?.content); - } catch (error) { - console.warn(error, aboutData); - } - - if (!publicJsonFileContent?.length) return null; + if (!data?.length) return null; const { sections = {} } = globalSettings; const { headlineAbout = texts.homeTitles.about } = sections; @@ -58,7 +50,7 @@ export const About = ({ navigation, withHomeRefresh, withSettings }) => { const sectionData = [ { title: headlineAbout, - data: publicJsonFileContent + data } ]; From 0bfca060a2c060c0c854befaeb2192292c416a92 Mon Sep 17 00:00:00 2001 From: Julian Kwast Date: Thu, 2 Dec 2021 15:00:35 +0100 Subject: [PATCH 7/7] fix(optional data): data is optional for error cases - this was not handled correctly, and would cause a crash SVA-314 --- src/screens/NestedInfoScreen.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/screens/NestedInfoScreen.tsx b/src/screens/NestedInfoScreen.tsx index 19a536ef8..94bc60fd7 100644 --- a/src/screens/NestedInfoScreen.tsx +++ b/src/screens/NestedInfoScreen.tsx @@ -79,6 +79,10 @@ export const NestedInfoScreen = ({ navigation, route }: StackScreenProps) = ); + if (!data) { + return null; + } + // aggregate current rootRouteName and title for navigation, if they are not present in params of children const sectionData = [ {