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