Revize 356c8bce
Přidáno uživatelem Fantič před téměř 2 roky(ů)
src/components/item/ItemDetail.tsx | ||
---|---|---|
1 | 1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, Divider } from "native-base" |
2 | 2 |
import React, { useState } from "react" |
3 | 3 |
import { Item } from "../../types/item" |
4 |
import { Note } from "../../types/note" |
|
4 | 5 |
|
5 | 6 |
interface ItemDetailProps { |
6 |
item: Item |
|
7 |
item: Item, |
|
8 |
notes: Note[] |
|
7 | 9 |
} |
8 | 10 |
|
9 | 11 |
|
10 |
const ItemView = (props: ItemDetailProps) => {
|
|
12 |
const ItemView = (props: {item: Item}) => {
|
|
11 | 13 |
const item = props.item; |
12 | 14 |
return ( |
13 | 15 |
<Center> |
src/pages/ItemViewPage.tsx | ||
---|---|---|
26 | 26 |
|
27 | 27 |
const { item, notes, concordances, selectedConcordance } = useSelector((state: RootState) => state.itemViewState) |
28 | 28 |
|
29 |
const [index, setIndex] = React.useState(0); |
|
30 | 29 |
|
31 |
|
|
32 |
// load main item |
|
30 |
// initial: load main item |
|
33 | 31 |
useEffect(() => { |
34 | 32 |
// TODO remove login from here |
35 | 33 |
dispatch(login({ username: "Viktorie", password: "Golem123." })); |
36 | 34 |
dispatch(getItem(props.itemId)); |
37 | 35 |
}, [props.itemId]); |
38 | 36 |
|
39 |
console.log(item.id); |
|
40 |
|
|
41 | 37 |
|
42 |
// concordances changed
|
|
38 |
// concordances are loaded
|
|
43 | 39 |
useEffect(() => { |
44 | 40 |
if (item && concordances && concordances.length > 0) { |
45 | 41 |
let concordanceRoutes = []; |
46 |
concordanceRoutes.push({ |
|
47 |
key: item.id, |
|
48 |
title: item.id |
|
49 |
}) |
|
50 | 42 |
|
51 | 43 |
for (let i = 0; i < concordances.length; i++) { |
52 | 44 |
let concordance = concordances[i]; |
... | ... | |
59 | 51 |
} |
60 | 52 |
}, [concordances]); |
61 | 53 |
|
62 |
// change tab |
|
63 |
useEffect(() => { |
|
54 |
const handleTabChange = (index: number) => { |
|
64 | 55 |
dispatch(setSelectedConcordance(index)); |
65 |
}, [index]);
|
|
56 |
}; |
|
66 | 57 |
|
58 |
// selected concordance changes |
|
67 | 59 |
useEffect(() => { |
68 | 60 |
if (concordances && concordances.length > 0) { |
69 | 61 |
dispatch(getItem(concordances[selectedConcordance].id)); |
70 | 62 |
} |
63 |
|
|
71 | 64 |
}, [selectedConcordance]); |
72 | 65 |
|
73 |
// item changes |
|
74 |
useEffect(() => { |
|
66 |
// item changes |
|
67 |
useEffect(() => { |
|
68 |
|
|
69 |
if (item && item.id) { |
|
75 | 70 |
if (selectedConcordance == 0) { |
76 | 71 |
dispatch(setConcordances(item.concordances)); |
77 | 72 |
} |
78 |
|
|
79 | 73 |
// set item notes if item is loaded |
80 | 74 |
if (item && item.id) { |
81 | 75 |
dispatch(getItemNotes(item.id)); |
82 | 76 |
} |
83 |
|
|
84 |
}, [item]); |
|
77 |
} |
|
78 |
|
|
79 |
}, [item]); |
|
85 | 80 |
|
86 | 81 |
return ( |
87 | 82 |
<TabView |
88 |
navigationState={{ index, routes }} |
|
83 |
navigationState={{ index: selectedConcordance, routes }}
|
|
89 | 84 |
renderScene={() => <ItemDetail item={item} />} |
90 |
onIndexChange={setIndex}
|
|
85 |
onIndexChange={handleTabChange}
|
|
91 | 86 |
initialLayout={{ width: layout.width }} |
92 | 87 |
/> |
93 |
|
|
94 |
|
|
95 | 88 |
); |
96 | 89 |
} |
97 | 90 |
|
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 |
|
src/stores/reducers/itemSlice.ts | ||
---|---|---|
8 | 8 |
high: { certainty: Certainty.High, color: "#FF0000" }, |
9 | 9 |
medium: { certainty: Certainty.Medium, color: "#FFFF00" }, |
10 | 10 |
low: { certainty: Certainty.Low, color: "#00FF00" }, |
11 |
unknown : { certainty: Certainty.Unknown, color: "#000000"} |
|
11 | 12 |
}; |
12 | 13 |
|
13 | 14 |
const initialState: ItemViewState = { |
... | ... | |
33 | 34 |
// getItem |
34 | 35 |
builder.addCase(getItem.fulfilled, (state, action) => { |
35 | 36 |
|
36 |
state.item.id = action.payload.id; |
|
37 |
state.item.authorDisplayName = action.payload.authorDisplayName; |
|
38 |
state.item.workName = action.payload.workName; |
|
39 |
state.item.concordances = action.payload.concordances; |
|
40 |
state.item.searchSubjects = action.payload.searchSubjects; |
|
41 |
state.item.inventoryItem = action.payload.inventoryItem; |
|
42 |
state.item.fullView = action.payload.fullView; |
|
37 |
state.item = { |
|
38 |
id : action.payload.id, |
|
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 |
fullView : action.payload.fullView, |
|
45 |
} |
|
43 | 46 |
|
44 | 47 |
if (action.payload.fullView) { |
45 | 48 |
state.item.institution = action.payload.institution; |
src/types/item.ts | ||
---|---|---|
44 | 44 |
High = "high", |
45 | 45 |
Medium = "medium", |
46 | 46 |
Low = "low", |
47 |
Unknown = "unknown" |
|
47 | 48 |
} |
Také k dispozici: Unified diff
re #10454: ItemView: concordances switch fix