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