Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d3c12593

Přidáno uživatelem Fantič před téměř 2 roky(ů)

re #10678 ItemViewUpdate: show related notes

Zobrazit rozdíly:

src/components/item/ItemView.tsx
1
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading } from "native-base"
2
import React from "react"
1
import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading, Switch, Flex } from "native-base"
2
import React, { useEffect, useState } from "react"
3 3
import { Item } from "../../types/item"
4 4
import { Note } from "../../types/note"
5 5
import LoadingBox from "../loading/LoadingBox"
6 6
import NotesListView from "../notes/NotesListView"
7 7
import { IMAGE_URL } from "../../api/constants"
8
import { log } from "../../logging/logger"
9
import { getAllNotes } from "../../stores/actions/notesThunks"
10
import { AppDispatch } from "../../stores/store"
11
import { useDispatch } from "react-redux"
12
import { getItemNotes } from "../../stores/actions/itemThunks"
8 13

  
9 14
interface ItemDetailProps {
10 15
    item: Item,
......
14 19
    navigation: any
15 20
}
16 21

  
17
const ItemDetail = (props: { item: Item }) => {
22
const ItemDetail = (props: { item: Item, itemLoading: boolean }) => {
18 23
    const item = props.item;
19 24

  
20 25
    return (<>
21 26
        {
22
            item && (
23
                <VStack>
24
                    <HStack marginTop="5%">
25
                        <VStack width="75%">
26
                            <Text>
27
                                {item.authorDisplayName ? item.authorDisplayName : item.authorName}
28
                            </Text>
29
                            <Heading size="sm">
30
                                {item.workName}
31
                            </Heading>
32

  
33
                        </VStack>
34
                        <Box width="25%">
35
                            <Button variant="outline" size="md">
36
                                {item.concordances[0].id}
37
                            </Button>
38
                        </Box>
39
                    </HStack>
40
                    <Card shadow="1" marginTop="5%">
41
                        {item.inventoryItem &&
42
                            <VStack>
43
                                <Text italic>
44
                                    <Text color="light.500">Inventory item: </Text>
45
                                    {item.inventoryItem}
46
                                </Text>
47
                                <Text italic marginTop="2.5%">
48
                                    {item.searchSubjects.map((subject, index) => (
49
                                        index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
50
                                    ))}
27

  
28
            item && props.itemLoading ?
29
                (<LoadingBox text="Item loading..." />)
30
                :
31
                (
32
                    <VStack>
33
                        <HStack marginTop="5%">
34
                            <VStack width="75%">
35
                                <Text>
36
                                    {item.authorDisplayName ? item.authorDisplayName : item.authorName}
51 37
                                </Text>
52
                            </VStack>}
53
                    </Card>
54
                    {item.fullView && item.imageUrl && (
55
                        <Center background="primary.100" marginTop="5%">
56
                            <Text>Resembling object</Text>
57
                            <Image size={250} alt="image" source={{ uri: IMAGE_URL + "/" + item.imageUrl }} />
58
                        </Center>)}
59
                    {item.fullView && (
60
                        <Card shadow="1" marginTop="5%" marginBottom="5%">
61
                            {item.authorName &&
62
                                <HStack>
63
                                    <Text italic marginTop="2.5%">
64
                                        <Text color="light.500">Author name: </Text>
65
                                        {item.authorName}
66
                                    </Text>
67
                                </HStack>}
68
                            {item.title &&
69
                                <HStack>
70
                                    <Text italic marginTop="2.5%">
71
                                        <Text color="light.500">Title: </Text>
72
                                        {item.title}
73
                                    </Text>
74
                                </HStack>}
75
                            {item.institution &&
76
                                <HStack>
77
                                    <Text italic marginTop="2.5%">
78
                                        <Text color="light.500">Institution: </Text>
79
                                        {item.institution.name}, Inv. No. {item.institution.inventoryNumber}, {item.institution.city} {"(" + item.institution.country + ")"}
80
                                    </Text>
81
                                </HStack>}
82
                            {item.repository &&
83
                                <HStack>
84
                                    <Text italic marginTop="2.5%">
85
                                        <Text color="light.500">Repository: </Text>
86
                                        {item.repository}
87
                                    </Text>
88
                                </HStack>}
89
                            {item.provenance &&
90
                                <HStack>
91
                                    <Text italic marginTop="2.5%">
92
                                        <Text color="light.500">Provenance: </Text>
93
                                        {item.provenance}
38
                                <Heading size="sm">
39
                                    {item.workName}
40
                                </Heading>
41

  
42
                            </VStack>
43
                            <Box width="25%">
44
                                <Button variant="outline" size="md">
45
                                    {item.concordances[0].id}
46
                                </Button>
47
                            </Box>
48
                        </HStack>
49
                        <Card shadow="1" marginTop="5%">
50
                            {item.inventoryItem &&
51
                                <VStack>
52
                                    <Text italic>
53
                                        <Text color="light.500">Inventory item: </Text>
54
                                        {item.inventoryItem}
94 55
                                    </Text>
95
                                </HStack>}
96
                            {item.description &&
97
                                <HStack>
98 56
                                    <Text italic marginTop="2.5%">
99
                                        <Text color="light.500">Description: </Text>
100
                                        {item.description}
57
                                        {item.searchSubjects.map((subject, index) => (
58
                                            index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject)
59
                                        ))}
101 60
                                    </Text>
102
                                </HStack>}
103
                        </Card>)}
104
                </VStack>
105
            )
61
                                </VStack>}
62
                        </Card>
63
                        {item.fullView && item.imageUrl && (
64
                            <Center background="primary.100" marginTop="5%">
65
                                <Text>Resembling object</Text>
66
                                <Image size={250} alt="image" source={{ uri: IMAGE_URL + "/" + item.imageUrl }} />
67
                            </Center>)}
68
                        {item.fullView && (
69
                            <Card shadow="1" marginTop="5%" marginBottom="5%">
70
                                {item.authorName &&
71
                                    <HStack>
72
                                        <Text italic marginTop="2.5%">
73
                                            <Text color="light.500">Author name: </Text>
74
                                            {item.authorName}
75
                                        </Text>
76
                                    </HStack>}
77
                                {item.title &&
78
                                    <HStack>
79
                                        <Text italic marginTop="2.5%">
80
                                            <Text color="light.500">Title: </Text>
81
                                            {item.title}
82
                                        </Text>
83
                                    </HStack>}
84
                                {item.institution &&
85
                                    <HStack>
86
                                        <Text italic marginTop="2.5%">
87
                                            <Text color="light.500">Institution: </Text>
88
                                            {item.institution.name}, Inv. No. {item.institution.inventoryNumber}, {item.institution.city} {"(" + item.institution.country + ")"}
89
                                        </Text>
90
                                    </HStack>}
91
                                {item.repository &&
92
                                    <HStack>
93
                                        <Text italic marginTop="2.5%">
94
                                            <Text color="light.500">Repository: </Text>
95
                                            {item.repository}
96
                                        </Text>
97
                                    </HStack>}
98
                                {item.provenance &&
99
                                    <HStack>
100
                                        <Text italic marginTop="2.5%">
101
                                            <Text color="light.500">Provenance: </Text>
102
                                            {item.provenance}
103
                                        </Text>
104
                                    </HStack>}
105
                                {item.description &&
106
                                    <HStack>
107
                                        <Text italic marginTop="2.5%">
108
                                            <Text color="light.500">Description: </Text>
109
                                            {item.description}
110
                                        </Text>
111
                                    </HStack>}
112
                            </Card>)}
113
                    </VStack>
114
                )
106 115
        }</>
107 116
    );
108 117
}
109 118

  
110 119

  
111 120

  
121
const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, navigation: any }) => {
122

  
123
    const [showRelatedComments, setShowRelatedComments] = useState(true);
124

  
125
    const dispatch = useDispatch<AppDispatch>();
126

  
127
    const toggleRelatedComments = () => {
128
        if (!props.notesLoading) {
129

  
130
            let value = !showRelatedComments;
131

  
132
            setShowRelatedComments(value);
133
            dispatch(getItemNotes({ item: props.item, relatedComments: value }));
134
        }
135
    }
136

  
137
    return (
138

  
139
        props.notesLoading ?
140
            (<LoadingBox text="Notes loading..." />)
141
            :
142
            (<VStack>
143
                <Flex direction="row" alignItems="center" justify="flex-end">
144
                    <Text fontSize={"12"}>Show related comments</Text>
145
                    <Switch value={showRelatedComments} onChange={toggleRelatedComments} size="md" />
146
                </Flex>
147
                <NotesListView notes={props.notes} handleDelete={() => console.log("TODO handle delete")} handleEdit={() => console.log("TODO handle edit")} handleReply={() => console.log("TODO handle reply")} setConfirmDialog={() => { }} navigation={props.navigation} />
148
            </VStack>)
149
    );
150
}
151

  
152

  
153

  
112 154
const ItemView = (props: ItemDetailProps) => {
113 155

  
114 156
    // item shown / note shown
......
129 171
            <ScrollView flex="1">
130 172
                <Box width="92%" marginLeft="5%">
131 173
                    {itemShown ? (
132
                        itemLoading ?
133
                            <LoadingBox text="Item loading" />
134
                            :
135
                            <ItemDetail item={props.item} />
174
                        <ItemDetail itemLoading={itemLoading} item={props.item} />
136 175
                    ) : (
137
                        notesLoading ?
138
                            <LoadingBox text="Notes loading" />
139
                            :
140
                            <NotesListView notes={props.notes} handleDelete={() => console.log("TODO handle delete")} handleEdit={() => console.log("TODO handle edit")} handleReply={() => console.log("TODO handle reply")} setConfirmDialog={() => { }} navigation={navigation} />
176
                        <ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
141 177
                    )}
142 178
                </Box>
143 179
            </ScrollView>

Také k dispozici: Unified diff