Revize 7c4cd2cd
Přidáno uživatelem Fantič před téměř 2 roky(ů)
src/pages/ItemViewPage.tsx | ||
---|---|---|
1 | 1 |
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer } from "native-base" |
2 |
import React, { useState } from "react" |
|
2 |
import React, { useState, useEffect } from "react"
|
|
3 | 3 |
import { useDispatch, useSelector } from "react-redux" |
4 | 4 |
import { AppDispatch } from "../stores/store" |
5 | 5 |
import { getPreviousConcordance, getNextConcordance, getItem } from "../stores/actions/itemThunks" |
6 |
import { Item, ItemState } from "../stores/reducers/itemSlice" |
|
6 |
import { Item, ItemState } from "../types/item" |
|
7 |
import { login } from "../stores/actions/userThunks" |
|
7 | 8 | |
8 | 9 |
interface ItemViewProps { |
9 | 10 |
itemId: string |
... | ... | |
13 | 14 | |
14 | 15 |
const dispatch = useDispatch<AppDispatch>(); |
15 | 16 | |
16 |
const itemState = useSelector((state: ItemState) => state) |
|
17 | ||
18 |
useEffect(() => { |
|
19 |
dispatch(getItem(props.itemId)); |
|
20 |
}, []); |
|
17 |
const itemViewState = useSelector((itemState: ItemState) => itemState) |
|
21 | 18 | |
22 | 19 |
const handleGetPreviousConcordance = async () => { |
23 |
await dispatch(getPreviousConcordance());
|
|
20 |
dispatch(getPreviousConcordance()); |
|
24 | 21 |
}; |
25 | 22 | |
26 | 23 |
const handleGetNextConcordance = async () => { |
27 |
await dispatch(getNextConcordance());
|
|
24 |
dispatch(getNextConcordance()); |
|
28 | 25 |
}; |
29 | 26 | |
27 |
useEffect(() => { |
|
28 |
dispatch(login({ username: "Viktorie", password: "Golem123." })); |
|
29 |
dispatch(getItem(props.itemId)); |
|
30 |
}, []); |
|
30 | 31 | |
32 |
console.log(itemViewState.item); |
|
31 | 33 | |
32 | 34 |
return ( |
33 | 35 |
<VStack> |
... | ... | |
38 | 40 |
color="coolGray.800" |
39 | 41 |
_dark={{ color: "warmGrey.50" }} |
40 | 42 |
> |
41 |
{item.authorName} |
|
43 |
{itemViewState.item.authorName}
|
|
42 | 44 |
</Heading> |
43 | 45 | |
44 | 46 |
<Text fontSize="xl" mt="2"> |
45 |
{item.caption}
|
|
47 |
{itemViewState.item.workName}
|
|
46 | 48 |
</Text> |
47 | 49 | |
48 | 50 |
<HStack> |
... | ... | |
57 | 59 |
); |
58 | 60 |
} |
59 | 61 | |
60 |
export default ItemViewPage |
|
61 | ||
62 |
function useEffect(arg0: () => void, arg1: (string | (import("redux-thunk").ThunkDispatch<{ user: import("../stores/reducers/userSlice").UserState; item: import("../stores/reducers/itemSlice").ItemState }, undefined, import("redux").AnyAction> & import("redux").Dispatch<...>))[]) { |
|
63 |
throw new Error("Function not implemented.") |
|
64 |
} |
|
62 |
export default ItemViewPage; |
Také k dispozici: Unified diff
re #10454: ItemView: getting all required fields from api