1 |
d3c12593
|
Fantič
|
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading, Switch, Flex } from "native-base"
|
2 |
|
|
import React, { useEffect, useState } from "react"
|
3 |
b88520f8
|
Fantič
|
import { Item } from "../../types/item"
|
4 |
|
|
import { Note } from "../../types/note"
|
5 |
a7a9a204
|
Fantič
|
import LoadingBox from "../loading/LoadingBox"
|
6 |
cb25df10
|
Fantič
|
import NotesListView from "../notes/NotesListView"
|
7 |
b225ffee
|
Fantič
|
import { IMAGE_URL } from "../../api/constants"
|
8 |
d3c12593
|
Fantič
|
import { log } from "../../logging/logger"
|
9 |
|
|
import { getAllNotes } from "../../stores/actions/notesThunks"
|
10 |
|
|
import { AppDispatch } from "../../stores/store"
|
11 |
|
|
import { useDispatch } from "react-redux"
|
12 |
|
|
import { getItemNotes } from "../../stores/actions/itemThunks"
|
13 |
b88520f8
|
Fantič
|
|
14 |
|
|
interface ItemDetailProps {
|
15 |
|
|
item: Item,
|
16 |
852de08e
|
Fantič
|
itemLoading: boolean,
|
17 |
|
|
notes: Note[],
|
18 |
72afb023
|
Fantič
|
notesLoading: boolean,
|
19 |
|
|
navigation: any
|
20 |
b88520f8
|
Fantič
|
}
|
21 |
|
|
|
22 |
d3c12593
|
Fantič
|
const ItemDetail = (props: { item: Item, itemLoading: boolean }) => {
|
23 |
b88520f8
|
Fantič
|
const item = props.item;
|
24 |
852de08e
|
Fantič
|
|
25 |
72afb023
|
Fantič
|
return (<>
|
26 |
|
|
{
|
27 |
d3c12593
|
Fantič
|
|
28 |
|
|
item && props.itemLoading ?
|
29 |
|
|
(<LoadingBox text="Item loading..." />)
|
30 |
|
|
:
|
31 |
|
|
(
|
32 |
|
|
<VStack>
|
33 |
|
|
<HStack marginTop="5%">
|
34 |
|
|
<VStack width="75%">
|
35 |
|
|
<Text>
|
36 |
|
|
{item.authorDisplayName ? item.authorDisplayName : item.authorName}
|
37 |
72afb023
|
Fantič
|
</Text>
|
38 |
d3c12593
|
Fantič
|
<Heading size="sm">
|
39 |
|
|
{item.workName}
|
40 |
|
|
</Heading>
|
41 |
|
|
|
42 |
|
|
</VStack>
|
43 |
|
|
<Box width="25%">
|
44 |
|
|
<Button variant="outline" size="md">
|
45 |
|
|
{item.concordances[0].id}
|
46 |
|
|
</Button>
|
47 |
|
|
</Box>
|
48 |
|
|
</HStack>
|
49 |
|
|
<Card shadow="1" marginTop="5%">
|
50 |
|
|
{item.inventoryItem &&
|
51 |
|
|
<VStack>
|
52 |
|
|
<Text italic>
|
53 |
|
|
<Text color="light.500">Inventory item: </Text>
|
54 |
|
|
{item.inventoryItem}
|
55 |
72afb023
|
Fantič
|
</Text>
|
56 |
|
|
<Text italic marginTop="2.5%">
|
57 |
d3c12593
|
Fantič
|
{item.searchSubjects.map((subject, index) => (
|
58 |
|
|
index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
|
59 |
|
|
))}
|
60 |
72afb023
|
Fantič
|
</Text>
|
61 |
d3c12593
|
Fantič
|
</VStack>}
|
62 |
|
|
</Card>
|
63 |
|
|
{item.fullView && item.imageUrl && (
|
64 |
|
|
<Center background="primary.100" marginTop="5%">
|
65 |
|
|
<Text>Resembling object</Text>
|
66 |
|
|
<Image size={250} alt="image" source={{ uri: IMAGE_URL + "/" + item.imageUrl }} />
|
67 |
|
|
</Center>)}
|
68 |
|
|
{item.fullView && (
|
69 |
|
|
<Card shadow="1" marginTop="5%" marginBottom="5%">
|
70 |
|
|
{item.authorName &&
|
71 |
|
|
<HStack>
|
72 |
|
|
<Text italic marginTop="2.5%">
|
73 |
|
|
<Text color="light.500">Author name: </Text>
|
74 |
|
|
{item.authorName}
|
75 |
|
|
</Text>
|
76 |
|
|
</HStack>}
|
77 |
|
|
{item.title &&
|
78 |
|
|
<HStack>
|
79 |
|
|
<Text italic marginTop="2.5%">
|
80 |
|
|
<Text color="light.500">Title: </Text>
|
81 |
|
|
{item.title}
|
82 |
|
|
</Text>
|
83 |
|
|
</HStack>}
|
84 |
|
|
{item.institution &&
|
85 |
|
|
<HStack>
|
86 |
|
|
<Text italic marginTop="2.5%">
|
87 |
|
|
<Text color="light.500">Institution: </Text>
|
88 |
|
|
{item.institution.name}, Inv. No. {item.institution.inventoryNumber}, {item.institution.city} {"(" + item.institution.country + ")"}
|
89 |
|
|
</Text>
|
90 |
|
|
</HStack>}
|
91 |
|
|
{item.repository &&
|
92 |
|
|
<HStack>
|
93 |
|
|
<Text italic marginTop="2.5%">
|
94 |
|
|
<Text color="light.500">Repository: </Text>
|
95 |
|
|
{item.repository}
|
96 |
|
|
</Text>
|
97 |
|
|
</HStack>}
|
98 |
|
|
{item.provenance &&
|
99 |
|
|
<HStack>
|
100 |
|
|
<Text italic marginTop="2.5%">
|
101 |
|
|
<Text color="light.500">Provenance: </Text>
|
102 |
|
|
{item.provenance}
|
103 |
|
|
</Text>
|
104 |
|
|
</HStack>}
|
105 |
|
|
{item.description &&
|
106 |
|
|
<HStack>
|
107 |
|
|
<Text italic marginTop="2.5%">
|
108 |
|
|
<Text color="light.500">Description: </Text>
|
109 |
|
|
{item.description}
|
110 |
|
|
</Text>
|
111 |
|
|
</HStack>}
|
112 |
|
|
</Card>)}
|
113 |
|
|
</VStack>
|
114 |
|
|
)
|
115 |
72afb023
|
Fantič
|
}</>
|
116 |
b88520f8
|
Fantič
|
);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
d3c12593
|
Fantič
|
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: any }) => {
|
122 |
|
|
|
123 |
|
|
const [showRelatedComments, setShowRelatedComments] = useState(true);
|
124 |
|
|
|
125 |
|
|
const dispatch = useDispatch<AppDispatch>();
|
126 |
|
|
|
127 |
|
|
const toggleRelatedComments = () => {
|
128 |
|
|
if (!props.notesLoading) {
|
129 |
|
|
|
130 |
|
|
let value = !showRelatedComments;
|
131 |
|
|
|
132 |
|
|
setShowRelatedComments(value);
|
133 |
|
|
dispatch(getItemNotes({ item: props.item, relatedComments: value }));
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
return (
|
138 |
|
|
|
139 |
|
|
props.notesLoading ?
|
140 |
|
|
(<LoadingBox text="Notes loading..." />)
|
141 |
|
|
:
|
142 |
|
|
(<VStack>
|
143 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
144 |
|
|
<Text fontSize={"12"}>Show related comments</Text>
|
145 |
|
|
<Switch value={showRelatedComments} onChange={toggleRelatedComments} size="md" />
|
146 |
|
|
</Flex>
|
147 |
|
|
<NotesListView notes={props.notes} handleDelete={() => console.log("TODO handle delete")} handleEdit={() => console.log("TODO handle edit")} handleReply={() => console.log("TODO handle reply")} setConfirmDialog={() => { }} navigation={props.navigation} />
|
148 |
|
|
</VStack>)
|
149 |
|
|
);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
b88520f8
|
Fantič
|
const ItemView = (props: ItemDetailProps) => {
|
155 |
|
|
|
156 |
|
|
// item shown / note shown
|
157 |
|
|
const [itemShown, setItemShown] = React.useState(true);
|
158 |
|
|
|
159 |
72afb023
|
Fantič
|
const { itemLoading, notesLoading, navigation } = props;
|
160 |
852de08e
|
Fantič
|
|
161 |
b88520f8
|
Fantič
|
const handleItemClick = () => {
|
162 |
|
|
setItemShown(true);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
const handleNotesClick = () => {
|
166 |
|
|
setItemShown(false);
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
return (
|
170 |
852de08e
|
Fantič
|
<Box display="flex" flex={1} flexDirection="column" justifyContent="space-between">
|
171 |
72afb023
|
Fantič
|
<ScrollView flex="1">
|
172 |
|
|
<Box width="92%" marginLeft="5%">
|
173 |
|
|
{itemShown ? (
|
174 |
d3c12593
|
Fantič
|
<ItemDetail itemLoading={itemLoading} item={props.item} />
|
175 |
72afb023
|
Fantič
|
) : (
|
176 |
d3c12593
|
Fantič
|
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
177 |
72afb023
|
Fantič
|
)}
|
178 |
|
|
</Box>
|
179 |
|
|
</ScrollView>
|
180 |
|
|
|
181 |
852de08e
|
Fantič
|
|
182 |
|
|
{/* item notes switch tab */}
|
183 |
|
|
<HStack alignItems="center">
|
184 |
091dec61
|
Fantič
|
<Button
|
185 |
852de08e
|
Fantič
|
variant={itemShown ? "subtle" : "outline"}
|
186 |
|
|
w="50%"
|
187 |
b88520f8
|
Fantič
|
onPress={handleItemClick}
|
188 |
|
|
>
|
189 |
|
|
Item
|
190 |
|
|
</Button>
|
191 |
091dec61
|
Fantič
|
<Button
|
192 |
852de08e
|
Fantič
|
variant={itemShown ? "outline" : "subtle"}
|
193 |
|
|
w="50%"
|
194 |
b88520f8
|
Fantič
|
onPress={handleNotesClick}
|
195 |
|
|
>
|
196 |
|
|
Notes
|
197 |
|
|
</Button>
|
198 |
|
|
</HStack>
|
199 |
852de08e
|
Fantič
|
</Box>
|
200 |
b88520f8
|
Fantič
|
)
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
export default ItemView
|