Always show home content even if an error occurred
This commit is contained in:
parent
dc57cbd7bd
commit
dca27e091c
2 changed files with 25 additions and 14 deletions
|
@ -22,6 +22,7 @@ type Props = {
|
||||||
onScroll: (event: SyntheticEvent<EventTarget>) => void,
|
onScroll: (event: SyntheticEvent<EventTarget>) => void,
|
||||||
collapsibleStack: Collapsible,
|
collapsibleStack: Collapsible,
|
||||||
|
|
||||||
|
showError: boolean,
|
||||||
itemHeight?: number,
|
itemHeight?: number,
|
||||||
updateData?: number,
|
updateData?: number,
|
||||||
renderSectionHeader?: (data: { [key: string]: any }) => React.Node,
|
renderSectionHeader?: (data: { [key: string]: any }) => React.Node,
|
||||||
|
@ -49,6 +50,7 @@ class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
stickyHeader: false,
|
stickyHeader: false,
|
||||||
updateData: 0,
|
updateData: 0,
|
||||||
|
showError: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollRef: { current: null | Animated.SectionList };
|
scrollRef: { current: null | Animated.SectionList };
|
||||||
|
@ -202,8 +204,12 @@ class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let dataset = [];
|
let dataset = [];
|
||||||
if (this.state.fetchedData != null)
|
if (this.state.fetchedData != null || (this.state.fetchedData == null && !this.props.showError)) {
|
||||||
dataset = this.props.createDataset(this.state.fetchedData);
|
if (this.state.fetchedData == null)
|
||||||
|
dataset = this.props.createDataset({});
|
||||||
|
else
|
||||||
|
dataset = this.props.createDataset(this.state.fetchedData);
|
||||||
|
}
|
||||||
const {containerPaddingTop, scrollIndicatorInsetTop, onScrollWithListener} = this.props.collapsibleStack;
|
const {containerPaddingTop, scrollIndicatorInsetTop, onScrollWithListener} = this.props.collapsibleStack;
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
|
|
|
@ -178,8 +178,12 @@ class HomeScreen extends React.Component<Props> {
|
||||||
let dashboardData = [];
|
let dashboardData = [];
|
||||||
if (fetchedData.news_feed != null)
|
if (fetchedData.news_feed != null)
|
||||||
newsData = fetchedData.news_feed.data;
|
newsData = fetchedData.news_feed.data;
|
||||||
|
else
|
||||||
|
newsData = [];
|
||||||
if (fetchedData.dashboard != null)
|
if (fetchedData.dashboard != null)
|
||||||
dashboardData = this.generateDashboardDataset(fetchedData.dashboard);
|
dashboardData = this.generateDashboardDataset(fetchedData.dashboard);
|
||||||
|
else
|
||||||
|
dashboardData = this.generateDashboardDataset(null);
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
title: '',
|
title: '',
|
||||||
|
@ -200,7 +204,7 @@ class HomeScreen extends React.Component<Props> {
|
||||||
* @param dashboardData
|
* @param dashboardData
|
||||||
* @return {Array<dashboardItem>}
|
* @return {Array<dashboardItem>}
|
||||||
*/
|
*/
|
||||||
generateDashboardDataset(dashboardData: fullDashboard): Array<dashboardItem> {
|
generateDashboardDataset(dashboardData: fullDashboard | null): Array<dashboardItem> {
|
||||||
return [
|
return [
|
||||||
{id: 'actions', content: []},
|
{id: 'actions', content: []},
|
||||||
{
|
{
|
||||||
|
@ -208,49 +212,49 @@ class HomeScreen extends React.Component<Props> {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
id: 'washers',
|
id: 'washers',
|
||||||
data: dashboardData.available_machines.washers,
|
data: dashboardData == null ? 0 : dashboardData.available_machines.washers,
|
||||||
icon: 'washing-machine',
|
icon: 'washing-machine',
|
||||||
color: this.colors.proxiwashColor,
|
color: this.colors.proxiwashColor,
|
||||||
onPress: this.onProxiwashClick,
|
onPress: this.onProxiwashClick,
|
||||||
isAvailable: dashboardData.available_machines.washers > 0
|
isAvailable: dashboardData == null ? false : dashboardData.available_machines.washers > 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'dryers',
|
id: 'dryers',
|
||||||
data: dashboardData.available_machines.dryers,
|
data: dashboardData == null ? 0 : dashboardData.available_machines.dryers,
|
||||||
icon: 'tumble-dryer',
|
icon: 'tumble-dryer',
|
||||||
color: this.colors.proxiwashColor,
|
color: this.colors.proxiwashColor,
|
||||||
onPress: this.onProxiwashClick,
|
onPress: this.onProxiwashClick,
|
||||||
isAvailable: dashboardData.available_machines.dryers > 0
|
isAvailable: dashboardData == null ? false : dashboardData.available_machines.dryers > 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'available_tutorials',
|
id: 'available_tutorials',
|
||||||
data: dashboardData.available_tutorials,
|
data: dashboardData == null ? 0 : dashboardData.available_tutorials,
|
||||||
icon: 'school',
|
icon: 'school',
|
||||||
color: this.colors.tutorinsaColor,
|
color: this.colors.tutorinsaColor,
|
||||||
onPress: this.onTutorInsaClick,
|
onPress: this.onTutorInsaClick,
|
||||||
isAvailable: dashboardData.available_tutorials > 0
|
isAvailable: dashboardData == null ? false : dashboardData.available_tutorials > 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'proximo_articles',
|
id: 'proximo_articles',
|
||||||
data: dashboardData.proximo_articles,
|
data: dashboardData == null ? 0 : dashboardData.proximo_articles,
|
||||||
icon: 'shopping',
|
icon: 'shopping',
|
||||||
color: this.colors.proximoColor,
|
color: this.colors.proximoColor,
|
||||||
onPress: this.onProximoClick,
|
onPress: this.onProximoClick,
|
||||||
isAvailable: dashboardData.proximo_articles > 0
|
isAvailable: dashboardData == null ? false : dashboardData.proximo_articles > 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'today_menu',
|
id: 'today_menu',
|
||||||
data: dashboardData.today_menu,
|
data: dashboardData == null ? 0 : dashboardData.today_menu,
|
||||||
icon: 'silverware-fork-knife',
|
icon: 'silverware-fork-knife',
|
||||||
color: this.colors.menuColor,
|
color: this.colors.menuColor,
|
||||||
onPress: this.onMenuClick,
|
onPress: this.onMenuClick,
|
||||||
isAvailable: dashboardData.today_menu.length > 0
|
isAvailable: dashboardData == null ? false : dashboardData.today_menu.length > 0
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'event',
|
id: 'event',
|
||||||
content: dashboardData.today_events
|
content: dashboardData == null ? [] : dashboardData.today_events
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -509,6 +513,7 @@ class HomeScreen extends React.Component<Props> {
|
||||||
renderItem={this.getRenderItem}
|
renderItem={this.getRenderItem}
|
||||||
itemHeight={FEED_ITEM_HEIGHT}
|
itemHeight={FEED_ITEM_HEIGHT}
|
||||||
onScroll={this.onScroll}
|
onScroll={this.onScroll}
|
||||||
|
showError={false}
|
||||||
/>
|
/>
|
||||||
<AnimatedFAB
|
<AnimatedFAB
|
||||||
{...this.props}
|
{...this.props}
|
||||||
|
|
Loading…
Reference in a new issue