Revize 356c8bce
Přidáno uživatelem Fantič před téměř 2 roky(ů)
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 { Concordance, ItemViewState } from "../../types/item";
|
|
4 |
import { Certainty, Concordance } from "../../types/item";
|
|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
export const getItem = createAsyncThunk( |
... | ... | |
11 | 11 |
console.log("GET item/getItem/" + itemId); |
12 | 12 |
|
13 | 13 |
const response = await getItemRequest(itemId); |
14 |
|
|
15 | 14 |
|
16 | 15 |
// data with image |
17 | 16 |
if (response.status === 200 && response.data.object.length > 1) { |
17 |
const authorName = response.data.object[1]?.name?.[0]?.getty_data?.display_name || null; |
|
18 |
const imageUrl = response.data.object[1]?.images?.[0]?.file || null; |
|
19 |
const title = response.data.object[1]?.images?.[0]?.text || null; |
|
20 |
const institution = { |
|
21 |
name: response.data.object[1]?.institution || null, |
|
22 |
inventoryNumber: response.data.object[1]?.id_number || null, |
|
23 |
country: response.data.object[1]?.country || null, |
|
24 |
city: response.data.object[1]?.city || null |
|
25 |
}; |
|
26 |
const repository = response.data.object[1]?.repository || null; |
|
27 |
const provenance = response.data.object[1]?.provenance || null; |
|
28 |
const description = response.data.object[1]?.physical_description || null; |
|
29 |
|
|
18 | 30 |
return { |
19 | 31 |
id: itemId, |
20 | 32 |
fullView: true, |
21 |
|
|
22 |
concordances: response.data.concordances, |
|
23 |
|
|
24 |
authorDisplayName: response.data.object[0].name[0].getty_data.display_name, |
|
25 |
workName: response.data.object[0].caption, |
|
26 |
|
|
27 |
inventoryItem: response.data.text, |
|
28 |
searchSubjects: response.data.search_subject, |
|
29 |
|
|
30 |
// additional fields |
|
31 |
authorName: response.data.object[1].name[0].getty_data.display_name, |
|
32 |
|
|
33 |
imageUrl: response.data.object[1].images[0].file, |
|
34 |
title: response.data.object[1].images[0].text, |
|
35 |
|
|
36 |
institution: { |
|
37 |
name: response.data.object[1].institution, |
|
38 |
inventoryNumber: response.data.object[1].id_number, |
|
39 |
country: response.data.object[1].country, |
|
40 |
city: response.data.object[1].city |
|
41 |
}, |
|
42 |
repository: response.data.object[1].repository, |
|
43 |
provenance: response.data.object[1].provenance, |
|
44 |
description: response.data.object[1].physical_description |
|
33 |
concordances: [{id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown}].concat(response.data.concordances), |
|
34 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null, |
|
35 |
workName: response.data.object[0]?.caption || null, |
|
36 |
inventoryItem: response.data.text || null, |
|
37 |
searchSubjects: response.data.search_subject || null, |
|
38 |
authorName, |
|
39 |
imageUrl, |
|
40 |
title, |
|
41 |
institution, |
|
42 |
repository, |
|
43 |
provenance, |
|
44 |
description |
|
45 | 45 |
} |
46 | 46 |
} |
47 | 47 |
// data without image |
... | ... | |
49 | 49 |
return { |
50 | 50 |
id: itemId, |
51 | 51 |
fullView: false, |
52 |
concordances: response.data.concordances, |
|
53 |
|
|
54 |
authorDisplayName: response.data.object[0].name[0].getty_data.display_name, |
|
55 |
workName: response.data.object[0].caption, |
|
56 |
inventoryItem: response.data.text, |
|
57 |
searchSubjects: response.data.search_subject, |
|
52 |
concordances: [{id: itemId, cert: Certainty.Unknown}].concat(response.data.concordances), |
|
53 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null, |
|
54 |
workName: response.data.object[0]?.caption || null, |
|
55 |
inventoryItem: response.data.text || null, |
|
56 |
searchSubjects: response.data.search_subject || null, |
|
58 | 57 |
} |
59 | 58 |
} |
60 | 59 |
else { |
60 |
console.log("Error " + response.data); |
|
61 | 61 |
return Promise.reject(response.data ? response.data : "Error") |
62 | 62 |
} |
63 | 63 |
} catch (err: any) { |
64 |
|
|
65 |
console.log(err); |
|
64 | 66 |
return Promise.reject(err.response.data) |
65 | 67 |
} |
66 | 68 |
} |
... | ... | |
107 | 109 |
"item/getItemNotes", |
108 | 110 |
async (itemId: string) => { |
109 | 111 |
try { |
110 |
console.log("¨GET notes/getNotes/" + itemId);
|
|
112 |
console.log("GET notes/getNotes/" + itemId); |
|
111 | 113 |
|
112 | 114 |
const response = await getItemNotesRequest(itemId); |
113 | 115 |
|
Také k dispozici: Unified diff
re #10454: ItemView: concordances switch fix