Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f2db3e05

Přidáno uživatelem Václav Honzík před více než 2 roky(ů)

re #9369 - catalog detail fetching

Zobrazit rozdíly:

frontend/src/features/Catalog/catalogSlice.ts
5 5
export interface CatalogState {
6 6
    catalogItems: CatalogItemDto[] // Items shown in the table
7 7
    isListLoading: boolean
8
    lastErr?: string
8
    catalogLastErr?: string // Error while fetching all catalog items
9 9
    catalogItem?: CatalogItemDto // Item shown in detail
10 10
    isItemLoading: boolean
11
    catalogItemLastErr?: string // Error while fetching catalog item
11 12
}
12 13

  
13 14
const initialState: CatalogState = {
......
18 19

  
19 20
export const catalogSlice = createSlice({
20 21
    name: 'catalog',
21

  
22 22
    initialState,
23

  
24 23
    reducers: {
25 24
        setItemListLoading: (state, action) => ({
26 25
            ...state,
27 26
            isListLoading: action.payload,
28 27
        }),
28
        consumeCatalogLastErr: (state) => ({
29
            ...state,
30
            catalogLastErr: undefined,
31
        }),
29 32
        setItemLoading: (state, action) => ({
30 33
            ...state,
31 34
            isItemLoading: action.payload,
32 35
        }),
36
        consumeCatalogItemLastErr: (state) => ({
37
            ...state,
38
            catalogItemLastErr: undefined,
39
        }),
33 40
    },
34 41

  
35 42
    extraReducers: (builder) => {
......
51 58
            ...state,
52 59
            lastErr: action.payload as string,
53 60
        }))
54
        builder.addCase(getCatalogItem.fulfilled, (state, action) => ({
55
            ...state, catalogItem: action.payload, isItemLoading: false,
56
        }))
57
        builder.addCase(getCatalogItem.rejected, (state, action) => ({
58
            ...state, lastErr: action.payload as string
59
        }))
60 61
    },
61 62
})
62 63

  
64
export const {
65
    setItemListLoading,
66
    setItemLoading,
67
    consumeCatalogItemLastErr,
68
    consumeCatalogLastErr,
69
} = catalogSlice.actions
70

  
63 71
export const catalogReducer = catalogSlice.reducer

Také k dispozici: Unified diff