1
|
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer } from "native-base"
|
2
|
import React from "react"
|
3
|
import { Item } from "../../types/item"
|
4
|
import { Note } from "../../types/note"
|
5
|
import LoadingBox from "../loading/LoadingBox"
|
6
|
|
7
|
interface ItemDetailProps {
|
8
|
item: Item,
|
9
|
itemLoading: boolean,
|
10
|
notes: Note[],
|
11
|
notesLoading: boolean
|
12
|
}
|
13
|
|
14
|
|
15
|
const ItemDetail = (props: { item: Item }) => {
|
16
|
const item = props.item;
|
17
|
|
18
|
return (
|
19
|
<View alignItems="center" flex="1" justifyContent="center">
|
20
|
{
|
21
|
item && (
|
22
|
<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
|
)
|
35
|
}
|
36
|
</View>
|
37
|
);
|
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
|
const {itemLoading, notesLoading} = props;
|
69
|
|
70
|
const handleItemClick = () => {
|
71
|
setItemShown(true);
|
72
|
}
|
73
|
|
74
|
const handleNotesClick = () => {
|
75
|
setItemShown(false);
|
76
|
}
|
77
|
|
78
|
return (
|
79
|
<Box display="flex" flex={1} flexDirection="column" justifyContent="space-between">
|
80
|
{itemShown ? (
|
81
|
itemLoading ?
|
82
|
<LoadingBox text="Item loading"/>
|
83
|
:
|
84
|
<ItemDetail item={props.item} />
|
85
|
) : (
|
86
|
notesLoading ?
|
87
|
<LoadingBox text="Notes loading"/>
|
88
|
:
|
89
|
<ItemNotes notes={props.notes} />
|
90
|
)}
|
91
|
|
92
|
{/* item notes switch tab */}
|
93
|
<HStack alignItems="center">
|
94
|
<Button
|
95
|
variant={itemShown ? "subtle" : "outline"}
|
96
|
w="50%"
|
97
|
onPress={handleItemClick}
|
98
|
>
|
99
|
Item
|
100
|
</Button>
|
101
|
<Button
|
102
|
variant={itemShown ? "outline" : "subtle"}
|
103
|
w="50%"
|
104
|
onPress={handleNotesClick}
|
105
|
>
|
106
|
Notes
|
107
|
</Button>
|
108
|
</HStack>
|
109
|
</Box>
|
110
|
)
|
111
|
}
|
112
|
|
113
|
export default ItemView
|