Projekt

Obecné

Profil

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