1 |
fedb75d6
|
Fantič
|
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer, Row } from "native-base"
|
2 |
7c4cd2cd
|
Fantič
|
import React, { useState, useEffect } from "react"
|
3 |
97deff21
|
Fantič
|
import { useDispatch, useSelector } from "react-redux"
|
4 |
fedb75d6
|
Fantič
|
import { AppDispatch, RootState } from "../stores/store"
|
5 |
88d2df9a
|
Fantič
|
import { getItem, getItemNotes, setConcordances, setSelectedConcordance } from "../stores/actions/itemThunks"
|
6 |
a7264b57
|
Fantič
|
import { Item, ItemViewState } from "../types/item"
|
7 |
7c4cd2cd
|
Fantič
|
import { login } from "../stores/actions/userThunks"
|
8 |
97deff21
|
Fantič
|
|
9 |
|
|
interface ItemViewProps {
|
10 |
|
|
itemId: string
|
11 |
b5599ba1
|
Fantič
|
}
|
12 |
|
|
|
13 |
97deff21
|
Fantič
|
const ItemViewPage = (props: ItemViewProps) => {
|
14 |
|
|
|
15 |
|
|
const dispatch = useDispatch<AppDispatch>();
|
16 |
|
|
|
17 |
88d2df9a
|
Fantič
|
const { item, notes, concordances, selectedConcordance } = useSelector((state: RootState) => state.itemViewState)
|
18 |
97deff21
|
Fantič
|
|
19 |
|
|
const handleGetPreviousConcordance = async () => {
|
20 |
c03fd43c
|
Fantič
|
if (selectedConcordance - 1 >= 0) {
|
21 |
|
|
dispatch(setSelectedConcordance(selectedConcordance - 1));
|
22 |
|
|
dispatch(getItem(concordances[selectedConcordance].id));
|
23 |
|
|
}
|
24 |
97deff21
|
Fantič
|
};
|
25 |
|
|
|
26 |
|
|
const handleGetNextConcordance = async () => {
|
27 |
c03fd43c
|
Fantič
|
if (selectedConcordance + 1 < concordances.length) {
|
28 |
|
|
dispatch(setSelectedConcordance(selectedConcordance + 1))
|
29 |
|
|
dispatch(getItem(concordances[selectedConcordance].id));
|
30 |
|
|
}
|
31 |
97deff21
|
Fantič
|
};
|
32 |
|
|
|
33 |
88d2df9a
|
Fantič
|
// load main item
|
34 |
fedb75d6
|
Fantič
|
useEffect(() => {
|
35 |
|
|
// TODO remove login from here
|
36 |
7c4cd2cd
|
Fantič
|
dispatch(login({ username: "Viktorie", password: "Golem123." }));
|
37 |
|
|
dispatch(getItem(props.itemId));
|
38 |
|
|
}, []);
|
39 |
97deff21
|
Fantič
|
|
40 |
88d2df9a
|
Fantič
|
// item changes
|
41 |
|
|
useEffect(() => {
|
42 |
|
|
|
43 |
|
|
if (selectedConcordance == 0) {
|
44 |
|
|
dispatch(setConcordances(item.concordances));
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// set item notes if item is loaded
|
48 |
|
|
if(item.id){
|
49 |
|
|
dispatch(getItemNotes(item.id));
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
}, [item]);
|
53 |
|
|
|
54 |
|
|
console.log(notes);
|
55 |
97deff21
|
Fantič
|
|
56 |
|
|
return (
|
57 |
|
|
<VStack>
|
58 |
|
|
<Center>
|
59 |
88d2df9a
|
Fantič
|
{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 |
fedb75d6
|
Fantič
|
|
80 |
97deff21
|
Fantič
|
<Divider my="2" />
|
81 |
|
|
</Center>
|
82 |
|
|
</VStack>
|
83 |
|
|
);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
7c4cd2cd
|
Fantič
|
export default ItemViewPage;
|