1 |
e0741b92
|
Fantič
|
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading, Switch, Flex, ChevronLeftIcon, ChevronRightIcon } from "native-base"
|
2 |
56626a63
|
Fantič
|
import React, { useCallback, 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 |
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 |
293f99f8
|
Fantič
|
|
18 |
b88520f8
|
Fantič
|
interface ItemDetailProps {
|
19 |
|
|
item: Item,
|
20 |
852de08e
|
Fantič
|
itemLoading: boolean,
|
21 |
|
|
notes: Note[],
|
22 |
72afb023
|
Fantič
|
notesLoading: boolean,
|
23 |
a62d7c92
|
Michal Schwob
|
navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined>
|
24 |
b88520f8
|
Fantič
|
}
|
25 |
|
|
|
26 |
d3c12593
|
Fantič
|
const ItemDetail = (props: { item: Item, itemLoading: boolean }) => {
|
27 |
b88520f8
|
Fantič
|
const item = props.item;
|
28 |
852de08e
|
Fantič
|
|
29 |
e0741b92
|
Fantič
|
const [selectedImage, setSelectedImage] = useState<number>(0);
|
30 |
|
|
|
31 |
72afb023
|
Fantič
|
return (<>
|
32 |
|
|
{
|
33 |
d3c12593
|
Fantič
|
item && props.itemLoading ?
|
34 |
|
|
(<LoadingBox text="Item loading..." />)
|
35 |
|
|
:
|
36 |
|
|
(
|
37 |
2135f53d
|
Fantič
|
<ScrollView flex="1">
|
38 |
|
|
<VStack>
|
39 |
e0741b92
|
Fantič
|
<HStack marginLeft={2.5} alignItems={"center"}>
|
40 |
|
|
<VStack flex={1} marginTop={3.5}>
|
41 |
2135f53d
|
Fantič
|
<Text>
|
42 |
|
|
{item.authorDisplayName ? item.authorDisplayName : item.authorName}
|
43 |
72afb023
|
Fantič
|
</Text>
|
44 |
2135f53d
|
Fantič
|
<Heading size="sm">
|
45 |
|
|
{item.workName}
|
46 |
|
|
</Heading>
|
47 |
|
|
</VStack>
|
48 |
e0741b92
|
Fantič
|
<Box marginLeft="auto" marginTop={0}> {/* marginLeft: "auto" pushes the Box to the right */}
|
49 |
2135f53d
|
Fantič
|
<Button variant="outline" size="md">
|
50 |
c1161e82
|
Fantič
|
{item?.concordances?.[0]?.id}
|
51 |
2135f53d
|
Fantič
|
</Button>
|
52 |
|
|
</Box>
|
53 |
|
|
</HStack>
|
54 |
e0741b92
|
Fantič
|
<Card shadow="1" marginTop={5}>
|
55 |
2135f53d
|
Fantič
|
{item.inventoryItem &&
|
56 |
|
|
<VStack>
|
57 |
|
|
<Text italic>
|
58 |
|
|
<Text color="light.500">Inventory item: </Text>
|
59 |
|
|
{item.inventoryItem}
|
60 |
d3c12593
|
Fantič
|
</Text>
|
61 |
|
|
<Text italic marginTop="2.5%">
|
62 |
c1161e82
|
Fantič
|
{item.searchSubjects != undefined && item?.searchSubjects?.map((subject, index) => (
|
63 |
|
|
item.searchSubjects && index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
|
64 |
2135f53d
|
Fantič
|
))}
|
65 |
d3c12593
|
Fantič
|
</Text>
|
66 |
2135f53d
|
Fantič
|
</VStack>}
|
67 |
|
|
</Card>
|
68 |
e0741b92
|
Fantič
|
{item.fullView && item.images && item.images.length > 0 && (
|
69 |
|
|
<VStack background="primary.100" marginTop={5} alignItems="center" justifyContent="center">
|
70 |
|
|
<Text marginBottom={2}>Resembling objects {selectedImage + 1 + "/" + item.images.length}</Text>
|
71 |
|
|
<HStack space={4}>
|
72 |
|
|
<Button variant="ghost" size="lg" onPress={() => {
|
73 |
|
|
if (item.images && selectedImage - 1 >= 0) {
|
74 |
|
|
setSelectedImage(selectedImage - 1);
|
75 |
|
|
}
|
76 |
|
|
}} leftIcon={<ChevronLeftIcon size="lg" />} />
|
77 |
|
|
<Image size={250} alt="image" source={{ uri: IMAGE_URL + "/" + item.images[selectedImage].imageUrl }} />
|
78 |
|
|
<Button variant="ghost" size="lg" onPress={() => {
|
79 |
|
|
if (item.images && selectedImage + 1 < item.images.length) {
|
80 |
|
|
setSelectedImage(selectedImage + 1);
|
81 |
|
|
}
|
82 |
|
|
}} leftIcon={<ChevronRightIcon size="lg" />} />
|
83 |
|
|
</HStack>
|
84 |
|
|
</VStack>
|
85 |
|
|
)}
|
86 |
2135f53d
|
Fantič
|
{item.fullView && (
|
87 |
e0741b92
|
Fantič
|
<Card shadow={1} marginTop={5} marginBottom={5}>
|
88 |
2135f53d
|
Fantič
|
{item.authorName &&
|
89 |
|
|
<HStack>
|
90 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
91 |
2135f53d
|
Fantič
|
<Text color="light.500">Author name: </Text>
|
92 |
|
|
{item.authorName}
|
93 |
|
|
</Text>
|
94 |
|
|
</HStack>}
|
95 |
|
|
{item.title &&
|
96 |
|
|
<HStack>
|
97 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
98 |
2135f53d
|
Fantič
|
<Text color="light.500">Title: </Text>
|
99 |
|
|
{item.title}
|
100 |
|
|
</Text>
|
101 |
|
|
</HStack>}
|
102 |
|
|
{item.institution &&
|
103 |
|
|
<HStack>
|
104 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
105 |
2135f53d
|
Fantič
|
<Text color="light.500">Institution: </Text>
|
106 |
|
|
{item.institution.name}, Inv. No. {item.institution.inventoryNumber}, {item.institution.city} {"(" + item.institution.country + ")"}
|
107 |
|
|
</Text>
|
108 |
|
|
</HStack>}
|
109 |
|
|
{item.repository &&
|
110 |
|
|
<HStack>
|
111 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
112 |
2135f53d
|
Fantič
|
<Text color="light.500">Repository: </Text>
|
113 |
|
|
{item.repository}
|
114 |
|
|
</Text>
|
115 |
|
|
</HStack>}
|
116 |
|
|
{item.provenance &&
|
117 |
|
|
<HStack>
|
118 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
119 |
2135f53d
|
Fantič
|
<Text color="light.500">Provenance: </Text>
|
120 |
|
|
{item.provenance}
|
121 |
|
|
</Text>
|
122 |
|
|
</HStack>}
|
123 |
|
|
{item.description &&
|
124 |
|
|
<HStack>
|
125 |
e0741b92
|
Fantič
|
<Text italic marginTop={2.5}>
|
126 |
2135f53d
|
Fantič
|
<Text color="light.500">Description: </Text>
|
127 |
|
|
{item.description}
|
128 |
|
|
</Text>
|
129 |
|
|
</HStack>}
|
130 |
|
|
</Card>)}
|
131 |
|
|
</VStack>
|
132 |
|
|
</ScrollView>
|
133 |
d3c12593
|
Fantič
|
)
|
134 |
72afb023
|
Fantič
|
}</>
|
135 |
b88520f8
|
Fantič
|
);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
a62d7c92
|
Michal Schwob
|
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined> }) => {
|
141 |
d3c12593
|
Fantič
|
|
142 |
|
|
const [showRelatedComments, setShowRelatedComments] = useState(true);
|
143 |
|
|
|
144 |
1853180f
|
Fantič
|
const { requestPending, triggerRefresh } = useSelector((state: RootState) => state.noteViewState)
|
145 |
2135f53d
|
Fantič
|
|
146 |
d3c12593
|
Fantič
|
const dispatch = useDispatch<AppDispatch>();
|
147 |
|
|
|
148 |
1853180f
|
Fantič
|
// trigger refresh on triggerRefresh increment
|
149 |
|
|
useEffect(() => {
|
150 |
e0741b92
|
Fantič
|
if (triggerRefresh > 0) {
|
151 |
1853180f
|
Fantič
|
log.debug("NotesViewPage", "useEffect", "getNotes");
|
152 |
|
|
dispatch(getItemNotes({ item: props.item, relatedComments: showRelatedComments }));
|
153 |
|
|
}
|
154 |
|
|
}, [triggerRefresh])
|
155 |
8ff3394e
|
Fantič
|
|
156 |
|
|
const toggleRelatedComments = useCallback(() => {
|
157 |
d3c12593
|
Fantič
|
if (!props.notesLoading) {
|
158 |
|
|
|
159 |
|
|
let value = !showRelatedComments;
|
160 |
|
|
|
161 |
|
|
setShowRelatedComments(value);
|
162 |
|
|
dispatch(getItemNotes({ item: props.item, relatedComments: value }));
|
163 |
|
|
}
|
164 |
8ff3394e
|
Fantič
|
}, [showRelatedComments]);
|
165 |
|
|
|
166 |
d3c12593
|
Fantič
|
|
167 |
56626a63
|
Fantič
|
const handleCreateItemComment = useCallback(
|
168 |
|
|
(newComment: string, replyingTo: { messageId: string; userName: string } | null) => {
|
169 |
|
|
if (!requestPending) {
|
170 |
|
|
// creating new comment
|
171 |
|
|
if (replyingTo != null) {
|
172 |
|
|
dispatch(createNote({ newNote: { note: newComment, reply_to: replyingTo.messageId } as Note }));
|
173 |
|
|
} else {
|
174 |
|
|
dispatch(createNote({ newNote: { note: newComment, items: props.item.id } as any }));
|
175 |
|
|
}
|
176 |
2135f53d
|
Fantič
|
}
|
177 |
56626a63
|
Fantič
|
},
|
178 |
|
|
[props.item.id]
|
179 |
|
|
);
|
180 |
2135f53d
|
Fantič
|
|
181 |
d3c12593
|
Fantič
|
return (
|
182 |
|
|
|
183 |
|
|
props.notesLoading ?
|
184 |
|
|
(<LoadingBox text="Notes loading..." />)
|
185 |
|
|
:
|
186 |
e0741b92
|
Fantič
|
(<VStack>
|
187 |
d3c12593
|
Fantič
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
188 |
|
|
<Text fontSize={"12"}>Show related comments</Text>
|
189 |
|
|
<Switch value={showRelatedComments} onChange={toggleRelatedComments} size="md" />
|
190 |
|
|
</Flex>
|
191 |
e0741b92
|
Fantič
|
<Box >
|
192 |
|
|
<NotesListView height={Dimensions.get('window').height - 355} requestPending={requestPending} notes={props.notes} navigation={props.navigation} handleCreateComment={handleCreateItemComment} />
|
193 |
2135f53d
|
Fantič
|
</Box>
|
194 |
d3c12593
|
Fantič
|
</VStack>)
|
195 |
|
|
);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
b88520f8
|
Fantič
|
const ItemView = (props: ItemDetailProps) => {
|
201 |
|
|
|
202 |
|
|
// item shown / note shown
|
203 |
|
|
const [itemShown, setItemShown] = React.useState(true);
|
204 |
|
|
|
205 |
72afb023
|
Fantič
|
const { itemLoading, notesLoading, navigation } = props;
|
206 |
852de08e
|
Fantič
|
|
207 |
b88520f8
|
Fantič
|
const handleItemClick = () => {
|
208 |
|
|
setItemShown(true);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
const handleNotesClick = () => {
|
212 |
|
|
setItemShown(false);
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
return (
|
216 |
e0741b92
|
Fantič
|
<Box marginLeft={2.5} marginRight={2.5}>
|
217 |
2135f53d
|
Fantič
|
|
218 |
e0741b92
|
Fantič
|
<Box height={Dimensions.get('window').height - 210}>
|
219 |
2135f53d
|
Fantič
|
{itemShown ? (
|
220 |
|
|
<ItemDetail itemLoading={itemLoading} item={props.item} />
|
221 |
|
|
) : (
|
222 |
|
|
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
223 |
|
|
)}
|
224 |
|
|
</Box>
|
225 |
|
|
|
226 |
852de08e
|
Fantič
|
{/* item notes switch tab */}
|
227 |
|
|
<HStack alignItems="center">
|
228 |
091dec61
|
Fantič
|
<Button
|
229 |
852de08e
|
Fantič
|
variant={itemShown ? "subtle" : "outline"}
|
230 |
|
|
w="50%"
|
231 |
b88520f8
|
Fantič
|
onPress={handleItemClick}
|
232 |
|
|
>
|
233 |
|
|
Item
|
234 |
|
|
</Button>
|
235 |
091dec61
|
Fantič
|
<Button
|
236 |
852de08e
|
Fantič
|
variant={itemShown ? "outline" : "subtle"}
|
237 |
|
|
w="50%"
|
238 |
b88520f8
|
Fantič
|
onPress={handleNotesClick}
|
239 |
|
|
>
|
240 |
|
|
Notes
|
241 |
|
|
</Button>
|
242 |
|
|
</HStack>
|
243 |
852de08e
|
Fantič
|
</Box>
|
244 |
b88520f8
|
Fantič
|
)
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
export default ItemView
|