Projekt

Obecné

Profil

« Předchozí | Další » 

Revize fedb75d6

Přidáno uživatelem Fantič před asi 2 roky(ů)

re #10454: ItemView: get itemViewState fix

Zobrazit rozdíly:

App.tsx
13 13
        <VStack space={4} alignItems="center">
14 14
          {/* TODO: remove placeholder pro navbar */}
15 15
          <Center w="100%" h="40" bg="indigo.300" rounded="md" shadow={3} />
16
          {/* <ItemViewPage itemId={'BxlA-2'} /> */}
17
          <ItemViewPage itemId={'BxlA-5'} />
16
          <ItemViewPage itemId={'BxlA-2'} />
17
          {/* <ItemViewPage itemId={'BxlA-5'} /> */}
18 18
        </VStack>
19 19
      </NativeBaseProvider>
20 20
    </Provider>
src/pages/ItemViewPage.tsx
1
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer } from "native-base"
1
import { Center, Box, Heading, VStack, FormControl, Link, Input, Button, HStack, Text, StatusBar, Container, Divider, Spacer, Row } from "native-base"
2 2
import React, { useState, useEffect } from "react"
3 3
import { useDispatch, useSelector } from "react-redux"
4
import { AppDispatch } from "../stores/store"
4
import { AppDispatch, RootState } from "../stores/store"
5 5
import { getPreviousConcordance, getNextConcordance, getItem } from "../stores/actions/itemThunks"
6 6
import { Item, ItemViewState } from "../types/item"
7 7
import { login } from "../stores/actions/userThunks"
......
14 14

  
15 15
  const dispatch = useDispatch<AppDispatch>();
16 16

  
17
  const itemViewState = useSelector((itemState: ItemViewState) => itemState)
17
  const {item, concordances, selectedConcordance} = useSelector((state: RootState) => state.itemViewState)
18 18

  
19 19
  const handleGetPreviousConcordance = async () => {
20 20
    dispatch(getPreviousConcordance());
......
24 24
    dispatch(getNextConcordance());
25 25
  };
26 26

  
27
  useEffect(() => { 
27
  useEffect(() => {
28
    // TODO remove login from here
28 29
    dispatch(login({ username: "Viktorie", password: "Golem123." }));
30

  
29 31
    dispatch(getItem(props.itemId));
30 32
  }, []);
31 33

  
32
  console.log(itemViewState.item)
34
  console.log(concordances);
35
  console.log(item);
33 36

  
34 37
  return (
35 38
    <VStack>
36 39
      <Center>
37
        <Heading
38
          size="lg"
39
          fontWeight="600"
40
          color="coolGray.800"
41
          _dark={{ color: "warmGrey.50" }}
42
        >
43
          {itemViewState.item.authorName}
44
        </Heading>
45

  
46
        <Text fontSize="xl" mt="2">
47
          {itemViewState.item.workName}
48
        </Text>
49

  
50
        <HStack>
51
          <Button onPress={handleGetPreviousConcordance} mr={2}>
52
            Previous Concordance
53
          </Button>
54
          <Button onPress={handleGetNextConcordance}>Next Concordance</Button>
55
        </HStack>
40

  
41

  
42

  
43
        <VStack>
44
          <Text>
45
            Concordances: {concordances.map((concordance) => concordance.id).join(', ')}
46
          </Text>
47
          <Text>
48
            Selected: {concordances[selectedConcordance].id} 
49
          </Text>
50
          <HStack>
51

  
52
            <Button onPress={handleGetPreviousConcordance} mr={2}>
53
              Previous Concordance
54
            </Button>
55
            <Button onPress={handleGetNextConcordance}>Next Concordance</Button>
56
          </HStack>
57
        </VStack>
58

  
56 59
        <Divider my="2" />
57 60
      </Center>
58 61
    </VStack>
src/stores/actions/itemThunks.ts
16 16

  
17 17
            // data with image
18 18
            if (response.status === 200 && response.data.object.length > 1) {
19
                
19 20
                return {
20 21
                    id: itemId,
21 22
                    fullView: true,
src/stores/reducers/itemSlice.ts
25 25
    },
26 26
    extraReducers: (builder) => {
27 27
        // getItem
28
        builder.addCase(getItem.fulfilled, (state, action) => { 
28
        builder.addCase(getItem.fulfilled, (state, action) => {
29 29

  
30
            state.item.id= action.payload.id;
31
            state.item.authorDisplayName= action.payload.authorDisplayName;
32
            state.item.workName= action.payload.workName;
33
            state.item.concordances= action.payload.concordances;
34
            state.item.searchSubjects= action.payload.searchSubjects;
35
            state.item.inventoryItem= action.payload.inventoryItem;
36
            state.item.fullView= action.payload.fullView;
37
        
38
            if (action.payload.fullView) {
39
                state.item.institution = action.payload.institution;
40
                state.item.authorName = action.payload.authorName;
41
                state.item.imageUrl = action.payload.imageUrl;
42
                state.item.title = action.payload.title;
43
                state.item.repository = action.payload.repository;
44
                state.item.provenance = action.payload.provenance;
45
                state.item.description = action.payload.description;
46
            }
47
            else{
48
                state.item.institution = undefined;
49
                state.item.authorName = undefined;
50
                state.item.imageUrl = undefined;
51
                state.item.title = undefined;
52
                state.item.repository = undefined;
53
                state.item.provenance = undefined;
54
                state.item.description = undefined;
55
            }
56
        
30 57
            // set concordances from item, if selected concordance is 0
31 58
            if (state.selectedConcordance === 0) {
59
                console.log("Tohle se vola!");
32 60
                state.concordances = action.payload.concordances;
33 61
            }
34 62

  
35
            state.item = {
36
                id: action.payload.id,
37
                authorDisplayName: action.payload.authorDisplayName,
38
                workName: action.payload.workName,
39
                concordances: action.payload.concordances,
40
                searchSubjects: action.payload.searchSubjects,
41
                inventoryItem: action.payload.inventoryItem,
42
                fullView: action.payload.fullView,
43
            } as Item
44

  
45
            if(action.payload.fullView){
46
                state.item = {
47
                    ...state.item,
48
                    // additional
49
                    institution: action.payload.institution,
50
                    authorName: action.payload.authorName,
51
                    imageUrl: action.payload.imageUrl,
52
                    title: action.payload.title,
53
                    repository: action.payload.repository,
54
                    provenance: action.payload.provenance,
55
                    description: action.payload.description
56
                }
57
            }
58 63
        })
59 64
        builder.addCase(getItem.rejected, (state, action) => {
60 65
            state.lastError = action.error.message
src/stores/store.ts
5 5
const store = configureStore({
6 6
    reducer: {
7 7
        user: userReducer,
8
        item: itemReducer
8
        itemViewState: itemReducer
9 9
    },
10 10
})
11 11

  

Také k dispozici: Unified diff