Projekt

Obecné

Profil

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