Projekt

Obecné

Profil

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