Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5593c10b

Přidáno uživatelem Dominik Poch před asi 2 roky(ů)

Connected tag panel to server

Zobrazit rozdíly:

webapp/components/annotation/SubTagItem.tsx
1
import { SubTagInfo } from '../../api';
1
import { SubTagInfo, TagInfo } from '../../api';
2 2
import { Container, Row } from 'react-bootstrap';
3 3
import { Button } from 'antd';
4
import { useContext } from 'react';
5
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
4 6

  
5 7
/**
6 8
 * Creates a single tag item in a tag panel.
7 9
 * @param props Properties should contain the tag.
8 10
 * @returns The item that represents the tag.
9 11
 */
10
export function SubTagItem(props: { subTag: SubTagInfo }) {
12
export function SubTagItem(props: { tag: TagInfo; subTag: SubTagInfo }) {
13
    const { selectTag } = useContext(TagCategoryContext);
14

  
11 15
    /**
12 16
     * Selects the sub tag.
13 17
     */
14
    const selectSubTag = () => {};
18
    const onSelectSubTag = () => {
19
        selectTag(props.tag, props.subTag);
20
    };
15 21

  
16 22
    return (
17 23
        <Container>
18 24
            <Row>
19
                <Button type="text" onClick={selectSubTag} className="w-100 text-start">
25
                <Button type="text" onClick={onSelectSubTag} className="w-100 text-start">
20 26
                    {props.subTag.name}
21 27
                </Button>
22 28
            </Row>
webapp/components/annotation/TagItem.tsx
2 2
import { TagInfo } from '../../api';
3 3
import { Button } from 'antd';
4 4
import { DownOutlined, TagOutlined } from '@ant-design/icons';
5
import { useState } from 'react';
5
import { useContext, useState } from 'react';
6 6
import { SubTagItem } from './SubTagItem';
7
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
7 8

  
8 9
/**
9 10
 * Creates a single tag item in a tag panel.
......
16 17
     */
17 18
    const [visibleSubTags, setVisibleSubTags] = useState(false);
18 19

  
20
    const { selectTag } = useContext(TagCategoryContext);
21

  
19 22
    /**
20 23
     * Changes visibility of sub tags.
21 24
     */
......
26 29
    /**
27 30
     * Selects the tag.
28 31
     */
29
    const selectTag = () => {};
32
    const onSelectTag = () => {
33
        selectTag(props.tag, null);
34
    };
30 35

  
31 36
    return (
32 37
        <Container>
......
45 50
                    {!props.tag.subTags && (
46 51
                        <Button
47 52
                            type="text"
48
                            onClick={selectTag}
53
                            onClick={onSelectTag}
49 54
                            className="w-100 text-start"
50 55
                        >
51 56
                            {props.tag.name}
......
59 64
            {props.tag.subTags && visibleSubTags && (
60 65
                <Stack>
61 66
                    {props.tag.subTags?.map((subTag, index) => (
62
                        <SubTagItem subTag={subTag} key={index} />
67
                        <SubTagItem tag={props.tag} subTag={subTag} key={index} />
63 68
                    ))}
64 69
                </Stack>
65 70
            )}
webapp/components/annotation/TagPanel.tsx
1 1
import { CategoryItem } from './CategoryItem';
2 2
import { TagCategoryInfo } from '../../api';
3 3
import { Stack } from 'react-bootstrap';
4
import { useContext } from 'react';
5
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
4 6

  
5 7
/**
6 8
 * Creates a panel in the annotation screen that contains a list of tag.
7 9
 * @returns Panel with a list of tags.
8 10
 */
9 11
export function TagPanel() {
10
    const tags: TagCategoryInfo[] = [
11
        {
12
            name: 'kategorie 1',
13
            color: '#FF0000',
14
            tags: [
15
                {
16
                    name: 'tag 1',
17
                    color: '#CD5C5C',
18
                    subTags: [{ name: 'subTag 1' }, { name: 'subTag 2' }],
19
                },
20
                { name: 'tag 2', color: '#F08080' },
21
            ],
22
        },
23
        {
24
            name: 'kategorie 2',
25
            color: '#0000FF',
26
            tags: [{ name: 'tag 3', color: '#3498DB' }],
27
        },
28
    ];
12
    const { tagCategories } = useContext(TagCategoryContext);
29 13

  
30 14
    return (
31 15
        <div>
32 16
            <Stack>
33
                {tags.map((category, index) => (
17
                {tagCategories?.map((category, index) => (
34 18
                    <CategoryItem category={category} key={index} />
35 19
                ))}
36 20
            </Stack>

Také k dispozici: Unified diff