Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a6999074

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

re #10871: PlanViewPage: ListView integration

Zobrazit rozdíly:

src/stores/reducers/planSlice.ts
5 5
const initialState: PlanViewState = {
6 6
    lastError: "",
7 7

  
8

  
9 8
    // TODO backend -> retrieve list of floors, not static -> not implemented at the time of coding
10 9
    floorList: [
11
        { label: "Ground floor", id: "ground_floor", roomList: [] },
12
        { label: "First floor", id: "first_floor", roomList: [] },
13
        { label: "Second floor", id: "second_floor", roomList: [] }
14 10
    ],
15 11
    floorListLoading: false,
16 12

  
17 13
    itemInventories: [],
14
    itemInventoriesLoading: false,
18 15

  
19
    itemList: [],
16
    // reseting itemList
17
    itemListLoading: {},
18
    itemList: {},
19
    itemListPagination: {},
20 20
}
21 21

  
22 22
export const planSlice = createSlice({
......
27 27

  
28 28
        // getFloorList
29 29
        builder.addCase(getFloorList.fulfilled, (state, action) => {
30

  
31 30
            state.floorList = action.payload
32 31
            state.floorListLoading = false;
33 32
        })
......
41 40

  
42 41
        // getPlanItems
43 42
        builder.addCase(getPlanItems.fulfilled, (state, action) => {
44
            state.itemList = action.payload.items
45
            state.itemListLoading = false;
43
            if (!state.itemList) {
44
                state.itemList = {}
45
            }
46

  
47
            if (action.meta.arg.inventory in state.itemList) {
48
                state.itemList[action.meta.arg.inventory] = state.itemList[action.meta.arg.inventory].concat(action.payload.items)
49
            }
50
            else {
51
                state.itemList[action.meta.arg.inventory] = action.payload.items
52
            }
53

  
54
            if (!state.itemListLoading) {
55
                state.itemListLoading = {}
56
            }
57
            state.itemListLoading[action.meta.arg.inventory] = false;
58

  
59
            if (!state.itemListPagination) {
60
                state.itemListPagination = {}
61
            }
62
            state.itemListPagination[action.meta.arg.inventory] = action.payload.inventoryPagination;
46 63
        })
64

  
47 65
        builder.addCase(getPlanItems.pending, (state, action) => {
48
            state.itemListLoading = true;
66

  
67
            if (!state.itemListLoading) {
68
                state.itemListLoading = {}
69
            }
70
            state.itemListLoading[action.meta.arg.inventory] = true;
49 71
        })
50 72
        builder.addCase(getPlanItems.rejected, (state, action) => {
51
            state.itemListLoading = false;
73

  
74
            if (!state.itemListLoading) {
75
                state.itemListLoading = {}
76
            }
77
            state.itemListLoading[action.meta.arg.inventory] = false;
52 78
            state.lastError = action.error.message
53 79
        })
54 80

  
55
        
56 81
        // getPlanInventories
57 82
        builder.addCase(getPlanInventories.fulfilled, (state, action) => {
58 83
            state.itemInventories = action.payload.inventories
59 84
            state.totalItemsCount = action.payload.allInventoriesRecords
60 85
            state.itemInventoriesLoading = false;
86

  
87
            // reseting itemList
88
            state.itemListLoading = {}
89
            state.itemList = {}
90
            state.itemListPagination = {}
61 91
        })
62 92
        builder.addCase(getPlanInventories.pending, (state, action) => {
63 93
            state.itemInventoriesLoading = true;

Také k dispozici: Unified diff