Revize 2135f53d
Přidáno uživatelem Fantič před téměř 2 roky(ů)
src/components/item/ItemView.tsx | ||
---|---|---|
6 | 6 |
import NotesListView from "../notes/NotesListView" |
7 | 7 |
import { IMAGE_URL } from "../../api/constants" |
8 | 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" |
|
9 |
import { createNote, getAllNotes } from "../../stores/actions/notesThunks"
|
|
10 |
import { AppDispatch, RootState } from "../../stores/store"
|
|
11 |
import { useDispatch, useSelector } from "react-redux"
|
|
12 | 12 |
import { getItemNotes } from "../../stores/actions/itemThunks" |
13 | 13 |
|
14 | 14 |
interface ItemDetailProps { |
... | ... | |
24 | 24 |
|
25 | 25 |
return (<> |
26 | 26 |
{ |
27 |
|
|
28 | 27 |
item && props.itemLoading ? |
29 | 28 |
(<LoadingBox text="Item loading..." />) |
30 | 29 |
: |
31 | 30 |
( |
32 |
<VStack> |
|
33 |
<HStack marginTop="5%"> |
|
34 |
<VStack width="75%"> |
|
35 |
<Text> |
|
36 |
{item.authorDisplayName ? item.authorDisplayName : item.authorName} |
|
37 |
</Text> |
|
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} |
|
55 |
</Text> |
|
56 |
<Text italic marginTop="2.5%"> |
|
57 |
{item.searchSubjects.map((subject, index) => ( |
|
58 |
index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject) |
|
59 |
))} |
|
31 |
<ScrollView flex="1"> |
|
32 |
<VStack> |
|
33 |
<HStack marginTop="5%"> |
|
34 |
<VStack width="75%"> |
|
35 |
<Text> |
|
36 |
{item.authorDisplayName ? item.authorDisplayName : item.authorName} |
|
60 | 37 |
</Text> |
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} |
|
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} |
|
82 | 55 |
</Text> |
83 |
</HStack>} |
|
84 |
{item.institution && |
|
85 |
<HStack> |
|
86 | 56 |
<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 + ")"} |
|
57 |
{item.searchSubjects.map((subject, index) => ( |
|
58 |
index < item.searchSubjects.length - 1 ? (subject + ", ") : (subject) |
|
59 |
))} |
|
89 | 60 |
</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> |
|
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 |
</ScrollView> |
|
114 | 115 |
) |
115 | 116 |
}</> |
116 | 117 |
); |
... | ... | |
122 | 123 |
|
123 | 124 |
const [showRelatedComments, setShowRelatedComments] = useState(true); |
124 | 125 |
|
126 |
const { requestPending } = useSelector((state: RootState) => state.noteViewState) |
|
127 |
|
|
125 | 128 |
const dispatch = useDispatch<AppDispatch>(); |
126 | 129 |
|
127 | 130 |
const toggleRelatedComments = () => { |
... | ... | |
134 | 137 |
} |
135 | 138 |
} |
136 | 139 |
|
140 |
const handleCreateItemComment = (newComment: string, replyingTo: { messageId: string; userName: string } | null) => { |
|
141 |
if (!requestPending) { |
|
142 |
// creating new comment |
|
143 |
if (replyingTo != null) { |
|
144 |
dispatch(createNote({ |
|
145 |
newNote: { note: newComment, reply_to: replyingTo.messageId } as Note |
|
146 |
})) |
|
147 |
} |
|
148 |
else { |
|
149 |
dispatch(createNote({ |
|
150 |
newNote: { note: newComment, items: [props.item.id] } as Note |
|
151 |
})) |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
137 | 156 |
return ( |
138 | 157 |
|
139 | 158 |
props.notesLoading ? |
140 | 159 |
(<LoadingBox text="Notes loading..." />) |
141 | 160 |
: |
142 |
(<VStack> |
|
161 |
(<VStack height="90%">
|
|
143 | 162 |
<Flex direction="row" alignItems="center" justify="flex-end"> |
144 | 163 |
<Text fontSize={"12"}>Show related comments</Text> |
145 | 164 |
<Switch value={showRelatedComments} onChange={toggleRelatedComments} size="md" /> |
146 | 165 |
</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} /> |
|
166 |
<Box height="120%"> |
|
167 |
<NotesListView requestPending={requestPending} notes={props.notes} navigation={props.navigation} handleCreateComment={handleCreateItemComment} /> |
|
168 |
</Box> |
|
148 | 169 |
</VStack>) |
149 | 170 |
); |
150 | 171 |
} |
... | ... | |
168 | 189 |
|
169 | 190 |
return ( |
170 | 191 |
<Box display="flex" flex={1} flexDirection="column" justifyContent="space-between"> |
171 |
<ScrollView flex="1"> |
|
172 |
<Box width="92%" marginLeft="5%">
|
|
173 |
{itemShown ? (
|
|
174 |
<ItemDetail itemLoading={itemLoading} item={props.item} />
|
|
175 |
) : (
|
|
176 |
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} />
|
|
177 |
)}
|
|
178 |
</Box>
|
|
179 |
</ScrollView> |
|
192 |
|
|
193 |
<Box width="92%" marginLeft="5%" height="92%">
|
|
194 |
{itemShown ? ( |
|
195 |
<ItemDetail itemLoading={itemLoading} item={props.item} /> |
|
196 |
) : ( |
|
197 |
<ItemNotes item={props.item} notesLoading={props.notesLoading} notes={props.notes} navigation={props.navigation} /> |
|
198 |
)} |
|
199 |
</Box> |
|
200 |
|
|
180 | 201 |
|
181 | 202 |
|
182 | 203 |
{/* item notes switch tab */} |
Také k dispozici: Unified diff
re #10678: ItemNotes refactor NoteListView