Revize 3a4bf532
Přidáno uživatelem Fantič před asi 2 roky(ů)
App.tsx | ||
---|---|---|
10 | 10 |
return ( |
11 | 11 |
<Provider store={store}> |
12 | 12 |
<NativeBaseProvider> |
13 |
<VStack space={4} alignItems="center"> |
|
14 | 13 |
{/* TODO: remove placeholder pro header / nav */} |
15 | 14 |
<Center w="100%" h="40" bg="primary.100" rounded="md" shadow={3} /> |
16 | 15 |
<ItemViewPage itemId={'PrgA-811'} /> |
17 |
</VStack> |
|
18 | 16 |
</NativeBaseProvider> |
19 | 17 |
</Provider> |
20 | 18 |
) |
src/components/item/ItemDetail.tsx | ||
---|---|---|
1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text } from "native-base" |
|
1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, Divider } from "native-base"
|
|
2 | 2 |
import React, { useState } from "react" |
3 |
import { Item } from "../../types/item" |
|
3 | 4 |
|
4 |
const ItemDetail = () => { |
|
5 |
interface ItemDetailProps { |
|
6 |
item: Item |
|
7 |
} |
|
8 |
|
|
9 |
|
|
10 |
const ItemView = (props: ItemDetailProps) => { |
|
11 |
const item = props.item; |
|
5 | 12 |
return ( |
6 |
<Center w="100%"> |
|
7 |
<Box> |
|
8 |
Item Detail :-) |
|
9 |
</Box> |
|
13 |
<Center> |
|
14 |
{item && ( |
|
15 |
<VStack> |
|
16 |
<Text> |
|
17 |
id: {item.id} |
|
18 |
</Text> |
|
19 |
<Text> |
|
20 |
name: {item.workName} |
|
21 |
</Text> |
|
22 |
</VStack> |
|
23 |
)} |
|
24 |
|
|
10 | 25 |
</Center> |
11 | 26 |
) |
12 | 27 |
} |
13 | 28 |
|
29 |
const ItemDetail = (props: ItemDetailProps) => { |
|
30 |
|
|
31 |
return ( |
|
32 |
<ItemView item={props.item}></ItemView> |
|
33 |
) |
|
34 |
} |
|
35 |
|
|
14 | 36 |
export default ItemDetail |
src/components/item/ItemNotes.tsx | ||
---|---|---|
1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text } from "native-base" |
|
2 |
import React, { useState } from "react" |
|
3 |
|
|
4 |
const ItemNotes = () => { |
|
5 |
return ( |
|
6 |
<Center w="100%"> |
|
7 |
<Box> |
|
8 |
Item notes :-) |
|
9 |
</Box> |
|
10 |
</Center> |
|
11 |
) |
|
12 |
} |
|
13 |
|
|
14 |
export default ItemNotes |
src/pages/ItemViewPage.tsx | ||
---|---|---|
1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer, Row } from "native-base" |
|
1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer, Row, View } from "native-base"
|
|
2 | 2 |
import React, { useState, useEffect } from "react" |
3 | 3 |
import { useDispatch, useSelector } from "react-redux" |
4 | 4 |
import { AppDispatch, RootState } from "../stores/store" |
5 | 5 |
import { getItem, getItemNotes, setConcordances, setSelectedConcordance } from "../stores/actions/itemThunks" |
6 | 6 |
import { Item, ItemViewState } from "../types/item" |
7 | 7 |
import { login } from "../stores/actions/userThunks" |
8 |
import { SceneRendererProps, TabView } from "react-native-tab-view" |
|
9 |
import { useWindowDimensions } from "react-native" |
|
10 |
import ItemDetail from "../components/item/ItemDetail" |
|
8 | 11 |
|
9 | 12 |
interface ItemViewProps { |
10 | 13 |
itemId: string |
... | ... | |
12 | 15 |
|
13 | 16 |
const ItemViewPage = (props: ItemViewProps) => { |
14 | 17 |
|
18 |
const layout = useWindowDimensions(); |
|
19 |
|
|
20 |
const [routes, setRoutes] = React.useState([ |
|
21 |
// initial tab |
|
22 |
{ key: 'loading', title: 'Loading item...' }, |
|
23 |
]); |
|
24 |
|
|
15 | 25 |
const dispatch = useDispatch<AppDispatch>(); |
16 | 26 |
|
17 | 27 |
const { item, notes, concordances, selectedConcordance } = useSelector((state: RootState) => state.itemViewState) |
18 | 28 |
|
19 |
const handleGetPreviousConcordance = async () => { |
|
20 |
if (selectedConcordance - 1 >= 0) { |
|
21 |
dispatch(setSelectedConcordance(selectedConcordance - 1)); |
|
22 |
dispatch(getItem(concordances[selectedConcordance].id)); |
|
23 |
} |
|
24 |
}; |
|
29 |
const [index, setIndex] = React.useState(0); |
|
25 | 30 |
|
26 |
const handleGetNextConcordance = async () => { |
|
27 |
if (selectedConcordance + 1 < concordances.length) { |
|
28 |
dispatch(setSelectedConcordance(selectedConcordance + 1)) |
|
29 |
dispatch(getItem(concordances[selectedConcordance].id)); |
|
30 |
} |
|
31 |
}; |
|
32 | 31 |
|
33 | 32 |
// load main item |
34 | 33 |
useEffect(() => { |
35 | 34 |
// TODO remove login from here |
36 | 35 |
dispatch(login({ username: "Viktorie", password: "Golem123." })); |
37 | 36 |
dispatch(getItem(props.itemId)); |
38 |
}, []); |
|
37 |
}, [props.itemId]); |
|
38 |
|
|
39 |
console.log(item.id); |
|
40 |
|
|
39 | 41 |
|
40 |
// item changes
|
|
42 |
// concordances changed
|
|
41 | 43 |
useEffect(() => { |
44 |
if (item && concordances && concordances.length > 0) { |
|
45 |
let concordanceRoutes = []; |
|
46 |
concordanceRoutes.push({ |
|
47 |
key: item.id, |
|
48 |
title: item.id |
|
49 |
}) |
|
42 | 50 |
|
43 |
if (selectedConcordance == 0) { |
|
44 |
dispatch(setConcordances(item.concordances)); |
|
51 |
for (let i = 0; i < concordances.length; i++) { |
|
52 |
let concordance = concordances[i]; |
|
53 |
concordanceRoutes.push({ |
|
54 |
key: concordance.id, |
|
55 |
title: concordance.id |
|
56 |
}) |
|
57 |
} |
|
58 |
setRoutes(concordanceRoutes); |
|
45 | 59 |
} |
60 |
}, [concordances]); |
|
46 | 61 |
|
47 |
// set item notes if item is loaded
|
|
48 |
if(item.id){
|
|
49 |
dispatch(getItemNotes(item.id));
|
|
50 |
}
|
|
62 |
// change tab
|
|
63 |
useEffect(() => {
|
|
64 |
dispatch(setSelectedConcordance(index));
|
|
65 |
}, [index]);
|
|
51 | 66 |
|
52 |
}, [item]); |
|
67 |
useEffect(() => { |
|
68 |
if (concordances && concordances.length > 0) { |
|
69 |
dispatch(getItem(concordances[selectedConcordance].id)); |
|
70 |
} |
|
71 |
}, [selectedConcordance]); |
|
53 | 72 |
|
54 |
console.log(notes); |
|
73 |
// item changes |
|
74 |
useEffect(() => { |
|
75 |
if (selectedConcordance == 0) { |
|
76 |
dispatch(setConcordances(item.concordances)); |
|
77 |
} |
|
78 |
|
|
79 |
// set item notes if item is loaded |
|
80 |
if (item && item.id) { |
|
81 |
dispatch(getItemNotes(item.id)); |
|
82 |
} |
|
83 |
|
|
84 |
}, [item]); |
|
55 | 85 |
|
56 | 86 |
return ( |
57 |
<VStack> |
|
58 |
<Center> |
|
59 |
{concordances && concordances.length > 0 && item && ( // concordances && item are loaded |
|
60 |
<VStack> |
|
61 |
<Text> |
|
62 |
Concordances: {concordances.map((concordance) => concordance.id).join(', ')} |
|
63 |
</Text> |
|
64 |
<Text> |
|
65 |
{/* Selected: {concordances[selectedConcordance].id} */} |
|
66 |
Selected: {concordances[selectedConcordance].id} |
|
67 |
</Text> |
|
68 |
<HStack> |
|
69 |
<Button onPress={handleGetPreviousConcordance} mr={2}> |
|
70 |
Previous Concordance |
|
71 |
</Button> |
|
72 |
<Button onPress={handleGetNextConcordance}>Next Concordance</Button> |
|
73 |
</HStack> |
|
74 |
<Text> |
|
75 |
current item: {item.workName} |
|
76 |
</Text> |
|
77 |
</VStack> |
|
78 |
)} |
|
79 |
|
|
80 |
<Divider my="2" /> |
|
81 |
</Center> |
|
82 |
</VStack> |
|
87 |
<TabView |
|
88 |
navigationState={{ index, routes }} |
|
89 |
renderScene={() => <ItemDetail item={item} />} |
|
90 |
onIndexChange={setIndex} |
|
91 |
initialLayout={{ width: layout.width }} |
|
92 |
/> |
|
93 |
|
|
94 |
|
|
83 | 95 |
); |
84 | 96 |
} |
85 | 97 |
|
86 |
export default ItemViewPage; |
|
98 |
export default ItemViewPage; |
src/stores/actions/itemThunks.ts | ||
---|---|---|
8 | 8 |
"item/getItem", |
9 | 9 |
async (itemId: string) => { |
10 | 10 |
try { |
11 |
|
|
12 |
console.log("¨GET item/getItem/" + itemId); |
|
11 |
console.log("GET item/getItem/" + itemId); |
|
13 | 12 |
|
14 | 13 |
const response = await getItemRequest(itemId); |
15 |
|
|
16 |
|
|
14 |
|
|
15 |
|
|
17 | 16 |
// data with image |
18 | 17 |
if (response.status === 200 && response.data.object.length > 1) { |
19 | 18 |
return { |
... | ... | |
128 | 127 |
noteColor: (note as any).note_color, |
129 | 128 |
}) |
130 | 129 |
} |
131 |
|
|
130 |
|
|
132 | 131 |
return { |
133 | 132 |
notes, |
134 | 133 |
} |
Také k dispozici: Unified diff
re #10454: ItemView: concordance tabs