Revize ab68c8da
Přidáno uživatelem Dominik Poch před téměř 3 roky(ů)
webapp/contexts/TagCategoryContext.tsx | ||
---|---|---|
1 | 1 |
import React, { createContext, useEffect, useState } from 'react'; |
2 |
import { TagCategoryInfo, TagInfo } from '../api'; |
|
2 |
import { SubTagInfo, TagCategoryInfo, TagInfo } from '../api';
|
|
3 | 3 |
import { tagController } from '../controllers'; |
4 | 4 |
|
5 | 5 |
/** |
... | ... | |
7 | 7 |
*/ |
8 | 8 |
interface ITagCategoryContextProvider { |
9 | 9 |
/** |
10 |
* Tags managed by the context.
|
|
10 |
* Categories managed by the context.
|
|
11 | 11 |
*/ |
12 | 12 |
tagCategories: TagCategoryInfo[] | null; |
13 | 13 |
|
14 |
/** |
|
15 |
* Selected tag managed by the context. |
|
16 |
*/ |
|
17 |
selectedTag: TagInfo | null; |
|
18 |
|
|
19 |
/** |
|
20 |
* Selected sub tag managed by the context. |
|
21 |
*/ |
|
22 |
selectedSubTag: SubTagInfo | null; |
|
23 |
|
|
14 | 24 |
/** |
15 | 25 |
* Sets new tags. |
16 | 26 |
* @param newTags An array of new tags. |
17 | 27 |
*/ |
18 | 28 |
setTagCategories: (newTagCategories: TagCategoryInfo[] | null) => void; |
29 |
|
|
30 |
/** |
|
31 |
* Selects a tag. |
|
32 |
* @param tag Tag. |
|
33 |
* @param subTag Sub tag. |
|
34 |
*/ |
|
35 |
selectTag: (tag: TagInfo, subTag: SubTagInfo | null) => void; |
|
19 | 36 |
} |
20 | 37 |
|
21 | 38 |
/** |
... | ... | |
23 | 40 |
*/ |
24 | 41 |
export const TagCategoryContext = createContext<ITagCategoryContextProvider>({ |
25 | 42 |
/** |
26 |
* Default tags.
|
|
43 |
* Default categories.
|
|
27 | 44 |
*/ |
28 | 45 |
tagCategories: null, |
29 | 46 |
|
47 |
/** |
|
48 |
* Default selected tag. |
|
49 |
*/ |
|
50 |
selectedTag: null, |
|
51 |
|
|
52 |
/** |
|
53 |
* Default selected sub tag. |
|
54 |
*/ |
|
55 |
selectedSubTag: null, |
|
56 |
|
|
30 | 57 |
/** |
31 | 58 |
* Default implementation of setTags method. |
32 |
* @param v Array of new tags.
|
|
59 |
* @param c Array of new tags.
|
|
33 | 60 |
*/ |
34 | 61 |
setTagCategories: (c) => { |
35 | 62 |
return; |
36 | 63 |
}, |
64 |
|
|
65 |
/** |
|
66 |
* Default implementation of selectTag. |
|
67 |
* @param t Tag. |
|
68 |
* @param s Sub tag. |
|
69 |
*/ |
|
70 |
selectTag: (t: TagInfo, s: SubTagInfo | null) => { |
|
71 |
return; |
|
72 |
}, |
|
37 | 73 |
}); |
38 | 74 |
|
39 | 75 |
/** |
... | ... | |
46 | 82 |
* Tags managed by the context. |
47 | 83 |
*/ |
48 | 84 |
const [tagCategories, setTagCategories] = useState<TagCategoryInfo[] | null>(null); |
85 |
const [selectedTag, setSelectedTag] = useState<TagInfo | null>(null); |
|
86 |
const [selectedSubTag, setSelectedSubTag] = useState<SubTagInfo | null>(null); |
|
87 |
|
|
88 |
/** |
|
89 |
* Selects a tag. |
|
90 |
*/ |
|
91 |
const selectTag = (tag: TagInfo, subTag: SubTagInfo | null) => { |
|
92 |
setSelectedTag(tag); |
|
93 |
setSelectedSubTag(subTag); |
|
94 |
}; |
|
49 | 95 |
|
50 | 96 |
/** |
51 | 97 |
* Initializes the context. |
... | ... | |
62 | 108 |
<TagCategoryContext.Provider |
63 | 109 |
value={{ |
64 | 110 |
tagCategories, |
111 |
selectedTag, |
|
112 |
selectedSubTag, |
|
65 | 113 |
setTagCategories, |
114 |
selectTag, |
|
66 | 115 |
}} |
67 | 116 |
> |
68 | 117 |
{props.children} |
webapp/pages/annotation/index.tsx | ||
---|---|---|
5 | 5 |
import 'antd/dist/antd.css'; |
6 | 6 |
import styles from '/styles/Annotation.module.scss'; |
7 | 7 |
import AnnotationProvider from '../../contexts/AnnotationContext'; |
8 |
import TagCategoryProvider from '../../contexts/TagCategoryContext'; |
|
8 | 9 |
|
9 | 10 |
/** |
10 | 11 |
* Creates an annotation screen. |
... | ... | |
13 | 14 |
function Annotation() { |
14 | 15 |
return ( |
15 | 16 |
<AnnotationProvider> |
16 |
<MainLayout> |
|
17 |
<div className={styles.layoutWrapper}> |
|
18 |
<div className={styles.tags}> |
|
19 |
<TagPanel /> |
|
17 |
<TagCategoryProvider> |
|
18 |
<MainLayout> |
|
19 |
<div className={styles.layoutWrapper}> |
|
20 |
<div className={styles.tags}> |
|
21 |
<TagPanel /> |
|
22 |
</div> |
|
23 |
<div className={styles.document}> |
|
24 |
<DocumentAnnotationView /> |
|
25 |
</div> |
|
26 |
<div className={styles.annotations}> |
|
27 |
<AnnotationPanel /> |
|
28 |
</div> |
|
20 | 29 |
</div> |
21 |
<div className={styles.document}> |
|
22 |
<DocumentAnnotationView /> |
|
23 |
</div> |
|
24 |
<div className={styles.annotations}> |
|
25 |
<AnnotationPanel /> |
|
26 |
</div> |
|
27 |
</div> |
|
28 |
</MainLayout> |
|
30 |
</MainLayout> |
|
31 |
</TagCategoryProvider> |
|
29 | 32 |
</AnnotationProvider> |
30 | 33 |
); |
31 | 34 |
} |
Také k dispozici: Unified diff
Tag selection
Report when tag is selected