Projekt

Obecné

Profil

Stáhnout (16.9 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 f4af30c8 Fantič
                                        <Image size={Dimensions.get('window').width - 110} alt="image" source={{ uri: IMAGE_URL + "/" + item.images[selectedImage].imageUrl }} />
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
                                                />
126
                                            </Pressable>
127
128
                                        ))}
129
                                    </ScrollView>
130 e0741b92 Fantič
                                </VStack>
131
                            )}
132 2135f53d Fantič
                            {item.fullView && (
133 f4af30c8 Fantič
                                <View marginTop={5} backgroundColor="#F5F4F1" borderRadius={10} borderColor="#F5F4F1" padding={2} marginBottom={5}>
134 2135f53d Fantič
                                    {item.authorName &&
135
                                        <HStack>
136 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
137
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Author name: </Text>
138 fb120216 Fantič
                                                {item.images?.[selectedImage]?.author}
139 2135f53d Fantič
                                            </Text>
140
                                        </HStack>}
141
                                    {item.title &&
142
                                        <HStack>
143 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
144
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Title: </Text>
145 fb120216 Fantič
                                                {item.images?.[selectedImage].title}
146 2135f53d Fantič
                                            </Text>
147
                                        </HStack>}
148
                                    {item.institution &&
149
                                        <HStack>
150 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
151
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Institution: </Text>
152 fb120216 Fantič
                                                {item.images?.[selectedImage].institution.name && `${item.images?.[selectedImage].institution.name}`}
153
                                                {item.images?.[selectedImage].institution.inventoryNumber && `, Inv. No. ${item.images?.[selectedImage].institution.inventoryNumber}`}
154
                                                {item.images?.[selectedImage].institution.city && `, ${item.images?.[selectedImage].institution.city}`}
155
                                                {item.images?.[selectedImage].institution.country && ` (${item.images?.[selectedImage].institution.country})`}
156 2135f53d Fantič
                                            </Text>
157
                                        </HStack>}
158
                                    {item.repository &&
159
                                        <HStack>
160 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
161
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Repository: </Text>
162 fb120216 Fantič
                                                {item.images?.[selectedImage].repository}
163 2135f53d Fantič
                                            </Text>
164
                                        </HStack>}
165 fb120216 Fantič
                                    {item.images?.[selectedImage].provenance &&
166 2135f53d Fantič
                                        <HStack>
167 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
168
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Provenance: </Text>
169 fb120216 Fantič
                                                {item.images?.[selectedImage].provenance}
170 2135f53d Fantič
                                            </Text>
171
                                        </HStack>}
172 fb120216 Fantič
                                    {item.images?.[selectedImage].description &&
173 2135f53d Fantič
                                        <HStack>
174 f4af30c8 Fantič
                                            <Text marginTop={2.5}>
175
                                                <Text color="#654B07" italic fontWeight={"semibold"}>Description: </Text>
176 fb120216 Fantič
                                                {item.images?.[selectedImage].description}
177 2135f53d Fantič
                                            </Text>
178
                                        </HStack>}
179 f4af30c8 Fantič
                                </View>)}
180
181
                            {
182
                                item.room && item.room.id &&
183
                                <Flex direction="row" alignItems="center" justify="flex-end">
184
                                    <Button
185
                                        onPress={() => props.navigation.navigate("Plan", { roomId: item?.room?.id, placeId: undefined })}
186
                                        variant={"link"}
187
                                        backgroundColor={"#F4DFAB"}
188
                                        borderRadius={7}
189
                                        marginTop={0}
190
                                        marginBottom={5}
191
                                        width={125}
192
                                        rightIcon={<ChevronRightIcon size="xs" />}>
193
                                        Show in map
194
                                    </Button>
195
                                </Flex>
196
197
                            }
198
199 2135f53d Fantič
                        </VStack>
200 f4af30c8 Fantič
                    </ScrollView >
201 d3c12593 Fantič
                )
202 72afb023 Fantič
        }</>
203 b88520f8 Fantič
    );
