Projekt

Obecné

Profil

Stáhnout (1.99 KB) Statistiky
| Větev: | Tag: | Revize:
1
import React, { createContext, useContext, useEffect, useState } from 'react';
2
import { TagInstanceInfo } from '../api';
3
import { Occurrence, Tag } from '../components/types/tag';
4

    
5
interface IAnnotationContextProvider {
6
    tags: TagInstanceInfo[] | null;
7
    setTags: (newTags: TagInstanceInfo[] | null) => void;
8
    addOccurrence: (tag: Tag) => void;
9
    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
    addOccurrence: (tag: Tag) => {
21
        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
    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

    
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;
    (1-1/1)