1 |
c057279b
|
Lukáš Vlček
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
2 |
|
|
import { TagInstanceInfo } from '../api';
|
3 |
c73aecde
|
Dominik Poch
|
import { Occurrence, Tag } from '../components/types/tag';
|
4 |
c057279b
|
Lukáš Vlček
|
|
5 |
|
|
interface IAnnotationContextProvider {
|
6 |
|
|
tags: TagInstanceInfo[] | null;
|
7 |
|
|
setTags: (newTags: TagInstanceInfo[] | null) => void;
|
8 |
c73aecde
|
Dominik Poch
|
addOccurrence: (tag: Tag) => void;
|
9 |
c057279b
|
Lukáš Vlček
|
changeVisibility: (tag: Tag) => void;
|
10 |
|
|
deleteOccurrence: (occurrence: Occurrence) => void;
|
11 |
|
|
changePosition: (occurrence: Occurrence, newValue: number) => void;
|
12 |
|
|
changeLength: (occurrence: Occurrence, newValue: number) => void;
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
export const AnnotationContext = createContext<IAnnotationContextProvider>({
|
16 |
|
|
tags: null,
|
17 |
|
|
setTags: (v) => {
|
18 |
|
|
return;
|
19 |
|
|
},
|
20 |
c73aecde
|
Dominik Poch
|
addOccurrence: (tag: Tag) => {
|
21 |
c057279b
|
Lukáš Vlček
|
return;
|
22 |
|
|
},
|
23 |
|
|
changeVisibility: (tag: Tag) => {
|
24 |
|
|
return;
|
25 |
|
|
},
|
26 |
|
|
deleteOccurrence: (occurrence: Occurrence) => {
|
27 |
|
|
return;
|
28 |
|
|
},
|
29 |
|
|
changePosition: (occurrence: Occurrence, newValue: number) => {
|
30 |
|
|
return;
|
31 |
|
|
},
|
32 |
|
|
changeLength: (occurrence: Occurrence, newValue: number) => {
|
33 |
|
|
return;
|
34 |
|
|
},
|
35 |
|
|
});
|
36 |
|
|
|
37 |
|
|
const AnnotationProvider = (props: { children: React.ReactNode }) => {
|
38 |
|
|
const [tags, setTags] = useState<TagInstanceInfo[] | null>(null);
|
39 |
c73aecde
|
Dominik Poch
|
const addOccurrence = (tag: Tag) => {};
|
40 |
c057279b
|
Lukáš Vlček
|
const changeVisibility = (tag: Tag) => {};
|
41 |
|
|
const deleteOccurrence = (occurrence: Occurrence) => {};
|
42 |
|
|
const changePosition = (occurrence: Occurrence, newValue: number) => {};
|
43 |
|
|
const changeLength = (occurrence: Occurrence, newValue: number) => {};
|
44 |
|
|
|
45 |
|
|
useEffect(() => {
|
46 |
|
|
// on context init
|
47 |
|
|
}, []);
|
48 |
|
|
|
49 |
|
|
return (
|
50 |
|
|
<AnnotationContext.Provider
|
51 |
|
|
value={{
|
52 |
|
|
tags,
|
53 |
|
|
setTags,
|
54 |
|
|
addOccurrence,
|
55 |
|
|
changeVisibility,
|
56 |
|
|
deleteOccurrence,
|
57 |
|
|
changeLength,
|
58 |
|
|
changePosition,
|
59 |
|
|
}}
|
60 |
|
|
>
|
61 |
|
|
{props.children}
|
62 |
|
|
</AnnotationContext.Provider>
|
63 |
|
|
);
|
64 |
|
|
};
|
65 |
|
|
|
66 |
|
|
export default AnnotationProvider;
|