Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c2c8470e

Přidáno uživatelem Fantič před více než 1 rok

re #10844 PlanView init reducer, page

Zobrazit rozdíly:

src/pages/Navigation.tsx
12 12
import Logout from "./Logout"
13 13
import ItemViewPage from "./ItemViewPage"
14 14
import NotesViewPage from "./NotesViewPage"
15
import PlanViewPage from "./PlanViewPage"
15 16

  
16 17
export type RootDrawerParamList = {
17 18
    Home: undefined,
18 19
    Search: { inventoryId: string | null },
19 20
    Logout: undefined,
20 21
    Item: { itemId: string },
22
    Plan: {  },
21 23
    Login: undefined,
22 24
    Notes: undefined,
23 25
}
......
78 80
                            component={ItemViewPage}
79 81
                            options={{ drawerItemStyle: { display: "none" } }}
80 82
                        />
83
                        <Drawer.Screen
84
                            name={"Plan"}
85
                            component={PlanViewPage}
86
                        />
81 87
                    </>
82 88
                ) : (
83 89
                    <Drawer.Screen
src/pages/PlanViewPage.tsx
1
import React, { useCallback, useEffect } from "react"
2
import { useDispatch, useSelector } from "react-redux"
3
import { AppDispatch, RootState } from "../stores/store"
4
import { getItem, getItemNotes, setConcordances } from "../stores/actions/itemThunks"
5
import { login } from "../stores/actions/userThunks"
6
import { TabView } from "react-native-tab-view"
7
import ItemView from "../components/item/ItemView"
8
import { useWindowDimensions } from "react-native"
9
import LoadingBox from "../components/loading/LoadingBox"
10
import ItemTabBar from "../components/item/ItemTabBar"
11
import { log } from "../logging/logger"
12
import { DrawerScreenProps } from "@react-navigation/drawer"
13
import { RootDrawerParamList } from "./Navigation"
14
import { Box, useToast } from "native-base"
15
import { ErrorToast } from "../components/toast/ErrorToast"
16
import Typography from "native-base/lib/typescript/theme/base/typography"
17

  
18

  
19
const PlanViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Plan'>) => {
20

  
21
  const layout = useWindowDimensions();
22

  
23
  const [routes, setRoutes] = React.useState<{ key: string, title: string }[]>([
24
    // initial tab
25
    { key: 'loading', title: 'Loading item...' },
26
  ]);
27

  
28
  // // TODO vyřešit, aby nebyly freezy při přepínání
29
  // const [renderSceneDict, setRenderSceneDict] = React.useState({});
30

  
31

  
32
  const dispatch = useDispatch<AppDispatch>();
33

  
34
  const { planLoading, lastError } = useSelector((state: RootState) => state.planViewState)
35

  
36
  const toast = useToast();
37

  
38
  useEffect(() => {
39
    if (lastError) {
40
      toast.closeAll()
41
      toast.show({
42
        render: ({
43
          id
44
        }) => {
45
          return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
46
        },
47
        duration: 3000
48
      });
49
    }
50
  }, [lastError])
51

  
52
  // // initial: load selected plan
53
  // useEffect(() => {
54
  //   dispatch(getItem(route.params.itemId));
55
  //   log.debug("PlanViewPage", "useEffect", "getPlan", route.params.itemId);
56
  // }, [route.params.itemId])
57

  
58

  
59
  const onBackPressed = () => {
60
    log.debug("back pressed")
61
    navigation.goBack();
62
  }
63

  
64
  return (
65
    <Box></Box>
66
  );
67
}
68

  
69
export default PlanViewPage;
src/stores/reducers/planSlice.ts
1
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
2
import { PlanViewState } from "../../types/plan";
3

  
4
const initialState: PlanViewState = {
5
    lastError: "",
6
    planLoading: true,
7
}
8

  
9
export const planSlice = createSlice({
10
    name: "plan",
11
    initialState: initialState,
12
    reducers: {},
13
    extraReducers: (builder) => {
14
    }
15
})
16

  
17
export default planSlice.reducer
src/stores/store.ts
5 5
import listViewReducer from "./reducers/listViewSlice"
6 6
import homePageReducer from "./reducers/homePageSlice"
7 7
import noteViewReducer from "./reducers/notesSlice"
8
import planViewReducer from "./reducers/planSlice"
8 9

  
9 10
const store = configureStore({
10 11
    reducer: {
11 12
        user: userReducer,
12 13
        itemViewState: itemReducer,
14
        planViewState: planViewReducer,
13 15
        noteViewState: noteViewReducer,
14 16
        searchForm: searchFormReducer,
15 17
        listView: listViewReducer,
src/types/plan.ts
1

  
2

  
3
export type PlanViewState = {
4
    planLoading: boolean
5
    lastError?: string
6
}

Také k dispozici: Unified diff