Revize 88d2df9a
Přidáno uživatelem Fantič před téměř 2 roky(ů)
App.tsx | ||
---|---|---|
13 | 13 |
<VStack space={4} alignItems="center"> |
14 | 14 |
{/* TODO: remove placeholder pro header / nav */} |
15 | 15 |
<Center w="100%" h="40" bg="primary.100" rounded="md" shadow={3} /> |
16 |
<ItemViewPage itemId={'BxlA-2'} /> |
|
17 |
{/* <ItemViewPage itemId={'BxlA-5'} /> */} |
|
16 |
<ItemViewPage itemId={'PrgA-811'} /> |
|
18 | 17 |
</VStack> |
19 | 18 |
</NativeBaseProvider> |
20 | 19 |
</Provider> |
src/pages/ItemViewPage.tsx | ||
---|---|---|
2 | 2 |
import React, { useState, useEffect } from "react" |
3 | 3 |
import { useDispatch, useSelector } from "react-redux" |
4 | 4 |
import { AppDispatch, RootState } from "../stores/store" |
5 |
import { getItem, setConcordances, setSelectedConcordance } from "../stores/actions/itemThunks" |
|
5 |
import { getItem, getItemNotes, setConcordances, setSelectedConcordance } from "../stores/actions/itemThunks"
|
|
6 | 6 |
import { Item, ItemViewState } from "../types/item" |
7 | 7 |
import { login } from "../stores/actions/userThunks" |
8 | 8 |
|
... | ... | |
14 | 14 |
|
15 | 15 |
const dispatch = useDispatch<AppDispatch>(); |
16 | 16 |
|
17 |
const { item, concordances, selectedConcordance } = useSelector((state: RootState) => state.itemViewState) |
|
17 |
const { item, notes, concordances, selectedConcordance } = useSelector((state: RootState) => state.itemViewState)
|
|
18 | 18 |
|
19 | 19 |
const handleGetPreviousConcordance = async () => { |
20 | 20 |
if (selectedConcordance - 1 >= 0) { |
... | ... | |
30 | 30 |
} |
31 | 31 |
}; |
32 | 32 |
|
33 |
// initialize with base item (set concordances from it)
|
|
33 |
// load main item
|
|
34 | 34 |
useEffect(() => { |
35 | 35 |
// TODO remove login from here |
36 | 36 |
dispatch(login({ username: "Viktorie", password: "Golem123." })); |
37 | 37 |
dispatch(getItem(props.itemId)); |
38 |
dispatch(setConcordances(item.concordances)); |
|
39 | 38 |
}, []); |
40 | 39 |
|
40 |
// 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); |
|
41 | 55 |
|
42 | 56 |
return ( |
43 | 57 |
<VStack> |
44 | 58 |
<Center> |
45 |
<VStack> |
|
46 |
<Text> |
|
47 |
Concordances: {concordances.map((concordance) => concordance.id).join(', ')} |
|
48 |
</Text> |
|
49 |
<Text> |
|
50 |
{/* Selected: {concordances[selectedConcordance].id} */} |
|
51 |
Selected: {selectedConcordance} |
|
52 |
</Text> |
|
53 |
<HStack> |
|
54 |
<Button onPress={handleGetPreviousConcordance} mr={2}> |
|
55 |
Previous Concordance |
|
56 |
</Button> |
|
57 |
<Button onPress={handleGetNextConcordance}>Next Concordance</Button> |
|
58 |
</HStack> |
|
59 |
<Text> |
|
60 |
current item: {item.workName} |
|
61 |
</Text> |
|
62 |
</VStack> |
|
59 |
{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 |
)} |
|
63 | 79 |
|
64 | 80 |
<Divider my="2" /> |
65 | 81 |
</Center> |
src/stores/actions/itemThunks.ts | ||
---|---|---|
11 | 11 |
|
12 | 12 |
console.log("¨GET item/getItem/" + itemId); |
13 | 13 |
|
14 |
const response = await getItemRequest(itemId) |
|
14 |
const response = await getItemRequest(itemId);
|
|
15 | 15 |
|
16 | 16 |
|
17 | 17 |
// data with image |
... | ... | |
57 | 57 |
inventoryItem: response.data.text, |
58 | 58 |
searchSubjects: response.data.search_subject, |
59 | 59 |
} |
60 |
} { |
|
60 |
} |
|
61 |
else { |
|
61 | 62 |
return Promise.reject(response.data ? response.data : "Error") |
62 | 63 |
} |
63 | 64 |
} catch (err: any) { |
... | ... | |
107 | 108 |
"item/getItemNotes", |
108 | 109 |
async (itemId: string) => { |
109 | 110 |
try { |
110 |
const response = await getItemNotesRequest(itemId) |
|
111 |
console.log(response) |
|
111 |
console.log("¨GET notes/getNotes/" + itemId); |
|
112 |
|
|
113 |
const response = await getItemNotesRequest(itemId); |
|
114 |
|
|
112 | 115 |
if (response.status === 200) { |
113 |
return { |
|
114 |
// TODO set item notes |
|
116 |
if(response.data.length > 0){ |
|
117 |
|
|
118 |
let notes = []; |
|
119 |
for(let i = 0; i < response.data.length; i++){ |
|
120 |
let note = response.data[i]; |
|
121 |
notes.push({ |
|
122 |
username: (note as any).created_by, |
|
123 |
userId: (note as any).created_by_id, |
|
124 |
avatarUrl: (note as any).avatar, |
|
125 |
items: (note as any).items, |
|
126 |
createdTime: (note as any).created, |
|
127 |
updatedTime: (note as any).updated, |
|
128 |
noteColor: (note as any).note_color, |
|
129 |
}) |
|
130 |
} |
|
131 |
|
|
132 |
return { |
|
133 |
notes, |
|
134 |
} |
|
135 |
} |
|
136 |
else{ |
|
137 |
// no notes for this item |
|
138 |
return { |
|
139 |
notes: [], |
|
140 |
} |
|
115 | 141 |
} |
116 |
} else { |
|
142 |
} |
|
143 |
else { |
|
117 | 144 |
return Promise.reject(response.data ? response.data : "Error") |
118 | 145 |
} |
119 | 146 |
} catch (err: any) { |
src/stores/reducers/itemSlice.ts | ||
---|---|---|
59 | 59 |
state.item.provenance = undefined; |
60 | 60 |
state.item.description = undefined; |
61 | 61 |
} |
62 |
|
|
63 |
// // set concordances from item, if selected concordance is 0 |
|
64 |
// if (state.selectedConcordance === 0) { |
|
65 |
// state.concordances = action.payload.concordances; |
|
66 |
// } |
|
67 | 62 |
}) |
68 | 63 |
builder.addCase(getItem.rejected, (state, action) => { |
69 | 64 |
state.lastError = action.error.message |
70 | 65 |
}) |
71 | 66 |
|
67 |
// getItemNotes |
|
68 |
builder.addCase(getItemNotes.fulfilled, (state, action) => { |
|
69 |
state.notes = action.payload.notes; |
|
70 |
}) |
|
71 |
builder.addCase(getItemNotes.rejected, (state, action) => { |
|
72 |
state.lastError = action.error.message |
|
73 |
}) |
|
74 |
|
|
72 | 75 |
} |
73 | 76 |
}) |
74 | 77 |
|
src/types/note.ts | ||
---|---|---|
6 | 6 |
createdTime: Date |
7 | 7 |
updatedTime: Date |
8 | 8 |
noteColor: string |
9 |
lastError?: string |
|
10 | 9 |
} |
Také k dispozici: Unified diff
re #10454: ItemView getItemNotes