Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7c4cd2cd

Přidáno uživatelem Fantič před téměř 2 roky(ů)

re #10454: ItemView: getting all required fields from api

Zobrazit rozdíly:

src/stores/reducers/itemSlice.ts
1 1
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
2 2
import { getItem, getItemNotes, getNextConcordance, getPreviousConcordance } from "../actions/itemThunks"
3
import { Note } from "./notesSlice"
3
import { Certainty, ItemState, Item } from "../../types/item";
4 4

  
5 5

  
6
export interface Item {
7
    authorName: string
8
    caption: string
9

  
10

  
11
    concordances: Concordance[]
12
}
13

  
14
export interface ItemState {
15
    item: Item
16
    concordances: Concordance[]
17
    selectedConcordance: number
18
    notes: Note[]
19
    lastError?: string
20
}
21

  
22
export interface Concordance {
23
    id: string
24
    certainty: Certainty
25
}
26

  
27
enum Certainty {
28
    SameAs = "same_as",
29
    High = "high",
30
    Medium = "medium",
31
    Low = "low",
32
}
33

  
34 6
export const CertaintyWithColors: Record<Certainty, { certainty: Certainty; color: string }> = {
35 7
    same_as: { certainty: Certainty.SameAs, color: "#000000" },
36 8
    high: { certainty: Certainty.High, color: "#FF0000" },
......
53 25
    },
54 26
    extraReducers: (builder) => {
55 27
        // getItem
56
        builder.addCase(getItem.fulfilled, (state, action) => {
28
        builder.addCase(getItem.fulfilled, (state, action) => { 
57 29

  
58 30
            // set concordances from item, if selected concordance is 0
59 31
            if (state.selectedConcordance === 0) {
60 32
                state.concordances = action.payload.concordances;
61 33
            }
62 34

  
63
            state.item = {
64
                authorName: action.payload.authorName,
65
                caption: action.payload.caption,
66
                concordances: action.payload.concordances
35
            if(action.payload.fullView){
36
                state.item = {
37
                    fullView: true,
38
                    
39
                    authorDisplayName: action.payload.authorDisplayName,
40
                    workName: action.payload.workName,
41
                    concordances: action.payload.concordances,
42
                    searchSubjects: action.payload.searchSubjects,
43
                    inventoryItem: action.payload.inventoryItem,
44

  
45
                    // additional
46
                    institution: action.payload.institution,
47
                    authorName: action.payload.authorName,
48
                    imageUrl: action.payload.imageUrl,
49
                    title: action.payload.title,
50
                    repository: action.payload.repository,
51
                    provenance: action.payload.provenance,
52
                    description: action.payload.description
53
                }
54
            }
55
            else{
56
                state.item = {
57
                    fullView: false,
58
                    authorDisplayName: action.payload.authorDisplayName,
59
                    workName: action.payload.workName,
60
                    concordances: action.payload.concordances,
61
                    searchSubjects: action.payload.searchSubjects,
62
                    inventoryItem: action.payload.inventoryItem
63
                }
67 64
            }
68

  
69 65
        })
70 66
        builder.addCase(getItem.rejected, (state, action) => {
71 67
            state.lastError = action.error.message

Také k dispozici: Unified diff