Projekt

Obecné

Profil

Stáhnout (6.81 KB) Statistiky
| Větev: | Tag: | Revize:
1 091dec61 Fantič
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading } from "native-base"
2 852de08e Fantič
import React from "react"
3 b88520f8 Fantič
import { Item } from "../../types/item"
4
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 b88520f8 Fantič
9
interface ItemDetailProps {
10
    item: Item,
11 852de08e Fantič
    itemLoading: boolean,
12
    notes: Note[],
13 72afb023 Fantič
    notesLoading: boolean,
14
    navigation: any
15 b88520f8 Fantič
}
16
17
const ItemDetail = (props: { item: Item }) => {
18
    const item = props.item;
19 852de08e Fantič
20 72afb023 Fantič
    return (<>
21
        {
22
            item && (
23
                <VStack>
24
                    <HStack marginTop="5%">
25
                        <VStack width="75%">
26
                            <Text>
27
                                {item.authorDisplayName ? item.authorDisplayName : item.authorName}
28
                            </Text>
29
                            <Heading size="sm">
30
                                {item.workName}
31
                            </Heading>
32 091dec61 Fantič
33 852de08e Fantič
                        </VStack>
34 72afb023 Fantič
                        <Box width="25%">
35
                            <Button variant="outline" size="md">
36
                                {item.concordances[0].id}
37
                            </Button>
38
                        </Box>
39
                    </HStack>
40
                    <Card shadow="1" marginTop="5%">
41
                        {item.inventoryItem &&
42
                            <VStack>
43
                                <Text italic>
44
                                    <Text color="light.500">Inventory item: </Text>
45
                                    {item.inventoryItem}
46
                                </Text>
47
                                <Text italic marginTop="2.5%">
48
                                    {item.searchSubjects.map((subject, index) => (
49
                                        index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
50
                                    ))}
51
                                </Text>
52
                            </VStack>}
53
                    </Card>
54
                    {item.fullView && item.imageUrl && (
55
                        <Center background="primary.100" marginTop="5%">
56
                            <Text>Resembling object</Text>
57
                            <Image size={250} alt="image" source={{ uri: IMAGE_URL + "/" + item.imageUrl }} />
58
                        </Center>)}
59
                    {item.fullView && (
60
                        <Card shadow="1" marginTop="5%" marginBottom="5%">
61
                            {item.authorName &&
62
                                <HStack>
63
                                    <Text italic marginTop="2.5%">
64
                                        <Text color="light.500">Author name: </Text>
65
                                        {item.authorName}
66
                                    </Text>
67
                                </HStack>}
68
                            {item.title &&
69
                                <HStack>
70
                                    <Text italic marginTop="2.5%">
71
                                        <Text color="light.500">Title: </Text>
72
                                        {item.title}
73
                                    </Text>
74
                                </HStack>}
75
                            {item.institution &&
76
                                <HStack>
77
                                    <Text italic marginTop="2.5%">
78
                                        <Text color="light.500">Institution: </Text>
79
                                        {item.institution.name}, Inv. No. {item.institution.inventoryNumber}, {item.institution.city} {"(" + item.institution.country + ")"}
80
                                    </Text>
81
                                </HStack>}
82
                            {item.repository &&
83
                                <HStack>
84
                                    <Text italic marginTop="2.5%">
85
                                        <Text color="light.500">Repository: </Text>
86
                                        {item.repository}
87
                                    </Text>
88
                                </HStack>}
89
                            {item.provenance &&
90
                                <HStack>
91
                                    <Text italic marginTop="2.5%">
92
                                        <Text color="light.500">Provenance: </Text>
93
                                        {item.provenance}
94
                                    </Text>
95
                                </HStack>}
96
                            {item.description &&
97
                                <HStack>
98
                                    <Text italic marginTop="2.5%">
99
                                        <Text color="light.500">Description: </Text>
100
                                        {item.description}
101
                                    </Text>
102
                                </HStack>}
103
                        </Card>)}
104
                </VStack>
105
            )
106
        }</>
107 b88520f8 Fantič
    );
108
}
109
110
111
112
const ItemView = (props: ItemDetailProps) => {
113
114
    // item shown / note shown
115
    const [itemShown, setItemShown] = React.useState(true);
116
117 72afb023 Fantič
    const { itemLoading, notesLoading, navigation } = props;
118 852de08e Fantič
119 b88520f8 Fantič
    const handleItemClick = () => {
120
        setItemShown(true);
121
    }
122
123
    const handleNotesClick = () => {
124
        setItemShown(false);
125
    }
126
127
    return (
128 852de08e Fantič
        <Box display="flex" flex={1} flexDirection="column" justifyContent="space-between">
129 72afb023 Fantič
            <ScrollView flex="1">
130
                <Box width="92%" marginLeft="5%">
131
                    {itemShown ? (
132
                        itemLoading ?
133
                            <LoadingBox text="Item loading" />
134
                            :
135
                            <ItemDetail item={props.item} />
136
                    ) : (
137
                        notesLoading ?
138
                            <LoadingBox text="Notes loading" />
139
                            :
140
                            <NotesListView notes={props.notes} handleDelete={() => console.log("TODO handle delete")} handleEdit={() => console.log("TODO handle edit")} handleReply={() => console.log("TODO handle reply")} setConfirmDialog={() => { }} navigation={navigation} />
141
                    )}
142
                </Box>
143
            </ScrollView>
144
145 852de08e Fantič
146
            {/* item notes switch tab */}
147
            <HStack alignItems="center">
148 091dec61 Fantič
                <Button
149 852de08e Fantič
                    variant={itemShown ? "subtle" : "outline"}
150
                    w="50%"
151 b88520f8 Fantič
                    onPress={handleItemClick}
152
                >
153
                    Item
154
                </Button>
155 091dec61 Fantič
                <Button
156 852de08e Fantič
                    variant={itemShown ? "outline" : "subtle"}
157
                    w="50%"
158 b88520f8 Fantič
                    onPress={handleNotesClick}
159
                >
160
                    Notes
161
                </Button>
162
            </HStack>
163 852de08e Fantič
        </Box>
164 b88520f8 Fantič
    )
165
}
166
167
export default ItemView