Projekt

Obecné

Profil

« Předchozí | Další » 

Revize acb8a961

Přidáno uživatelem Dominik Poch před více než 2 roky(ů)

Added comments

Zobrazit rozdíly:

webapp/contexts/AnnotationContext.tsx
1
import React, { createContext, useContext, useEffect, useState } from 'react';
1
import React, { createContext, useEffect, useState } from 'react';
2 2
import { TagInstanceInfo } from '../api';
3 3
import { Occurrence, Tag } from '../components/types/tag';
4 4

  
5
/**
6
 * Interface of an annotation context provider.
7
 */
5 8
interface IAnnotationContextProvider {
9
    /**
10
     * Tags managed by the context.
11
     */
6 12
    tags: TagInstanceInfo[] | null;
13

  
14
    /**
15
     * Sets new tags.
16
     * @param newTags An array of new tags.
17
     */
7 18
    setTags: (newTags: TagInstanceInfo[] | null) => void;
19

  
20
    /**
21
     * Adds occurrence to an annotation.
22
     * @param tag Tag whose occurrence should be added.
23
     */
8 24
    addOccurrence: (tag: Tag) => void;
25

  
26
    /**
27
     * Changes visibility of an annotation.
28
     * @param tag Tag whose visibility should be changed.
29
     */
9 30
    changeVisibility: (tag: Tag) => void;
31

  
32
    /**
33
     * Deletes an occurrence of an annotation.
34
     * @param occurrence Occurrence that should be deleted.
35
     */
10 36
    deleteOccurrence: (occurrence: Occurrence) => void;
37

  
38
    /**
39
     * Changes a position of an occurrence of an annotation.
40
     * @param occurrence Occurrence whose position should be changed.
41
     * @param newValue New value of the position.
42
     */
11 43
    changePosition: (occurrence: Occurrence, newValue: number) => void;
44

  
45
    /**
46
     * Changes a length of an occurrence of an annotation.
47
     * @param occurrence Occurrence whose length should be changed.
48
     * @param newValue New value of the length.
49
     */
12 50
    changeLength: (occurrence: Occurrence, newValue: number) => void;
13 51
}
14 52

  
53
/**
54
 * The annotation context that manages active annotations.
55
 */
15 56
export const AnnotationContext = createContext<IAnnotationContextProvider>({
57
    /**
58
     * Default tags.
59
     */
16 60
    tags: null,
61

  
62
    /**
63
     * Default implementation of setTags method.
64
     * @param v Array of new tags.
65
     */
17 66
    setTags: (v) => {
18 67
        return;
19 68
    },
69

  
70
    /**
71
     * Default implementation of addOccurrence method.
72
     * @param tag The tag with new occurrence.
73
     */
20 74
    addOccurrence: (tag: Tag) => {
21 75
        return;
22 76
    },
77

  
78
    /**
79
     * Default implementation of changeVisibility method.
80
     * @param tag The tag whose visibility should be changed.
81
     */
23 82
    changeVisibility: (tag: Tag) => {
24 83
        return;
25 84
    },
85

  
86
    /**
87
     * Default implementation of deleteOccurrence method.
88
     * @param occurrence Occurrence that should be deleted.
89
     */
26 90
    deleteOccurrence: (occurrence: Occurrence) => {
27 91
        return;
28 92
    },
93

  
94
    /**
95
     * Default implementation of changePosition method.
96
     * @param occurrence Occurrence whose position should be changed.
97
     * @param newValue A new position.
98
     */
29 99
    changePosition: (occurrence: Occurrence, newValue: number) => {
30 100
        return;
31 101
    },
102

  
103
    /**
104
     * Default implementation of changeLength method.
105
     * @param occurrence Occurrence whose length should be changed.
106
     * @param newValue A new length.
107
     */
32 108
    changeLength: (occurrence: Occurrence, newValue: number) => {
33 109
        return;
34 110
    },
35 111
});
36 112

  
113
/**
114
 * Provider of the annotation context.
115
 * @param props Children that should have access to the annotation context.
116
 * @returns Prepared html of the provider.
117
 */
37 118
const AnnotationProvider = (props: { children: React.ReactNode }) => {
119
    /**
120
     * Tags managed by the context.
121
     */
38 122
    const [tags, setTags] = useState<TagInstanceInfo[] | null>(null);
39
    const addOccurrence = (tag: Tag) => {};
40
    const changeVisibility = (tag: Tag) => {};
41
    const deleteOccurrence = (occurrence: Occurrence) => {};
42
    const changePosition = (occurrence: Occurrence, newValue: number) => {};
43
    const changeLength = (occurrence: Occurrence, newValue: number) => {};
44 123

  
124
    /**
125
     * Default implementation of addOccurrence method.
126
     * @param tag The tag with new occurrence.
127
     */
128
    const addOccurrence = (tag: Tag) => {
129
        //TODO: Implement method (should use objects from server API)
130
    };
131

  
132
    /**
133
     * Changes visibility of an annotation.
134
     * @param tag Tag whose visibility should be changed.
135
     */
136
    const changeVisibility = (tag: Tag) => {
137
        //TODO: Implement method (should use objects from server API)
138
    };
139

  
140
    /**
141
     * Deletes an occurrence of an annotation.
142
     * @param occurrence Occurrence that should be deleted.
143
     */
144
    const deleteOccurrence = (occurrence: Occurrence) => {
145
        //TODO: Implement method (should use objects from server API)
146
    };
147

  
148
    /**
149
     * Changes a position of an occurrence of an annotation.
150
     * @param occurrence Occurrence whose position should be changed.
151
     * @param newValue New value of the position.
152
     */
153
    const changePosition = (occurrence: Occurrence, newValue: number) => {
154
        //TODO: Implement method (should use objects from server API)
155
    };
156

  
157
    /**
158
     * Changes a length of an occurrence of an annotation.
159
     * @param occurrence Occurrence whose length should be changed.
160
     * @param newValue New value of the length.
161
     */
162
    const changeLength = (occurrence: Occurrence, newValue: number) => {
163
        //TODO: Implement method (should use objects from server API)
164
    };
165

  
166
    /**
167
     * Initializes the context.
168
     */
45 169
    useEffect(() => {
46
        // on context init
170
        //TODO: Implement initialization with values from the server
47 171
    }, []);
48 172

  
49 173
    return (

Také k dispozici: Unified diff