Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c03fd43c

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

re #10454: ItemView concordances switching

Zobrazit rozdíly:

src/stores/actions/itemThunks.ts
1 1
import { createAsyncThunk } from "@reduxjs/toolkit"
2 2
import { getItemRequest } from "../../api/itemservice"
3 3
import { getItemNotesRequest } from "../../api/notesservice"
4
import { ItemViewState } from "../../types/item";
4
import { Concordance, ItemViewState } from "../../types/item";
5 5

  
6 6

  
7 7
export const getItem = createAsyncThunk(
......
16 16

  
17 17
            // data with image
18 18
            if (response.status === 200 && response.data.object.length > 1) {
19
                
20 19
                return {
21 20
                    id: itemId,
22 21
                    fullView: true,
......
28 27

  
29 28
                    inventoryItem: response.data.text,
30 29
                    searchSubjects: response.data.search_subject,
31
                
30

  
32 31
                    // additional fields
33 32
                    authorName: response.data.object[1].name[0].getty_data.display_name,
34 33

  
......
36 35
                    title: response.data.object[1].images[0].text,
37 36

  
38 37
                    institution: {
39
                        name :response.data.object[1].institution,
38
                        name: response.data.object[1].institution,
40 39
                        inventoryNumber: response.data.object[1].id_number,
41 40
                        country: response.data.object[1].country,
42 41
                        city: response.data.object[1].city
......
67 66
    }
68 67
)
69 68

  
70
export const getNextConcordance = createAsyncThunk(
71
    "item/getNextConcordance",
72
    async (_, { getState, dispatch }) => {
73
        const state = getState() as ItemViewState;
74

  
75
        const nextIndex = (state.selectedConcordance + 1) % state.concordances.length;
76

  
77
        // Dispatch the getItem action with the next concordance id
78
        await dispatch(getItem(state.concordances[nextIndex].id));
79

  
80
        // Return the next concordance index for updating the state in the reducer
81
        return nextIndex;
82
    }
83
);
84

  
85
export const getPreviousConcordance = createAsyncThunk(
86
    "item/getPreviousConcordance",
87
    async (_, { getState, dispatch }) => {
88
        const state = getState() as ItemViewState;
89
        const previousIndex = (state.selectedConcordance - 1 + state.concordances.length) % state.concordances.length;
90
        await dispatch(getItem(state.concordances[previousIndex].id));
91
        return previousIndex;
92
    }
93
);
69
export const setSelectedConcordance = (selectedConcordance: number) => {
70
    return {
71
      type: "item/setSelectedConcordance",
72
      payload: {
73
        selectedConcordance,
74
      },
75
    };
76
  };
77

  
78
  export const setConcordances = (concordances: Concordance[]) => {
79
    return {
80
      type: "item/setConcordances",
81
      payload: {
82
        concordances,
83
      },
84
    };
85
  };
94 86

  
95 87
// export const getItemConcordances = createAsyncThunk(
96 88
//     "item/getItemConcordances",

Také k dispozici: Unified diff