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