Projekt

Obecné

Profil

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