Revize c1161e82
Přidáno uživatelem Fantič před více než 1 rok
src/components/item/ItemTabBar.tsx | ||
---|---|---|
1 | 1 |
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon } from "native-base"; |
2 | 2 |
import { CertaintyWithColors } from "../../stores/reducers/itemSlice"; |
3 |
import { Concordance } from "../../types/item"; |
|
3 |
import { Certainty, Concordance } from "../../types/item";
|
|
4 | 4 |
import LoadingBox from "../loading/LoadingBox"; |
5 | 5 |
|
6 | 6 |
// custom render Tab |
... | ... | |
46 | 46 |
<CircleIcon |
47 | 47 |
marginLeft="5" |
48 | 48 |
size="2" |
49 |
color={CertaintyWithColors[concordances[i].cert].color} |
|
49 |
color={CertaintyWithColors[concordances[i].cert ?? Certainty.Unknown].color}
|
|
50 | 50 |
/> |
51 | 51 |
<Text marginLeft="5%"> |
52 | 52 |
{i == index ? <Text bold>{concordances[i].id}</Text> : concordances[i].id} |
... | ... | |
64 | 64 |
<CircleIcon |
65 | 65 |
marginLeft="42%" |
66 | 66 |
size="2" |
67 |
color={CertaintyWithColors[concordances[0].cert].color} |
|
67 |
color={CertaintyWithColors[concordances[0].cert ?? Certainty.Unknown].color}
|
|
68 | 68 |
/> |
69 | 69 |
<Text marginLeft="2%"> |
70 | 70 |
<Text bold>{concordances[0].id}</Text> |
src/components/item/ItemView.tsx | ||
---|---|---|
47 | 47 |
</VStack> |
48 | 48 |
<Box marginLeft="auto" marginTop={0}> {/* marginLeft: "auto" pushes the Box to the right */} |
49 | 49 |
<Button variant="outline" size="md"> |
50 |
{item.concordances[0].id}
|
|
50 |
{item?.concordances?.[0]?.id}
|
|
51 | 51 |
</Button> |
52 | 52 |
</Box> |
53 | 53 |
</HStack> |
... | ... | |
59 | 59 |
{item.inventoryItem} |
60 | 60 |
</Text> |
61 | 61 |
<Text italic marginTop="2.5%"> |
62 |
{item.searchSubjects.map((subject, index) => ( |
|
63 |
index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject) |
|
62 |
{item.searchSubjects != undefined && item?.searchSubjects?.map((subject, index) => (
|
|
63 |
item.searchSubjects && index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
|
|
64 | 64 |
))} |
65 | 65 |
</Text> |
66 | 66 |
</VStack>} |
src/pages/ItemViewPage.tsx | ||
---|---|---|
19 | 19 |
|
20 | 20 |
const layout = useWindowDimensions(); |
21 | 21 |
|
22 |
const [routes, setRoutes] = React.useState([ |
|
22 |
const [routes, setRoutes] = React.useState<{key: string, title: string}[]>([
|
|
23 | 23 |
// initial tab |
24 | 24 |
{ key: 'loading', title: 'Loading item...' }, |
25 | 25 |
]); |
... | ... | |
54 | 54 |
useEffect(() => { |
55 | 55 |
dispatch(getItem(route.params.itemId)); |
56 | 56 |
log.debug("ItemViewPage", "useEffect", "getItem", route.params.itemId); |
57 |
}, []) |
|
58 |
|
|
57 |
}, [route.params.itemId]) |
|
59 | 58 |
|
60 | 59 |
// concordances are loaded |
61 | 60 |
useEffect(() => { |
... | ... | |
69 | 68 |
for (let i = 0; i < concordances.length; i++) { |
70 | 69 |
let concordance = concordances[i]; |
71 | 70 |
concordanceRoutes.push({ |
72 |
key: concordance.id, |
|
73 |
title: concordance.id |
|
71 |
key: concordance.id ?? "",
|
|
72 |
title: concordance.id ?? ""
|
|
74 | 73 |
}) |
75 | 74 |
// _renderSceneDict[concordance.id] = <LoadingBox text={`Loading item ${concordance.id}...`}></LoadingBox>; |
76 | 75 |
} |
... | ... | |
86 | 85 |
|
87 | 86 |
if (!itemLoading && item && item.id) { |
88 | 87 |
if (index == 0) { |
89 |
dispatch(setConcordances(item.concordances)); |
|
88 |
dispatch(setConcordances(item.concordances ?? []));
|
|
90 | 89 |
} |
91 | 90 |
// set item notes if item is loaded |
92 | 91 |
if (item && item.id) { |
... | ... | |
100 | 99 |
console.log("index changed"); |
101 | 100 |
setIndex(newIndex); |
102 | 101 |
if (concordances && concordances.length > 0) { |
103 |
dispatch(getItem(concordances[newIndex].id)); |
|
102 |
dispatch(getItem(concordances[newIndex].id ?? ""));
|
|
104 | 103 |
} |
105 | 104 |
} |
106 | 105 |
} |
src/stores/actions/itemThunks.ts | ||
---|---|---|
2 | 2 |
import { getItemRequest } from "../../api/itemservice" |
3 | 3 |
import { getItemNotesRequest } from "../../api/notesservice" |
4 | 4 |
import { Certainty, Concordance, Item } from "../../types/item"; |
5 |
import { Note } from "../../types/note"; |
|
6 | 5 |
|
7 | 6 |
|
8 | 7 |
export const getItem = createAsyncThunk( |
... | ... | |
16 | 15 |
// data with image |
17 | 16 |
if (response.status === 200 && response.data.object.length > 1) { |
18 | 17 |
// TODO IMAGES to array :-) |
19 |
const authorName = response.data.object[1]?.name?.[0]?.getty_data?.display_name || null;
|
|
18 |
const authorName = response.data?.object[1]?.name?.[0]?.getty_data?.display_name ?? undefined;
|
|
20 | 19 |
const images : {imageUrl: string, title: string}[] = [] |
21 |
for(let i = 0; i < response.data.object[1]?.images.length; i++){
|
|
22 |
images.push({imageUrl: response.data.object[1]?.images?.[i]?.file, title: response.data.object[1]?.images?.[i]?.text})
|
|
20 |
for(let i = 1; i < response.data.object.length; i++){
|
|
21 |
images.push({imageUrl: response.data.object[i]?.images?.[0]?.file, title: response.data.object[i]?.images?.[0]?.text})
|
|
23 | 22 |
} |
24 | 23 |
|
25 | 24 |
const institution = { |
26 |
name: response.data.object[1]?.institution || null,
|
|
27 |
inventoryNumber: response.data.object[1]?.id_number || null,
|
|
28 |
country: response.data.object[1]?.country || null,
|
|
29 |
city: response.data.object[1]?.city || null
|
|
25 |
name: response.data?.object[1]?.institution ?? undefined,
|
|
26 |
inventoryNumber: response.data?.object[1]?.id_number ?? undefined,
|
|
27 |
country: response.data?.object[1]?.country ?? undefined,
|
|
28 |
city: response.data?.object[1]?.city ?? undefined
|
|
30 | 29 |
}; |
31 |
const repository = response.data.object[1]?.repository || null;
|
|
32 |
const provenance = response.data.object[1]?.provenance || null;
|
|
33 |
const description = response.data.object[1]?.physical_description || null;
|
|
30 |
const repository = response.data?.object[1]?.repository ?? undefined;
|
|
31 |
const provenance = response.data?.object[1]?.provenance ?? undefined;
|
|
32 |
const description = response.data?.object[1]?.physical_description ?? undefined;
|
|
34 | 33 |
|
35 | 34 |
return { |
36 | 35 |
id: itemId, |
37 | 36 |
fullView: true, |
38 | 37 |
concordances: response.data.concordances ? |
39 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }].concat(response.data.concordances)
|
|
38 |
[{ id: itemId, cert: response.data?.object[1]?.cert ?? Certainty.Unknown }].concat(response.data.concordances)
|
|
40 | 39 |
: |
41 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }],
|
|
42 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null,
|
|
43 |
workName: response.data.object[0]?.caption || null,
|
|
44 |
inventoryItem: response.data.text || null,
|
|
45 |
searchSubjects: response.data.search_subject || null,
|
|
40 |
[{ id: itemId, cert: response.data?.object[1]?.cert ?? Certainty.Unknown }],
|
|
41 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name ?? undefined,
|
|
42 |
workName: response.data.object[0]?.caption ?? undefined,
|
|
43 |
inventoryItem: response.data.text ?? undefined,
|
|
44 |
searchSubjects: response.data.search_subject ?? undefined,
|
|
46 | 45 |
authorName, |
47 | 46 |
images, |
48 | 47 |
institution, |
... | ... | |
57 | 56 |
id: itemId, |
58 | 57 |
fullView: false, |
59 | 58 |
concordances: response.data.concordances ? |
60 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }].concat(response.data.concordances)
|
|
59 |
[{ id: itemId, cert: response.data?.object[1]?.cert ?? Certainty.Unknown }].concat(response.data.concordances)
|
|
61 | 60 |
: |
62 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }],
|
|
63 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null,
|
|
64 |
workName: response.data.object[0]?.caption || null,
|
|
65 |
inventoryItem: response.data.text || null,
|
|
66 |
searchSubjects: response.data.search_subject || null,
|
|
61 |
[{ id: itemId, cert: response.data?.object[1]?.cert ?? Certainty.Unknown }],
|
|
62 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name ?? undefined,
|
|
63 |
workName: response.data.object[0]?.caption ?? undefined,
|
|
64 |
inventoryItem: response.data.text ?? undefined,
|
|
65 |
searchSubjects: response.data.search_subject ?? undefined,
|
|
67 | 66 |
} |
68 | 67 |
} |
69 | 68 |
else { |
... | ... | |
115 | 114 |
const response = await getItemNotesRequest(item, relatedComments); |
116 | 115 |
|
117 | 116 |
if (response.status === 200) { |
118 |
if (response.data.length > 0) { |
|
117 |
if (response.data && response.data.length > 0) {
|
|
119 | 118 |
|
120 | 119 |
let notes = []; |
121 | 120 |
for (let i = 0; i < response.data.length; i++) { |
src/types/item.ts | ||
---|---|---|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
export type Item = { |
5 |
id: string |
|
5 |
id?: string
|
|
6 | 6 |
|
7 |
concordances: Concordance[] |
|
7 |
concordances?: Concordance[]
|
|
8 | 8 |
|
9 |
authorDisplayName: string |
|
10 |
workName: string |
|
11 |
inventoryItem: string |
|
12 |
searchSubjects: string[] |
|
9 |
authorDisplayName?: string
|
|
10 |
workName?: string
|
|
11 |
inventoryItem?: string
|
|
12 |
searchSubjects?: string[]
|
|
13 | 13 |
|
14 | 14 |
fullView : boolean |
15 | 15 |
|
... | ... | |
37 | 37 |
} |
38 | 38 |
|
39 | 39 |
export type Concordance = { |
40 |
id: string |
|
41 |
cert: Certainty |
|
40 |
id?: string
|
|
41 |
cert?: Certainty
|
|
42 | 42 |
} |
43 | 43 |
|
44 | 44 |
export enum Certainty { |
Také k dispozici: Unified diff
re #10819 ItemView prevent error states