1 |
7e9d79f3
|
Fantič
|
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading, Switch, Flex, ChevronLeftIcon, ChevronRightIcon, Divider, Pressable, CircleIcon, IconButton } from "native-base"
|
2 |
56626a63
|
Fantič
|
import React, { useCallback, useEffect, useState } from "react"
|
3 |
fb120216
|
Fantič
|
import { Certainty, Item, RelationshipType } from "../../types/item"
|
4 |
b88520f8
|
Fantič
|
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 |
2135f53d
|
Fantič
|
import { createNote, getAllNotes } from "../../stores/actions/notesThunks"
|
10 |
|
|
import { AppDispatch, RootState } from "../../stores/store"
|
11 |
|
|
import { useDispatch, useSelector } from "react-redux"
|
12 |
d3c12593
|
Fantič
|
import { getItemNotes } from "../../stores/actions/itemThunks"
|
13 |
b88520f8
|
Fantič
|
|
14 |
293f99f8
|
Fantič
|
import { Dimensions } from "react-native";
|
15 |
8ff3394e
|
Fantič
|
import { DrawerNavigationProp } from "@react-navigation/drawer"
|
16 |
a62d7c92
|
Michal Schwob
|
import { RootStackParamList } from "../../pages/Navigation"
|
17 |
f4af30c8
|
Fantič
|
import { select } from "d3"
|
18 |
fb120216
|
Fantič
|
import { CertaintyWithColors } from "../../stores/reducers/itemSlice"
|
19 |
7e9d79f3
|
Fantič
|
import { LeftArrowIcon, RightArrowIcon } from "../general/Icons"
|
20 |
d0870262
|
Fantič
|
import { ZoomableImage } from "./ZoomableImage"
|
21 |
293f99f8
|
Fantič
|
|
22 |
b88520f8
|
Fantič
|
interface ItemDetailProps {
|
23 |
|
|
item: Item,
|
24 |
852de08e
|
Fantič
|
itemLoading: boolean,
|
25 |
|
|
notes: Note[],
|
26 |
72afb023
|
Fantič
|
notesLoading: boolean,
|
27 |
a62d7c92
|
Michal Schwob
|
navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined>
|
28 |
b88520f8
|
Fantič
|
}
|
29 |
|
|
|
30 |
f4af30c8
|
Fantič
|
const ItemDetail = (props: ItemDetailProps) => {
|
31 |
b88520f8
|
Fantič
|
const item = props.item;
|
32 |
852de08e
|
Fantič
|
|
33 |
e0741b92
|
Fantič
|
const [selectedImage, setSelectedImage] = useState<number>(0);
|
34 |
|
|
|
35 |
f4af30c8
|
Fantič
|
const [images, setImages] = useState<{ imageUrl: string, title: string }[]>([]);
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
useEffect(() => {
|
39 |
|
|
if (item.images?.[0]) {
|
40 |
|
|
setImages([item.images[0], item.images[0], item.images[0], item.images[0], item.images[0], item.images[0], item.images[0]])
|
41 |
|
|
}
|
42 |
|
|
}, [item])
|
43 |
|
|
|
44 |
72afb023
|
Fantič
|
return (<>
|
45 |
|
|
{
|
46 |
d3c12593
|
Fantič
|
item && props.itemLoading ?
|
47 |
|
|
(<LoadingBox text="Item loading..." />)
|
48 |
|
|
:
|
49 |
|
|
(
|
50 |
7e9d79f3
|
Fantič
|
<ScrollView flex="1" paddingLeft={2.5} paddingRight={2.5} marginTop={2.5}>
|
51 |
2135f53d
|
Fantič
|
<VStack>
|
52 |
e0741b92
|
Fantič
|
<HStack marginLeft={2.5} alignItems={"center"}>
|
53 |
|
|
<VStack flex={1} marginTop={3.5}>
|
54 |
f4af30c8
|
Fantič
|
<Text fontSize={13} color="#4D4D4D">
|
55 |
2135f53d
|
Fantič
|
{item.authorDisplayName ? item.authorDisplayName : item.authorName}
|
56 |
72afb023
|
Fantič
|
</Text>
|
57 |
f4af30c8
|
Fantič
|
<Heading marginTop={1} fontSize={18} color="#4D4D4D">
|
58 |
2135f53d
|
Fantič
|
{item.workName}
|
59 |
|
|
</Heading>
|
60 |
f4af30c8
|
Fantič
|
|
61 |
2135f53d
|
Fantič
|
</VStack>
|
62 |
d0870262
|
Fantič
|
<Box marginLeft="auto" marginTop={1.5} alignItems={"end"}> {/* marginLeft: "auto" pushes the Box to the right */}
|
63 |
|
|
<Button variant="outline" backgroundColor={"#F4DFAB"} borderRadius={8} size="sm" padding={0.5} paddingLeft={2} paddingRight={2} >
|
64 |
7e9d79f3
|
Fantič
|
<Text color="#654B07" fontSize={12}>
|
65 |
f4af30c8
|
Fantič
|
{item?.concordances?.[0]?.id}
|
66 |
|
|
</Text>
|
67 |
2135f53d
|
Fantič
|
</Button>
|
68 |
|
|
</Box>
|
69 |
|
|
</HStack>
|
70 |
f4af30c8
|
Fantič
|
|
71 |
|
|
|
72 |
ca637f52
|
Fantič
|
|
73 |
|
|
|
74 |
f4af30c8
|
Fantič
|
<View marginTop={5} backgroundColor="#F5F4F1" borderRadius={10} borderColor="#F5F4F1" padding={2}>
|
75 |
2135f53d
|
Fantič
|
{item.inventoryItem &&
|
76 |
|
|
<VStack>
|
77 |
7e9d79f3
|
Fantič
|
<Text >
|
78 |
f4af30c8
|
Fantič
|
<Text color="#654B07" italic fontWeight={"semibold"}>Inventory item: </Text>
|
79 |
2135f53d
|
Fantič
|
{item.inventoryItem}
|
80 |
d3c12593
|
Fantič
|
</Text>
|
81 |
7e9d79f3
|
Fantič
|
<Text marginTop="2.5%">
|
82 |
c1161e82
|
Fantič
|
{item.searchSubjects != undefined && item?.searchSubjects?.map((subject, index) => (
|
83 |
f4af30c8
|
Fantič
|
subject != "" ?
|
84 |
|
|
item.searchSubjects && index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
|
85 |
|
|
:
|
86 |
|
|
""
|
87 |
2135f53d
|
Fantič
|
))}
|
88 |
d3c12593
|
Fantič
|
</Text>
|
89 |
2135f53d
|
Fantič
|
</VStack>}
|
90 |
f4af30c8
|
Fantič
|
</View>
|
91 |
e0741b92
|
Fantič
|
{item.fullView && item.images && item.images.length > 0 && (
|
92 |
7e9d79f3
|
Fantič
|
<VStack marginTop={5} alignItems="center" justifyContent="center" backgroundColor="#F5F4F1" borderRadius={10} borderColor="#F5F4F1" padding={0}>
|
93 |
f4af30c8
|
Fantič
|
|
94 |
fb120216
|
Fantič
|
<Box style={{ backgroundColor: item.images[selectedImage].relationship_type != RelationshipType.IdentifiedArtwork ? "#B3B3B3" : CertaintyWithColors[item.images[selectedImage].cert ?? Certainty.Unknown].color }}
|
95 |
7e9d79f3
|
Fantič
|
marginTop={0} width={Dimensions.get('window').width - 20} alignItems="center" borderTopRadius={10} >
|
96 |
fb120216
|
Fantič
|
<Text marginBottom={2}>
|
97 |
ca637f52
|
Fantič
|
|
98 |
fb120216
|
Fantič
|
{item.images[selectedImage].relationship_type == RelationshipType.Resembling && "Resembling object"}
|
99 |
|
|
{item.images[selectedImage].relationship_type == RelationshipType.IdentifiedArtwork && "Identified artwork"}
|
100 |
|
|
{item.images[selectedImage].relationship_type == RelationshipType.Related && "Related item"}
|
101 |
|
|
|
102 |
|
|
{item.images[selectedImage].relationship_type == RelationshipType.IdentifiedArtwork && item.images[selectedImage].cert && item.images[selectedImage].cert != Certainty.Unknown && ` - ${item.images?.[selectedImage].cert}`}
|
103 |
f4af30c8
|
Fantič
|
</Text>
|
104 |
|
|
</Box>
|
105 |
|
|
|
106 |
7e9d79f3
|
Fantič
|
<HStack style={{ alignItems: "center", marginTop: 5 }}>
|
107 |
|
|
<IconButton variant="ghost" style={{ height: 30, width: 30, borderRadius: 15 }} onPress={() => {
|
108 |
e0741b92
|
Fantič
|
if (item.images && selectedImage - 1 >= 0) {
|
109 |
|
|
setSelectedImage(selectedImage - 1);
|
110 |
|
|
}
|
111 |
7e9d79f3
|
Fantič
|
}} icon={<LeftArrowIcon color="#49454F" />} />
|
112 |
d0870262
|
Fantič
|
|
113 |
|
|
<ZoomableImage fullScreen={false} size={Dimensions.get('window').width - 110} imageUri={IMAGE_URL + "/" + item.images[selectedImage].imageUrl} />
|
114 |
|
|
|
115 |
|
|
<IconButton variant="ghost" style={{ height: 30, width: 30, borderRadius: 15 }} onPress={() => {
|
116 |
e0741b92
|
Fantič
|
if (item.images && selectedImage + 1 < item.images.length) {
|
117 |
|
|
setSelectedImage(selectedImage + 1);
|
118 |
|
|
}
|
119 |
7e9d79f3
|
Fantič
|
}} icon={<RightArrowIcon color="#49454F" />} />
|
120 |
e0741b92
|
Fantič
|
</HStack>
|
121 |
f4af30c8
|
Fantič
|
<ScrollView horizontal marginBottom={2.5} marginTop={5}>
|
122 |
|
|
|
123 |
|
|
{item.images.map((image, index) => (
|
124 |
|
|
<Pressable
|
125 |
|
|
onPress={() => { setSelectedImage(index); }}>
|
126 |
|
|
<Image marginLeft={2.5} size={90} alt="image" source={{ uri: IMAGE_URL + "/" + image.imageUrl }}
|
127 |
|
|
borderColor={selectedImage == index ? "#1782FF" : undefined}
|
128 |
|
|
borderWidth={3}
|
129 |
1abbf06f
|
František Kaiser
|
resizeMode={"contain"}
|
130 |
f4af30c8
|
Fantič
|
/>
|
131 |
|
|
</Pressable>
|
132 |
|
|
|
133 |
|
|
))}
|
134 |
|
|
</ScrollView>
|
135 |
e0741b92
|
Fantič
|
</VStack>
|
136 |
|
|
)}
|
137 |
2135f53d
|
Fantič
|
{item.fullView && (
|
138 |
f4af30c8
|
Fantič
|
<View marginTop={5} backgroundColor="#F5F4F1" borderRadius={10} borderColor="#F5F4F1" padding={2} marginBottom={5}>
|
139 |
2135f53d
|
Fantič
|
{item.authorName &&
|
140 |
|
|
<HStack>
|
141 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
142 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Author name: </Text>
|
143 |
fb120216
|
Fantič
|
{item.images?.[selectedImage]?.author}
|
144 |
2135f53d
|
Fantič
|
</Text>
|
145 |
|
|
</HStack>}
|
146 |
|
|
{item.title &&
|
147 |
|
|
<HStack>
|
148 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
149 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Title: </Text>
|
150 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].title}
|
151 |
2135f53d
|
Fantič
|
</Text>
|
152 |
|
|
</HStack>}
|
153 |
|
|
{item.institution &&
|
154 |
|
|
<HStack>
|
155 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
156 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Institution: </Text>
|
157 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].institution.name && `${item.images?.[selectedImage].institution.name}`}
|
158 |
|
|
{item.images?.[selectedImage].institution.inventoryNumber && `, Inv. No. ${item.images?.[selectedImage].institution.inventoryNumber}`}
|
159 |
|
|
{item.images?.[selectedImage].institution.city && `, ${item.images?.[selectedImage].institution.city}`}
|
160 |
|
|
{item.images?.[selectedImage].institution.country && ` (${item.images?.[selectedImage].institution.country})`}
|
161 |
2135f53d
|
Fantič
|
</Text>
|
162 |
|
|
</HStack>}
|
163 |
|
|
{item.repository &&
|
164 |
|
|
<HStack>
|
165 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
166 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Repository: </Text>
|
167 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].repository}
|
168 |
2135f53d
|
Fantič
|
</Text>
|
169 |
|
|
</HStack>}
|
170 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].provenance &&
|
171 |
2135f53d
|
Fantič
|
<HStack>
|
172 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
173 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Provenance: </Text>
|
174 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].provenance}
|
175 |
2135f53d
|
Fantič
|
</Text>
|
176 |
|
|
</HStack>}
|
177 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].description &&
|
178 |
2135f53d
|
Fantič
|
<HStack>
|
179 |
f4af30c8
|
Fantič
|
<Text marginTop={2.5}>
|
180 |
|
|
<Text color="#654B07" italic fontWeight={"semibold"}>Description: </Text>
|
181 |
fb120216
|
Fantič
|
{item.images?.[selectedImage].description}
|
182 |
2135f53d
|
Fantič
|
</Text>
|
183 |
|
|
</HStack>}
|
184 |
f4af30c8
|
Fantič
|
</View>)}
|
185 |
|
|
|
186 |
|
|
{
|
187 |
|
|
item.room && item.room.id &&
|
188 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
189 |
|
|
<Button
|
190 |
|
|
onPress={() => props.navigation.navigate("Plan", { roomId: item?.room?.id, placeId: undefined })}
|
191 |
|
|
variant={"link"}
|
192 |
|
|
backgroundColor={"#F4DFAB"}
|
193 |
|
|
borderRadius={7}
|
194 |
|
|
marginTop={0}
|
195 |
|
|
marginBottom={5}
|
196 |
|
|
width={125}
|
197 |
|
|
rightIcon={<ChevronRightIcon size="xs" />}>
|
198 |
|
|
Show in map
|
199 |
|
|
</Button>
|
200 |
|
|
</Flex>
|
201 |
|
|
|
202 |
|
|
}
|
203 |
|
|
|
204 |
2135f53d
|
Fantič
|
</VStack>
|
205 |
f4af30c8
|
Fantič
|
</ScrollView >
|
206 |
d3c12593
|
Fantič
|
)
|
207 |
72afb023
|
Fantič
|
}</>
|
208 |
b88520f8
|
Fantič
|
);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
a62d7c92
|
Michal Schwob
|
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined> }) => {
|
214 |
d3c12593
|
Fantič
|
|
215 |
|
|
const [showRelatedComments, setShowRelatedComments] = useState(true);
|
216 |
|
|
|
217 |
1853180f
|
Fantič
|
const { requestPending, triggerRefresh } = useSelector((state: RootState) => state.noteViewState)
|
218 |
2135f53d
|
Fantič
|
|
219 |
d3c12593
|
Fantič
|
const dispatch = useDispatch<AppDispatch>();
|
220 |
|
|
|
221 |
1853180f
|
Fantič
|
// trigger refresh on triggerRefresh increment
|
222 |
|
|
useEffect(() => {
|
223 |
e0741b92
|
Fantič
|
if (triggerRefresh > 0) {
|
224 |
1853180f
|
Fantič
|
log.debug("NotesViewPage", "useEffect", "getNotes");
|
225 |
|
|
dispatch(getItemNotes({ item: props.item, relatedComments: showRelatedComments }));
|
226 |
|
|
}
|
227 |
|
|
}, [triggerRefresh])
|
228 |
f4af30c8
|
Fantič
|
|
229 |
8ff3394e
|
Fantič
|
const toggleRelatedComments = useCallback(() => {
|
230 |
d3c12593
|
Fantič
|
if (!props.notesLoading) {
|
231 |
|
|
|
232 |
|
|
let value = !showRelatedComments;
|
233 |
|
|
|
234 |
|
|
setShowRelatedComments(value);
|
235 |
|
|
dispatch(getItemNotes({ item: props.item, relatedComments: value }));
|
236 |
|
|
}
|
237 |
f4af30c8
|
Fantič
|
}, [showRelatedComments]);
|
238 |
8ff3394e
|
Fantič
|
|
239 |
d3c12593
|
Fantič
|
|
240 |
56626a63
|
Fantič
|
const handleCreateItemComment = useCallback(
|
241 |
|
|
(newComment: string, replyingTo: { messageId: string; userName: string } | null) => {
|
242 |
|
|
if (!requestPending) {
|
243 |
|
|
// creating new comment
|
244 |
|
|
if (replyingTo != null) {
|
245 |
|
|
dispatch(createNote({ newNote: { note: newComment, reply_to: replyingTo.messageId } as Note }));
|
246 |
|
|
} else {
|
247 |
|
|
dispatch(createNote({ newNote: { note: newComment, items: props.item.id } as any }));
|
248 |
|
|
}
|
249 |
2135f53d
|
Fantič
|
}
|
250 |
56626a63
|
Fantič
|
},
|
251 |
|
|
[props.item.id]
|
252 |
|
|
);
|
253 |
2135f53d
|
Fantič
|
|
254 |
d3c12593
|
Fantič
|
return (
|
255 |
|
|
|
256 |
|
|
props.notesLoading ?
|
257 |
|
|
(<LoadingBox text="Notes loading..." />)
|
258 |
|
|
:
|
259 |
9814562f
|
Fantič
|
(<VStack>
|
260 |
|
|
<Flex direction="row" align="flex-start" justifyContent="space-between" marginTop={2.5} marginLeft={2.5} marginRight={2.5}>
|
261 |
b56c1e7d
|
Fantič
|
<Text fontWeight="semibold" mt={4} ml={2} fontSize="md" color="#4D4D4D">Show related comments</Text>
|
262 |
ca637f52
|
Fantič
|
<Switch value={showRelatedComments} onChange={toggleRelatedComments} size="lg" marginRight={2} />
|
263 |
d3c12593
|
Fantič
|
</Flex>
|
264 |
e0741b92
|
Fantič
|
<Box >
|
265 |
7e9d79f3
|
Fantič
|
<NotesListView height={Dimensions.get('window').height - 295} requestPending={requestPending} notes={props.notes} navigation={props.navigation} handleCreateComment={handleCreateItemComment} />
|
266 |
2135f53d
|
Fantič
|
</Box>
|
267 |
d3c12593
|
Fantič
|
</VStack>)
|
268 |
|
|
);
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
b88520f8
|
Fantič
|
const ItemView = (props: ItemDetailProps) => {
|
274 |
|
|
|
275 |
|
|
// item shown / note shown
|
276 |
|
|
const [itemShown, setItemShown] = React.useState(true);
|
277 |
|
|
|
278 |
72afb023
|
Fantič
|
const { itemLoading, notesLoading, navigation } = props;
|
279 |
852de08e
|
Fantič
|
|
280 |
b88520f8
|
Fantič
|
const handleItemClick = () => {
|
281 |
|
|
setItemShown(true);
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
const handleNotesClick = () => {
|
285 |
|
|
setItemShown(false);
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
return (
|
289 |
f4af30c8
|
Fantič
|
<Box>
|
290 |
2135f53d
|
Fantič
|
|
291 |
7e9d79f3
|
Fantič
|
<Box height={Dimensions.get('window').height - 145}>
|
292 |
2135f53d
|
Fantič
|
{itemShown ? (
|
293 |
f4af30c8
|
Fantič
|
<ItemDetail itemLoading={props.itemLoading} item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
294 |
2135f53d
|
Fantič
|
) : (
|
295 |
|
|
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
296 |
|
|
)}
|
297 |
|
|
</Box>
|
298 |
|
|
|
299 |
852de08e
|
Fantič
|
{/* item notes switch tab */}
|
300 |
|
|
<HStack alignItems="center">
|
301 |
091dec61
|
Fantič
|
<Button
|
302 |
f4af30c8
|
Fantič
|
variant={"unstyled"}
|
303 |
852de08e
|
Fantič
|
w="50%"
|
304 |
b88520f8
|
Fantič
|
onPress={handleItemClick}
|
305 |
|
|
>
|
306 |
f4af30c8
|
Fantič
|
<VStack alignItems={"center"}>
|
307 |
ca637f52
|
Fantič
|
<Text fontSize="md" color="primary" bold={itemShown} mb={itemShown ? undefined : 2}>
|
308 |
7e9d79f3
|
Fantič
|
Detail
|
309 |
f4af30c8
|
Fantič
|
</Text>
|
310 |
ca637f52
|
Fantič
|
{itemShown && <Divider borderRadius={5} borderWidth={1} width={70} mt={1.5} color="primary" />}
|
311 |
f4af30c8
|
Fantič
|
</VStack>
|
312 |
b88520f8
|
Fantič
|
</Button>
|
313 |
091dec61
|
Fantič
|
<Button
|
314 |
f4af30c8
|
Fantič
|
variant={"unstyled"}
|
315 |
852de08e
|
Fantič
|
w="50%"
|
316 |
b88520f8
|
Fantič
|
onPress={handleNotesClick}
|
317 |
|
|
>
|
318 |
f4af30c8
|
Fantič
|
<VStack alignItems={"center"}>
|
319 |
ca637f52
|
Fantič
|
<Text fontSize="md" color="primary" bold={!itemShown} mb={!itemShown ? undefined : 2}>
|
320 |
f4af30c8
|
Fantič
|
Notes
|
321 |
|
|
</Text>
|
322 |
ca637f52
|
Fantič
|
{!itemShown && <Divider borderRadius={5} borderWidth={1} width={70} mt={1.5} color="primary" />}
|
323 |
f4af30c8
|
Fantič
|
</VStack>
|
324 |
b88520f8
|
Fantič
|
</Button>
|
325 |
|
|
</HStack>
|
326 |
852de08e
|
Fantič
|
</Box>
|
327 |
b88520f8
|
Fantič
|
)
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
export default ItemView
|