Projekt

Obecné

Profil

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