Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a27b3427

Přidáno uživatelem Fantič před více než 1 rok

#re 10797 NoteView: Note replies base

Zobrazit rozdíly:

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: [],

Také k dispozici: Unified diff