Browse Source

fix no group selected screen

Arnaud Vergnet 2 years ago
parent
commit
c2fdda5588

+ 3
- 2
src/components/Screens/ErrorView.tsx View File

@@ -19,7 +19,7 @@
19 19
 
20 20
 import * as React from 'react';
21 21
 import { Button, Subheading, useTheme } from 'react-native-paper';
22
-import { StyleSheet, View } from 'react-native';
22
+import { StyleSheet, View, ViewStyle } from 'react-native';
23 23
 import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
24 24
 import i18n from 'i18n-js';
25 25
 import * as Animatable from 'react-native-animatable';
@@ -36,6 +36,7 @@ type Props = {
36 36
     icon: string;
37 37
     onPress: () => void;
38 38
   };
39
+  style?: ViewStyle;
39 40
 };
40 41
 
41 42
 const styles = StyleSheet.create({
@@ -147,7 +148,7 @@ function ErrorView(props: Props) {
147 148
   const { button } = props;
148 149
 
149 150
   return (
150
-    <View style={styles.outer}>
151
+    <View style={{ ...styles.outer, ...props.style }}>
151 152
       <Animatable.View
152 153
         style={{
153 154
           ...styles.outer,

+ 17
- 7
src/components/Screens/PlanexWebview.tsx View File

@@ -1,5 +1,5 @@
1 1
 import React from 'react';
2
-import { View } from 'react-native';
2
+import { StyleSheet, View } from 'react-native';
3 3
 import GENERAL_STYLES from '../../constants/Styles';
4 4
 import Urls from '../../constants/Urls';
5 5
 import DateManager from '../../managers/DateManager';
@@ -15,6 +15,14 @@ type Props = {
15 15
   onMessage: (event: { nativeEvent: { data: string } }) => void;
16 16
 };
17 17
 
18
+const styles = StyleSheet.create({
19
+  error: {
20
+    position: 'absolute',
21
+    height: '100%',
22
+    width: '100%',
23
+  },
24
+});
25
+
18 26
 // Watch for changes in the calendar and call the remove alpha function to prevent invisible events
19 27
 const OBSERVE_MUTATIONS_INJECTED =
20 28
   'function removeAlpha(node) {\n' +
@@ -99,19 +107,21 @@ const generateInjectedJS = (group: PlanexGroupType | undefined) => {
99 107
 function PlanexWebview(props: Props) {
100 108
   return (
101 109
     <View style={GENERAL_STYLES.flex}>
102
-      {!props.currentGroup ? (
103
-        <ErrorView
104
-          icon={'account-clock'}
105
-          message={i18n.t('screens.planex.noGroupSelected')}
106
-        />
107
-      ) : null}
108 110
       <WebViewScreen
109 111
         url={Urls.planex.planning}
110 112
         initialJS={generateInjectedJS(props.currentGroup)}
111 113
         injectJS={props.injectJS}
112 114
         onMessage={props.onMessage}
113 115
         showAdvancedControls={false}
116
+        showControls={props.currentGroup !== undefined}
114 117
       />
118
+      {!props.currentGroup ? (
119
+        <ErrorView
120
+          icon={'account-clock'}
121
+          message={i18n.t('screens.planex.noGroupSelected')}
122
+          style={styles.error}
123
+        />
124
+      ) : null}
115 125
     </View>
116 126
   );
117 127
 }

+ 14
- 6
src/components/Screens/WebViewScreen.tsx View File

@@ -57,6 +57,7 @@ type Props = {
57 57
   injectJS?: string;
58 58
   customPaddingFunction?: null | ((padding: number) => string);
59 59
   showAdvancedControls?: boolean;
60
+  showControls?: boolean;
60 61
 };
61 62
 
62 63
 const AnimatedWebView = Animated.createAnimatedComponent(WebView);
@@ -110,13 +111,20 @@ function WebViewScreen(props: Props) {
110 111
   );
111 112
 
112 113
   useLayoutEffect(() => {
113
-    navigation.setOptions({
114
-      headerRight: props.showAdvancedControls
115
-        ? getAdvancedButtons
116
-        : getBasicButton,
117
-    });
114
+    if (props.showControls !== false) {
115
+      navigation.setOptions({
116
+        headerRight: props.showAdvancedControls
117
+          ? getAdvancedButtons
118
+          : getBasicButton,
119
+      });
120
+    }
118 121
     // eslint-disable-next-line react-hooks/exhaustive-deps
119
-  }, [navigation, props.showAdvancedControls, navState?.url]);
122
+  }, [
123
+    navigation,
124
+    props.showAdvancedControls,
125
+    navState?.url,
126
+    props.showControls,
127
+  ]);
120 128
 
121 129
   useEffect(() => {
122 130
     if (props.injectJS && props.injectJS !== currentInjectedJS) {

Loading…
Cancel
Save