Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dee53692

Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)

Disabling tag buttons when adding new tag occurrence

Zobrazit rozdíly:

webapp/contexts/AnnotationContext.tsx
1 1
import React, { createContext, useEffect, useState } from 'react';
2 2
import { AnnotationInfo, ETagType, SubTagInfo, TagInfo, TagInstanceInfo } from '../api';
3 3
import { Tag } from '../components/types/tag';
4
import { annotationController } from '../controllers';
4
import { annotationController, userController } from '../controllers';
5 5
import { GetSelectionInfo } from '../utils/selectionUtils';
6
import { ShowConfirmDelete, ShowToast } from '../utils/alerts';
6 7

  
7 8
/**
8 9
 * Interface of an annotation context provider.
......
13 14
     */
14 15
    tags: TagInstanceInfo[] | null;
15 16

  
17
    /**
18
     * Submitting boolean
19
     */
20
    submitting: boolean;
21

  
16 22
    /**
17 23
     * Sets new tags.
18 24
     * @param newTags An array of new tags.
......
71 77
     */
72 78
    tags: null,
73 79

  
80
    /**
81
     * Submitting boolean
82
     */
83
    submitting: false,
84

  
74 85
    /**
75 86
     * Default implementation of setTags method.
76 87
     * @param v Array of new tags.
......
150 161

  
151 162
    const [mappedTags, setMappedTags] = useState<Tag[] | null>(null);
152 163

  
164
    const [submitting, setSubmitting] = useState(false);
165

  
153 166
    async function markSelectedText(
154 167
        tagId: string,
155 168
        subtagId: string | null,
156 169
        instanceId: string | null
157 170
    ) {
171
        setSubmitting(true);
158 172
        if (!annotation) {
159 173
            console.log('annotation not found');
160 174
            return;
......
170 184

  
171 185
        const id = subtagId ?? tagId;
172 186
        const type: ETagType = subtagId == null ? ETagType.Tag : ETagType.Subtag;
173

  
174
        const res = await annotationController.annotationAnnotationIdPost(
175
            props.annotationId,
176
            {
187
        const res = await annotationController
188
            .annotationAnnotationIdPost(props.annotationId, {
177 189
                id: id,
178 190
                instanceId,
179 191
                type,
180 192
                position: selectionInfo.startPositionOriginalDocument,
181 193
                length: selectionInfo.selectionLengthOriginalDocument,
182
            }
183
        );
194
            })
195
            .catch((e) => ShowToast('Duplicitní výskyt anotace!', 'warning'));
184 196

  
185 197
        await refreshAnnotation();
186 198
    }
......
211 223
            return;
212 224
        }
213 225

  
214
        const deleteRes =
215
            await annotationController.annotationAnnotationIdOccurenceIdDelete(
216
                props.annotationId,
217
                occurrence.occurenceId
218
            );
219

  
220
        await refreshAnnotation();
226
        ShowConfirmDelete(() => {
227
            annotationController
228
                .annotationAnnotationIdOccurenceIdDelete(
229
                    props.annotationId,
230
                    occurrence.occurenceId ?? ''
231
                )
232
                .then(() => refreshAnnotation());
233
        }, 'značku');
221 234
    };
222 235

  
223 236
    /**
......
268 281

  
269 282
        remapAnnotations(data.data);
270 283
        setAnnotation(data.data ?? null);
284
        setSubmitting(false);
271 285
    }
272 286

  
273 287
    /**
......
281 295
        <AnnotationContext.Provider
282 296
            value={{
283 297
                tags,
298
                submitting,
284 299
                setTags,
285 300
                addOccurrence,
286 301
                changeVisibility,

Také k dispozici: Unified diff