commit a7264b57313aec8820b1f739afb76d3ae5aa8c88
Author: Fantič <58391275+FantaFantic@users.noreply.github.com>
Date:   Thu Apr 20 14:24:36 2023 +0200

    re #10454: ItemView: minor api call update

diff --git a/src/pages/ItemViewPage.tsx b/src/pages/ItemViewPage.tsx
index 80ee40c..9b885df 100644
--- a/src/pages/ItemViewPage.tsx
+++ b/src/pages/ItemViewPage.tsx
@@ -3,7 +3,7 @@ import React, { useState, useEffect } from "react"
 import { useDispatch, useSelector } from "react-redux"
 import { AppDispatch } from "../stores/store"
 import { getPreviousConcordance, getNextConcordance, getItem } from "../stores/actions/itemThunks"
-import { Item, ItemState } from "../types/item"
+import { Item, ItemViewState } from "../types/item"
 import { login } from "../stores/actions/userThunks"
 
 interface ItemViewProps {
@@ -14,7 +14,7 @@ const ItemViewPage = (props: ItemViewProps) => {
 
   const dispatch = useDispatch<AppDispatch>();
 
-  const itemViewState = useSelector((itemState: ItemState) => itemState)
+  const itemViewState = useSelector((itemState: ItemViewState) => itemState)
 
   const handleGetPreviousConcordance = async () => {
     dispatch(getPreviousConcordance());
@@ -29,7 +29,7 @@ const ItemViewPage = (props: ItemViewProps) => {
     dispatch(getItem(props.itemId));
   }, []);
 
-  console.log(itemViewState.item);
+  console.log(itemViewState.item)
 
   return (
     <VStack>
diff --git a/src/stores/actions/itemThunks.ts b/src/stores/actions/itemThunks.ts
index e2391af..556fa9b 100644
--- a/src/stores/actions/itemThunks.ts
+++ b/src/stores/actions/itemThunks.ts
@@ -1,7 +1,7 @@
 import { createAsyncThunk } from "@reduxjs/toolkit"
 import { getItemRequest } from "../../api/itemservice"
 import { getItemNotesRequest } from "../../api/notesservice"
-import { ItemState } from "../../types/item";
+import { ItemViewState } from "../../types/item";
 
 
 export const getItem = createAsyncThunk(
@@ -17,6 +17,7 @@ export const getItem = createAsyncThunk(
             // data with image
             if (response.status === 200 && response.data.object.length > 1) {
                 return {
+                    id: itemId,
                     fullView: true,
 
                     concordances: response.data.concordances,
@@ -47,12 +48,14 @@ export const getItem = createAsyncThunk(
             // data without image
             else if (response.status === 200 && response.data.object.length == 1) {
                 return {
+                    id: itemId,
                     fullView: false,
-
                     concordances: response.data.concordances,
 
-                    authorName: response.data.object[0].name[0].getty_data.display_name,
+                    authorDisplayName: response.data.object[0].name[0].getty_data.display_name,
                     workName: response.data.object[0].caption,
+                    inventoryItem: response.data.text,
+                    searchSubjects: response.data.search_subject,
                 }
             } {
                 return Promise.reject(response.data ? response.data : "Error")
@@ -66,7 +69,7 @@ export const getItem = createAsyncThunk(
 export const getNextConcordance = createAsyncThunk(
     "item/getNextConcordance",
     async (_, { getState, dispatch }) => {
-        const state = getState() as ItemState;
+        const state = getState() as ItemViewState;
 
         const nextIndex = (state.selectedConcordance + 1) % state.concordances.length;
 
@@ -81,7 +84,7 @@ export const getNextConcordance = createAsyncThunk(
 export const getPreviousConcordance = createAsyncThunk(
     "item/getPreviousConcordance",
     async (_, { getState, dispatch }) => {
-        const state = getState() as ItemState;
+        const state = getState() as ItemViewState;
         const previousIndex = (state.selectedConcordance - 1 + state.concordances.length) % state.concordances.length;
         await dispatch(getItem(state.concordances[previousIndex].id));
         return previousIndex;
diff --git a/src/stores/reducers/itemSlice.ts b/src/stores/reducers/itemSlice.ts
index c8ba66b..a0b0e09 100644
--- a/src/stores/reducers/itemSlice.ts
+++ b/src/stores/reducers/itemSlice.ts
@@ -1,6 +1,6 @@
 import { PayloadAction, createSlice } from "@reduxjs/toolkit"
 import { getItem, getItemNotes, getNextConcordance, getPreviousConcordance } from "../actions/itemThunks"
-import { Certainty, ItemState, Item } from "../../types/item";
+import { Certainty, ItemViewState, Item } from "../../types/item";
 
 
 export const CertaintyWithColors: Record<Certainty, { certainty: Certainty; color: string }> = {
@@ -10,7 +10,7 @@ export const CertaintyWithColors: Record<Certainty, { certainty: Certainty; colo
     low: { certainty: Certainty.Low, color: "#00FF00" },
 };
 
-const initialState: ItemState = {
+const initialState: ItemViewState = {
     item: {} as Item,
     selectedConcordance: 0,
     concordances: [],
@@ -32,16 +32,19 @@ export const itemSlice = createSlice({
                 state.concordances = action.payload.concordances;
             }
 
+            state.item = {
+                id: action.payload.id,
+                authorDisplayName: action.payload.authorDisplayName,
+                workName: action.payload.workName,
+                concordances: action.payload.concordances,
+                searchSubjects: action.payload.searchSubjects,
+                inventoryItem: action.payload.inventoryItem,
+                fullView: action.payload.fullView,
+            } as Item
+
             if(action.payload.fullView){
                 state.item = {
-                    fullView: true,
-                    
-                    authorDisplayName: action.payload.authorDisplayName,
-                    workName: action.payload.workName,
-                    concordances: action.payload.concordances,
-                    searchSubjects: action.payload.searchSubjects,
-                    inventoryItem: action.payload.inventoryItem,
-
+                    ...state.item,
                     // additional
                     institution: action.payload.institution,
                     authorName: action.payload.authorName,
@@ -52,16 +55,6 @@ export const itemSlice = createSlice({
                     description: action.payload.description
                 }
             }
-            else{
-                state.item = {
-                    fullView: false,
-                    authorDisplayName: action.payload.authorDisplayName,
-                    workName: action.payload.workName,
-                    concordances: action.payload.concordances,
-                    searchSubjects: action.payload.searchSubjects,
-                    inventoryItem: action.payload.inventoryItem
-                }
-            }
         })
         builder.addCase(getItem.rejected, (state, action) => {
             state.lastError = action.error.message
diff --git a/src/types/item.ts b/src/types/item.ts
index b081185..1b1d8a7 100644
--- a/src/types/item.ts
+++ b/src/types/item.ts
@@ -1,11 +1,12 @@
 import { Note } from "./note"
 
 export type  Item = {
+    id: string
+    
     concordances: Concordance[]
 
     authorDisplayName: string
     workName: string
-
     inventoryItem: string
     searchSubjects: string[]
 
@@ -13,7 +14,6 @@ export type  Item = {
 
     authorName?: string
     imageUrl?: string
-
     title?: string
     institution?: { 
         name :string,
@@ -26,7 +26,7 @@ export type  Item = {
     description?: string
 }
 
-export type ItemState = {
+export type ItemViewState = {
     item: Item
     concordances: Concordance[]
     selectedConcordance: number
