Projekt

Obecné

Profil

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