Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c057279b

Přidáno uživatelem Lukáš Vlček před více než 2 roky(ů)

AnnotationContext added

Zobrazit rozdíly:

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

  
5
interface IAnnotationContextProvider {
6
    tags: TagInstanceInfo[] | null;
7
    setTags: (newTags: TagInstanceInfo[] | null) => void;
8
    addOccurrence: () => 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: () => {
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 = () => {};
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;
webapp/pages/annotation/index.tsx
5 5
import 'antd/dist/antd.css';
6 6
import styles from '/styles/annotation.module.scss';
7 7
import { Occurrence, Tag } from '../../components/models/tag';
8
import AnnotationProvider from '../../contexts/AnnotationContext';
8 9

  
9 10
/**
10 11
 * Creates an annotation screen.
......
43 44
    const changeLength = (occurrence: Occurrence, newValue: number) => {};
44 45

  
45 46
    return (
46
        <MainLayout>
47
            <div className={styles.layoutwrapper}>
48
                <div className={styles.tags}>
49
                    <TagPanel />
47
        <AnnotationProvider>
48
            <MainLayout>
49
                <div className={styles.layoutwrapper}>
50
                    <div className={styles.tags}>
51
                        <TagPanel />
52
                    </div>
53
                    <div className={styles.document}>
54
                        <DocumentAnnotationView />
55
                    </div>
56
                    <div className={styles.annotations}>
57
                        <AnnotationPanel
58
                            tags={tags}
59
                            onAddOccurrence={addOccurrence}
60
                            onChangeVisibility={changeVisibility}
61
                            onDeleteOccurrence={deleteOccurrence}
62
                            onChangePosition={changePosition}
63
                            onChangeLength={changeLength}
64
                        />
65
                    </div>
50 66
                </div>
51
                <div className={styles.document}>
52
                    <DocumentAnnotationView />
53
                </div>
54
                <div className={styles.annotations}>
55
                    <AnnotationPanel
56
                        tags={tags}
57
                        onAddOccurrence={addOccurrence}
58
                        onChangeVisibility={changeVisibility}
59
                        onDeleteOccurrence={deleteOccurrence}
60
                        onChangePosition={changePosition}
61
                        onChangeLength={changeLength}
62
                    />
63
                </div>
64
            </div>
65
        </MainLayout>
67
            </MainLayout>
68
        </AnnotationProvider>
66 69
    );
67 70
}
68 71

  

Také k dispozici: Unified diff