Your Name 3 years ago
parent
commit
e8aae03f2e
2 changed files with 12 additions and 8 deletions
  1. 2
    4
      src/layout/useScreen.js
  2. 10
    4
      src/reducers/system.js

+ 2
- 4
src/layout/useScreen.js View File

10
   const dispatch = useDispatch()
10
   const dispatch = useDispatch()
11
 
11
 
12
   const [firstScreen, setFirstScreen] = useState()
12
   const [firstScreen, setFirstScreen] = useState()
13
-  const canShow = useSelector(s => !s.system.firstScreen.filter(x => x === cityId)[0])
13
+  const cityShow = useSelector(s => s.system.firstScreen.filter(x => x.cityId === cityId)[0])
14
   const toggle = useCallback(
14
   const toggle = useCallback(
15
     () => dispatch({ type: 'TOGGLE_FIRSTSCREEN', payload: { cityId } }),
15
     () => dispatch({ type: 'TOGGLE_FIRSTSCREEN', payload: { cityId } }),
16
     [cityId, dispatch],
16
     [cityId, dispatch],
29
     }
29
     }
30
   }, [cityId, toggle, person?.personId])
30
   }, [cityId, toggle, person?.personId])
31
 
31
 
32
-  const show = canShow && firstScreen
33
-
34
-  return [firstScreen, show, toggle]
32
+  return [firstScreen, cityShow?.visible, toggle]
35
 }
33
 }

+ 10
- 4
src/reducers/system.js View File

45
     }
45
     }
46
     case 'TOGGLE_FIRSTSCREEN': {
46
     case 'TOGGLE_FIRSTSCREEN': {
47
       const { cityId } = action.payload
47
       const { cityId } = action.payload
48
-      const showed = state.firstScreen.filter(x => x === cityId)[0]
49
-
50
-      if (!showed) {
48
+      let cityState = state.firstScreen.filter(x => x.cityId === cityId)[0]
49
+console.log('---------cityState-------->', cityState)
50
+      if (!cityState) {
51
+        return {
52
+          ...state,
53
+          firstScreen: state.firstScreen.concat({ cityId, showed: true, visible: true })
54
+        };
55
+      } else if (cityState.showed && cityState.visible) {
56
+        const firstScreen = state.firstScreen.map(x => x.cityId === cityId ? { ...x, visible: false } : x)
51
         return {
57
         return {
52
           ...state,
58
           ...state,
53
-          firstScreen: state.firstScreen.concat(cityId)
59
+          firstScreen,
54
         };
60
         };
55
       }
61
       }
56
 
62