Projekt

Obecné

Profil

Stáhnout (3.19 KB) Statistiky
| Větev: | Tag: | Revize:
1 852de08e Fantič
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer } from "native-base"
2
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 b88520f8 Fantič
7
interface ItemDetailProps {
8
    item: Item,
9 852de08e Fantič
    itemLoading: boolean,
10
    notes: Note[],
11
    notesLoading: boolean
12 b88520f8 Fantič
}
13
14
15
const ItemDetail = (props: { item: Item }) => {
16
    const item = props.item;
17 852de08e Fantič
18 b88520f8 Fantič
    return (
19 852de08e Fantič
        <View alignItems="center" flex="1" justifyContent="center">
20 b88520f8 Fantič
            {
21
                item && (
22 852de08e Fantič
                    <ScrollView>
23
                        <VStack>
24
                            <Text>id: {item.id}</Text>
25
                            <Text>name: {item.workName}</Text>
26
                            {
27
                                item.fullView && item.imageUrl && (
28
                                    <Image size={250} alt="image" source={{ uri: `http:147.228.173.159/static/images/${item.imageUrl}` }} />
29
                                )
30
                            }
31
                        </VStack>
32
                    </ScrollView>
33
34 b88520f8 Fantič
                )
35
            }
36 852de08e Fantič
        </View>
37 b88520f8 Fantič
    );
38
}
39
40
const ItemNotes = (props: { notes: Note[] }) => {
41
    const notes = props.notes;
42
    return (
43
        <Center>
44
            {
45
                notes && notes.length > 0 ? (
46
                    <VStack>
47
                        {notes.map((note, index) => (
48
                            <Box key={index}>
49
                                <Text>{note.username}</Text>
50
                                <Text>{note.note}</Text>
51
                            </Box>
52
                        ))}
53
                    </VStack>
54
                ) : (
55
                    <Text>There are no notes for selected item.</Text>
56
                )
57
            }
58
        </Center>
59
    );
60
}
61
62
63
const ItemView = (props: ItemDetailProps) => {
64
65
    // item shown / note shown
66
    const [itemShown, setItemShown] = React.useState(true);
67
68 852de08e Fantič
    const {itemLoading, notesLoading} = props;
69
70 b88520f8 Fantič
    const handleItemClick = () => {
71
        setItemShown(true);
72
    }
73
74
    const handleNotesClick = () => {
75
        setItemShown(false);
76
    }
77
78
    return (
79 852de08e Fantič
        <Box display="flex" flex={1} flexDirection="column" justifyContent="space-between">
80 b88520f8 Fantič
            {itemShown ? (
81 852de08e Fantič
                itemLoading ? 
82
                <LoadingBox text="Item loading"/>
83
                :
84 b88520f8 Fantič
                <ItemDetail item={props.item} />
85
            ) : (
86 852de08e Fantič
                notesLoading ? 
87
                <LoadingBox text="Notes loading"/>
88
                :
89 b88520f8 Fantič
                <ItemNotes notes={props.notes} />
90
            )}
91 852de08e Fantič
92
            {/* item notes switch tab */}
93
            <HStack alignItems="center">
94
                <Button 
95
                    variant={itemShown ? "subtle" : "outline"}
96
                    w="50%"
97 b88520f8 Fantič
                    onPress={handleItemClick}
98
                >
99
                    Item
100
                </Button>
101 852de08e Fantič
                <Button 
102
                    variant={itemShown ? "outline" : "subtle"}
103
                    w="50%"
104 b88520f8 Fantič
                    onPress={handleNotesClick}
105
                >
106
                    Notes
107
                </Button>
108
            </HStack>
109 852de08e Fantič
        </Box>
110 b88520f8 Fantič
    )
111
}
112
113
export default ItemView