1
|
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
|
import { Item } 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 { getAllNotes } from "../../stores/actions/notesThunks"
|
10
|
import { AppDispatch } from "../../stores/store"
|
11
|
import { useDispatch } from "react-redux"
|
12
|
import { getItemNotes } from "../../stores/actions/itemThunks"
|
13
|
|
14
|
interface ItemDetailProps {
|
15
|
item: Item,
|
16
|
itemLoading: boolean,
|
17
|
notes: Note[],
|
18
|
notesLoading: boolean,
|
19
|
navigation: any
|
20
|
}
|
21
|
|
22
|
const ItemDetail = (props: { item: Item, itemLoading: boolean }) => {
|
23
|
const item = props.item;
|
24
|
|
25
|
return (<>
|
26
|
{
|
27
|
|
28
|
item && props.itemLoading ?
|
29
|
(<LoadingBox text="Item loading..." />)
|
30
|
:
|
31
|
(
|
32
|
<VStack>
|
33
|
<HStack marginTop="5%">
|
34
|
<VStack width="75%">
|
35
|
<Text>
|
36
|
{item.authorDisplayName ? item.authorDisplayName : item.authorName}
|
37
|
</Text>
|
38
|
<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
|
</Text>
|
56
|
<Text italic marginTop="2.5%">
|
57
|
{item.searchSubjects.map((subject, index) => (
|
58
|
index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
|
59
|
))}
|
60
|
</Text>
|
61
|
</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
|
)
|
115
|
}</>
|
116
|
);
|
117
|
}
|
118
|
|
119
|
|
120
|
|
121
|
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: any }) => {
|
122
|
|
123
|
const [showRelatedComments, setShowRelatedComments] = useState(true);
|
124
|
|
125
|
const dispatch = useDispatch<AppDispatch>();
|
126
|
|
127
|
const toggleRelatedComments = () => {
|
128
|
if (!props.notesLoading) {
|
129
|
|
130
|
let value = !showRelatedComments;
|
131
|
|
132
|
setShowRelatedComments(value);
|
133
|
dispatch(getItemNotes({ item: props.item, relatedComments: value }));
|
134
|
}
|
135
|
}
|
136
|
|
137
|
return (
|
138
|
|
139
|
props.notesLoading ?
|
140
|
(<LoadingBox text="Notes loading..." />)
|
141
|
:
|
142
|
(<VStack>
|
143
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
144
|
<Text fontSize={"12"}>Show related comments</Text>
|
145
|
<Switch value={showRelatedComments} onChange={toggleRelatedComments} size="md" />
|
146
|
</Flex>
|
147
|
<NotesListView notes={props.notes} handleDelete={() => console.log("TODO handle delete")} handleEdit={() => console.log("TODO handle edit")} handleReply={() => console.log("TODO handle reply")} setConfirmDialog={() => { }} navigation={props.navigation} />
|
148
|
</VStack>)
|
149
|
);
|
150
|
}
|
151
|
|
152
|
|
153
|
|
154
|
const ItemView = (props: ItemDetailProps) => {
|
155
|
|
156
|
// item shown / note shown
|
157
|
const [itemShown, setItemShown] = React.useState(true);
|
158
|
|
159
|
const { itemLoading, notesLoading, navigation } = props;
|
160
|
|
161
|
const handleItemClick = () => {
|
162
|
setItemShown(true);
|
163
|
}
|
164
|
|
165
|
const handleNotesClick = () => {
|
166
|
setItemShown(false);
|
167
|
}
|
168
|
|
169
|
return (
|
170
|
<Box display="flex" flex={1} flexDirection="column" justifyContent="space-between">
|
171
|
<ScrollView flex="1">
|
172
|
<Box width="92%" marginLeft="5%">
|
173
|
{itemShown ? (
|
174
|
<ItemDetail itemLoading={itemLoading} item={props.item} />
|
175
|
) : (
|
176
|
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
177
|
)}
|
178
|
</Box>
|
179
|
</ScrollView>
|
180
|
|
181
|
|
182
|
{/* item notes switch tab */}
|
183
|
<HStack alignItems="center">
|
184
|
<Button
|
185
|
variant={itemShown ? "subtle" : "outline"}
|
186
|
w="50%"
|
187
|
onPress={handleItemClick}
|
188
|
>
|
189
|
Item
|
190
|
</Button>
|
191
|
<Button
|
192
|
variant={itemShown ? "outline" : "subtle"}
|
193
|
w="50%"
|
194
|
onPress={handleNotesClick}
|
195
|
>
|
196
|
Notes
|
197
|
</Button>
|
198
|
</HStack>
|
199
|
</Box>
|
200
|
)
|
201
|
}
|
202
|
|
203
|
export default ItemView
|