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