Revize a27b3427
Přidáno uživatelem Fantič před více než 1 rok
src/components/notes/NoteView.tsx | ||
---|---|---|
1 |
import { HStack, Box, Text, Image, VStack, Flex, Pressable, DeleteIcon, Button, Center, Avatar, TextArea, AlertDialog } from "native-base"; |
|
1 |
import { HStack, Box, Text, Image, VStack, Flex, Pressable, DeleteIcon, Button, Center, Avatar, TextArea, AlertDialog, ScrollView } from "native-base";
|
|
2 | 2 |
import { Note } from "../../types/note"; |
3 | 3 |
import { EditIcon } from "../general/Icons"; |
4 | 4 |
import { AVATAR_URL } from "../../api/constants"; |
5 | 5 |
import { useState } from "react"; |
6 | 6 |
import React from "react"; |
7 |
import { StyleProp, ViewStyle } from "react-native";
|
|
7 |
import NotesListView from "./NotesListView";
|
|
8 | 8 |
|
9 |
const NoteView = React.memo((props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any }) => { |
|
9 |
const NoteView = React.memo((props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any, parentId?: string }) => {
|
|
10 | 10 |
const note = props.note; |
11 | 11 |
|
12 | 12 |
const [isEdited, setIsEdited] = useState(false); |
13 | 13 |
|
14 |
const [showReplies, setShowReplies] = useState(false); |
|
15 |
|
|
14 | 16 |
const [text, setText] = useState(note.note); |
15 | 17 |
|
16 |
console.log("rerender"); |
|
17 | 18 |
|
18 | 19 |
const getDateString = (timestamp: Date): string => { |
19 | 20 |
return new Date(timestamp).toLocaleString("en-US", |
... | ... | |
30 | 31 |
return "UK"; // Unknown |
31 | 32 |
} |
32 | 33 |
|
34 |
|
|
35 |
const toggleShowReplies = () => { |
|
36 |
console.log("Toggle showReplies"); |
|
37 |
setShowReplies(!showReplies) |
|
38 |
} |
|
39 |
|
|
33 | 40 |
const toggleEdited = () => { |
34 | 41 |
console.log("Toggle edit"); |
35 | 42 |
if (isEdited) { |
... | ... | |
127 | 134 |
<Pressable onPress={() => props.handleReply(note.uuid, note.username)}> |
128 | 135 |
<Text color="light.500">Reply</Text> |
129 | 136 |
</Pressable>} |
137 |
{!props.parentId && note.replies && note.replies.length > 0 && |
|
138 |
<Pressable marginLeft={3} onPress={() => toggleShowReplies()}> |
|
139 |
{!showReplies ? |
|
140 |
<Text color="light.500">{note.replies.length} replies</Text> |
|
141 |
: |
|
142 |
<Text color="light.500">Hide</Text> |
|
143 |
} |
|
144 |
|
|
145 |
</Pressable>} |
|
130 | 146 |
</Flex> |
131 | 147 |
|
132 | 148 |
<Flex direction="row" alignItems="center" justify="flex-end"> |
... | ... | |
150 | 166 |
</Pressable>} |
151 | 167 |
</Flex> |
152 | 168 |
</HStack> |
169 |
{showReplies && |
|
170 |
<VStack style={{borderLeftColor: '#FFC107', borderLeftWidth: 1, paddingLeft: 5, marginTop: 5}}> |
|
171 |
{note.replies?.map((note, index) => { |
|
172 |
return ( |
|
173 |
<NoteView key={index} note={note} handleReply={null} handleDelete={props.handleDelete} handleEdit={props.handleEdit} setConfirmDialog={props.setConfirmDialog} navigation={props.navigation} /> |
|
174 |
) |
|
175 |
})} |
|
176 |
</VStack> |
|
177 |
} |
|
153 | 178 |
</VStack> |
154 | 179 |
</HStack> |
155 | 180 |
); |
src/components/notes/NotesListView.tsx | ||
---|---|---|
56 | 56 |
notes && notes.length > 0 ? ( |
57 | 57 |
<VStack> |
58 | 58 |
{notes.map((note, index) => { |
59 |
if(index >= 5){ |
|
60 |
return null; |
|
61 |
} |
|
59 |
// if(index >= 5){
|
|
60 |
// return null;
|
|
61 |
// }
|
|
62 | 62 |
return ( |
63 | 63 |
<NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} /> |
64 | 64 |
) |
src/stores/actions/itemThunks.ts | ||
---|---|---|
2 | 2 |
import { getItemRequest } from "../../api/itemservice" |
3 | 3 |
import { getItemNotesRequest } from "../../api/notesservice" |
4 | 4 |
import { Certainty, Concordance, Item } from "../../types/item"; |
5 |
import { Note } from "../../types/note"; |
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
export const getItem = createAsyncThunk( |
... | ... | |
11 | 12 |
console.log("GET item/getItem/" + itemId); |
12 | 13 |
|
13 | 14 |
const response = await getItemRequest(itemId); |
14 |
|
|
15 |
|
|
15 | 16 |
// data with image |
16 | 17 |
if (response.status === 200 && response.data.object.length > 1) { |
17 | 18 |
const authorName = response.data.object[1]?.name?.[0]?.getty_data?.display_name || null; |
... | ... | |
26 | 27 |
const repository = response.data.object[1]?.repository || null; |
27 | 28 |
const provenance = response.data.object[1]?.provenance || null; |
28 | 29 |
const description = response.data.object[1]?.physical_description || null; |
29 |
|
|
30 |
|
|
30 | 31 |
return { |
31 | 32 |
id: itemId, |
32 | 33 |
fullView: true, |
33 | 34 |
concordances: response.data.concordances ? |
34 |
[{id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown}].concat(response.data.concordances)
|
|
35 |
:
|
|
36 |
[{id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown}],
|
|
35 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }].concat(response.data.concordances)
|
|
36 |
: |
|
37 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }],
|
|
37 | 38 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null, |
38 | 39 |
workName: response.data.object[0]?.caption || null, |
39 | 40 |
inventoryItem: response.data.text || null, |
... | ... | |
53 | 54 |
id: itemId, |
54 | 55 |
fullView: false, |
55 | 56 |
concordances: response.data.concordances ? |
56 |
[{id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown}].concat(response.data.concordances)
|
|
57 |
: |
|
58 |
[{id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown}],
|
|
57 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }].concat(response.data.concordances)
|
|
58 |
:
|
|
59 |
[{ id: itemId, cert: response.data.object[1]?.cert || Certainty.Unknown }],
|
|
59 | 60 |
authorDisplayName: response.data.object[0]?.name?.[0]?.getty_data?.display_name || null, |
60 | 61 |
workName: response.data.object[0]?.caption || null, |
61 | 62 |
inventoryItem: response.data.text || null, |
... | ... | |
67 | 68 |
return Promise.reject(response.data ? response.data : "Error") |
68 | 69 |
} |
69 | 70 |
} catch (err: any) { |
70 |
|
|
71 |
|
|
71 | 72 |
console.log(err); |
72 | 73 |
return Promise.reject(err.response.data) |
73 | 74 |
} |
74 | 75 |
} |
75 | 76 |
) |
76 | 77 |
|
77 |
export const setConcordances = (concordances: Concordance[]) => {
|
|
78 |
export const setConcordances = (concordances: Concordance[]) => { |
|
78 | 79 |
return { |
79 |
type: "item/setConcordances", |
|
80 |
payload: { |
|
81 |
concordances, |
|
82 |
}, |
|
80 |
type: "item/setConcordances",
|
|
81 |
payload: {
|
|
82 |
concordances,
|
|
83 |
},
|
|
83 | 84 |
}; |
84 |
};
|
|
85 |
}; |
|
85 | 86 |
|
86 | 87 |
// export const getItemConcordances = createAsyncThunk( |
87 | 88 |
// "item/getItemConcordances", |
... | ... | |
104 | 105 |
|
105 | 106 |
export const getItemNotes = createAsyncThunk( |
106 | 107 |
"item/getItemNotes", |
107 |
async ({item, relatedComments}: {item: Item, relatedComments: boolean}) => {
|
|
108 |
async ({ item, relatedComments }: { item: Item, relatedComments: boolean }) => {
|
|
108 | 109 |
try { |
109 | 110 |
console.log("GET notes/getNotes/" + item.id); |
110 | 111 |
|
111 | 112 |
const response = await getItemNotesRequest(item, relatedComments); |
112 | 113 |
|
113 | 114 |
if (response.status === 200) { |
114 |
if(response.data.length > 0){
|
|
115 |
if (response.data.length > 0) {
|
|
115 | 116 |
|
116 | 117 |
let notes = []; |
117 |
for(let i = 0; i < response.data.length; i++){
|
|
118 |
for (let i = 0; i < response.data.length; i++) {
|
|
118 | 119 |
let note = response.data[i]; |
120 |
let replies : any = undefined |
|
121 |
|
|
122 |
// convert replies |
|
123 |
if(note.replies){ |
|
124 |
replies = []; |
|
125 |
for(let i = 0; i < note.replies.length; i++){ |
|
126 |
const reply = note.replies[i]; |
|
127 |
replies.push({ |
|
128 |
uuid: (reply as any).uuid, |
|
129 |
username: (reply as any).created_by, |
|
130 |
userId: (reply as any).created_by_id, |
|
131 |
note: (reply as any).note, |
|
132 |
avatarUrl: (reply as any).avatar, |
|
133 |
items: (reply as any).items, |
|
134 |
createdTime: (reply as any).created, |
|
135 |
updatedTime: (reply as any).updated, |
|
136 |
noteColor: (reply as any).note_color, |
|
137 |
reply_to: note.uuid |
|
138 |
}) |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
119 | 142 |
notes.push({ |
120 | 143 |
uuid: (note as any).uuid, |
121 | 144 |
username: (note as any).created_by, |
... | ... | |
123 | 146 |
note: (note as any).note, |
124 | 147 |
avatarUrl: (note as any).avatar, |
125 | 148 |
items: (note as any).items, |
126 |
replies: (note as any).replies ?? undefined,
|
|
127 |
createdTime: (note as any).created,
|
|
149 |
replies: replies,
|
|
150 |
createdTime: (note as any).created, |
|
128 | 151 |
updatedTime: (note as any).updated, |
129 | 152 |
noteColor: (note as any).note_color, |
130 | 153 |
reply_to: (note as any).reply_to |
... | ... | |
135 | 158 |
notes, |
136 | 159 |
} |
137 | 160 |
} |
138 |
else{ |
|
161 |
else {
|
|
139 | 162 |
// no notes for this item |
140 | 163 |
return { |
141 | 164 |
notes: [], |
src/stores/actions/notesThunks.ts | ||
---|---|---|
86 | 86 |
let notes = []; |
87 | 87 |
for (let i = 0; i < response.data.length; i++) { |
88 | 88 |
let note = response.data[i]; |
89 |
let replies : any = undefined |
|
90 |
|
|
91 |
// convert replies |
|
92 |
if(note.replies){ |
|
93 |
replies = []; |
|
94 |
for(let i = 0; i < note.replies.length; i++){ |
|
95 |
const reply = note.replies[i]; |
|
96 |
replies.push({ |
|
97 |
uuid: (reply as any).uuid, |
|
98 |
username: (reply as any).created_by, |
|
99 |
userId: (reply as any).created_by_id, |
|
100 |
note: (reply as any).note, |
|
101 |
avatarUrl: (reply as any).avatar, |
|
102 |
items: (reply as any).items, |
|
103 |
createdTime: (reply as any).created, |
|
104 |
updatedTime: (reply as any).updated, |
|
105 |
noteColor: (reply as any).note_color, |
|
106 |
reply_to: note.uuid |
|
107 |
}) |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
89 | 111 |
notes.push({ |
90 | 112 |
uuid: (note as any).uuid, |
91 | 113 |
username: (note as any).created_by, |
... | ... | |
93 | 115 |
note: (note as any).note, |
94 | 116 |
avatarUrl: (note as any).avatar, |
95 | 117 |
items: (note as any).items, |
96 |
replies: (note as any).replies ?? undefined,
|
|
118 |
replies: replies,
|
|
97 | 119 |
createdTime: (note as any).created, |
98 | 120 |
updatedTime: (note as any).updated, |
99 | 121 |
noteColor: (note as any).note_color, |
Také k dispozici: Unified diff
#re 10797 NoteView: Note replies base