204
}
205
206
207
208 a62d7c92 Michal Schwob
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined> }) => {
209 d3c12593 Fantič
210
    const [showRelatedComments, setShowRelatedComments] = useState(true);
211
212 1853180f Fantič
    const { requestPending, triggerRefresh } = useSelector((state: RootState) => state.noteViewState)
213 2135f53d Fantič
214 d3c12593 Fantič
    const dispatch = useDispatch<AppDispatch>();
215
216 1853180f Fantič
    // trigger refresh on triggerRefresh increment
217
    useEffect(() => {
218 e0741b92 Fantič
        if (triggerRefresh > 0) {
219 1853180f Fantič
            log.debug("NotesViewPage", "useEffect", "getNotes");
220
            dispatch(getItemNotes({ item: props.item, relatedComments: showRelatedComments }));
221
        }
222
    }, [triggerRefresh])
223 f4af30c8 Fantič
224 8ff3394e Fantič
    const toggleRelatedComments = useCallback(() => {
225 d3c12593 Fantič
        if (!props.notesLoading) {
226
227
            let value = !showRelatedComments;
228
229
            setShowRelatedComments(value);
230
            dispatch(getItemNotes({ item: props.item, relatedComments: value }));
231
        }
232 f4af30c8 Fantič
    }, [showRelatedComments]);
233 8ff3394e Fantič
234 d3c12593 Fantič
235 56626a63 Fantič
    const handleCreateItemComment = useCallback(
236
        (newComment: string, replyingTo: { messageId: string; userName: string } | null) => {
237
            if (!requestPending) {
238
                // creating new comment
239
                if (replyingTo != null) {
240
                    dispatch(createNote({ newNote: { note: newComment, reply_to: replyingTo.messageId } as Note }));
241
                } else {
242
                    dispatch(createNote({ newNote: { note: newComment, items: props.item.id } as any }));
243
                }
244 2135f53d Fantič
            }
245 56626a63 Fantič
        },
246
        [props.item.id]
247
    );
248 2135f53d Fantič
249 d3c12593 Fantič
    return (
250
251
        props.notesLoading ?
252
            (<LoadingBox text="Notes loading..." />)
253
            :
254 9814562f Fantič
            (<VStack>
255
                <Flex direction="row" align="flex-start" justifyContent="space-between" marginTop={2.5} marginLeft={2.5} marginRight={2.5}>
256 ca637f52 Fantič
                    <Text fontWeight="semibold" mt={4} ml={2} fontSize="md" color="4D4D4D">Show related comments</Text>
257
                    <Switch value={showRelatedComments} onChange={toggleRelatedComments} size="lg" marginRight={2} />
258 d3c12593 Fantič
                </Flex>
259 e0741b92 Fantič
                <Box >
260 ca637f52 Fantič
                    <NotesListView height={Dimensions.get('window').height - 315} requestPending={requestPending} notes={props.notes} navigation={props.navigation} handleCreateComment={handleCreateItemComment} />
261 2135f53d Fantič
                </Box>
262 d3c12593 Fantič
            </VStack>)
263
    );
264
}
265
266
267
268 b88520f8 Fantič
const ItemView = (props: ItemDetailProps) => {
269
270
    // item shown / note shown
271
    const [itemShown, setItemShown] = React.useState(true);
272
273 72afb023 Fantič
    const { itemLoading, notesLoading, navigation } = props;
274 852de08e Fantič
275 b88520f8 Fantič
    const handleItemClick = () => {
276
        setItemShown(true);
277
    }
278
279
    const handleNotesClick = () => {
280
        setItemShown(false);
281
    }
282
283
    return (
284 f4af30c8 Fantič
        <Box>
285 2135f53d Fantič
286 ca637f52 Fantič
            <Box height={Dimensions.get('window').height - 165}>
287 2135f53d Fantič
                {itemShown ? (
288 f4af30c8 Fantič
                    <ItemDetail itemLoading={props.itemLoading} item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
289 2135f53d Fantič
                ) : (
290
                    <ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
291
                )}
292
            </Box>
293
294 852de08e Fantič
            {/* item notes switch tab */}
295
            <HStack alignItems="center">
296 091dec61 Fantič
                <Button
297 f4af30c8 Fantič
                    variant={"unstyled"}
298 852de08e Fantič
                    w="50%"
299 b88520f8 Fantič
                    onPress={handleItemClick}
300
                >
301 f4af30c8 Fantič
                    <VStack alignItems={"center"}>
302 ca637f52 Fantič
                        <Text fontSize="md" color="primary" bold={itemShown} mb={itemShown ? undefined : 2}>
303 f4af30c8 Fantič
                            Item
304
                        </Text>
305 ca637f52 Fantič
                        {itemShown && <Divider borderRadius={5} borderWidth={1} width={70} mt={1.5} color="primary" />}
306 f4af30c8 Fantič
                    </VStack>
307 b88520f8 Fantič
                </Button>
308 091dec61 Fantič
                <Button
309 f4af30c8 Fantič
                    variant={"unstyled"}
310 852de08e Fantič
                    w="50%"
311 b88520f8 Fantič
                    onPress={handleNotesClick}
312
                >
313 f4af30c8 Fantič
                    <VStack alignItems={"center"}>
314 ca637f52 Fantič
                        <Text fontSize="md" color="primary" bold={!itemShown} mb={!itemShown ? undefined : 2}>
315 f4af30c8 Fantič
                            Notes
316
                        </Text>
317 ca637f52 Fantič
                        {!itemShown && <Divider borderRadius={5} borderWidth={1} width={70} mt={1.5} color="primary" />}
318 f4af30c8 Fantič
                    </VStack>
319 b88520f8 Fantič
                </Button>
320
            </HStack>
321 852de08e Fantič
        </Box>
322 b88520f8 Fantič
    )
323
}
324
325
export default ItemView