Revize 7652cf88
Přidáno uživatelem Lukáš Vlček před asi 2 roky(ů)
webapp/contexts/AnnotationContext.tsx | ||
---|---|---|
1 | 1 |
import React, { createContext, useEffect, useState } from 'react'; |
2 |
import { TagInstanceInfo } from '../api'; |
|
2 |
import { AnnotationInfo, TagInstanceInfo } from '../api';
|
|
3 | 3 |
import { Occurrence, Tag } from '../components/types/tag'; |
4 |
import { annotationController } from '../controllers'; |
|
4 | 5 |
|
5 | 6 |
/** |
6 | 7 |
* Interface of an annotation context provider. |
... | ... | |
48 | 49 |
* @param newValue New value of the length. |
49 | 50 |
*/ |
50 | 51 |
changeLength: (occurrence: Occurrence, newValue: number) => void; |
52 |
|
|
53 |
annotation: AnnotationInfo | null; |
|
54 |
refreshAnnotation: () => void; |
|
51 | 55 |
} |
52 | 56 |
|
53 | 57 |
/** |
... | ... | |
108 | 112 |
changeLength: (occurrence: Occurrence, newValue: number) => { |
109 | 113 |
return; |
110 | 114 |
}, |
115 |
|
|
116 |
annotation: null, |
|
117 |
refreshAnnotation: () => { |
|
118 |
return; |
|
119 |
}, |
|
111 | 120 |
}); |
112 | 121 |
|
113 | 122 |
/** |
... | ... | |
119 | 128 |
children: React.ReactNode; |
120 | 129 |
annotationId: string; |
121 | 130 |
}) => { |
131 |
const [annotation, setAnnotation] = useState<AnnotationInfo | null>(null); |
|
132 |
|
|
122 | 133 |
/** |
123 | 134 |
* Tags managed by the context. |
124 | 135 |
*/ |
... | ... | |
166 | 177 |
//TODO: Implement method (should use objects from server API) |
167 | 178 |
}; |
168 | 179 |
|
180 |
async function refreshAnnotation() { |
|
181 |
const data = await annotationController.annotationAnnotationIdGet( |
|
182 |
props.annotationId |
|
183 |
); |
|
184 |
|
|
185 |
setAnnotation(data.data ?? null); |
|
186 |
} |
|
187 |
|
|
169 | 188 |
/** |
170 | 189 |
* Initializes the context. |
171 | 190 |
*/ |
172 | 191 |
useEffect(() => { |
173 |
//TODO: Implement initialization with values from the server
|
|
192 |
refreshAnnotation();
|
|
174 | 193 |
}, [props.annotationId]); |
175 | 194 |
|
176 | 195 |
return ( |
... | ... | |
183 | 202 |
deleteOccurrence, |
184 | 203 |
changeLength, |
185 | 204 |
changePosition, |
205 |
refreshAnnotation, |
|
206 |
annotation, |
|
186 | 207 |
}} |
187 | 208 |
> |
188 | 209 |
{props.children} |
Také k dispozici: Unified diff
Basic annotation document preview