Revize 06d1aa21
Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)
webapp/pages/documents/annotator/index.tsx | ||
---|---|---|
15 | 15 |
const redirecting = useUnauthRedirect('/login'); |
16 | 16 |
const { logout, role } = useContext(LoggedUserContext); |
17 | 17 |
const router = useRouter(); |
18 |
const [documents, setDocuments] = useState<AnnotationListInfo[] | null | undefined>( |
|
19 |
[] |
|
20 |
); |
|
18 |
const [documents, setDocuments] = useState<AnnotationListInfo[]>([]); |
|
21 | 19 |
|
22 | 20 |
useEffect(() => { |
23 |
console.log(role); |
|
24 |
if (role !== 'ANNOTATOR') { |
|
25 |
logout(); |
|
26 |
router.push('/login'); |
|
27 |
} |
|
28 |
|
|
29 | 21 |
async function fetchData() { |
30 | 22 |
let docs = (await userController.userAnnotationsGet()).data.annotations; |
31 |
console.log(docs); |
|
32 |
setDocuments(docs); |
|
23 |
if (!docs) { |
|
24 |
setDocuments([]); |
|
25 |
} else { |
|
26 |
setDocuments(docs); |
|
27 |
} |
|
33 | 28 |
} |
34 |
if (!redirecting) { |
|
29 |
if (!redirecting && role === 'ANNOTATOR') {
|
|
35 | 30 |
fetchData(); |
36 | 31 |
} |
37 | 32 |
}, [logout, redirecting, role, router]); |
... | ... | |
69 | 64 |
key: 'action', |
70 | 65 |
dataIndex: 'annotationId', |
71 | 66 |
render: (anotationId: number) => ( |
72 |
<Button onClick={() => router.push('/annotation/' + anotationId)}> |
|
67 |
<Button |
|
68 |
key={anotationId} |
|
69 |
type={'primary'} |
|
70 |
onClick={() => router.push('/annotation/' + anotationId)} |
|
71 |
> |
|
73 | 72 |
Anotovat |
74 | 73 |
</Button> |
75 | 74 |
), |
76 | 75 |
}, |
77 | 76 |
]; |
78 | 77 |
|
79 |
// TODO switch to REAL data from Controller |
|
80 |
const data = []; |
|
81 |
for (let i = 0; i < 100; i++) { |
|
82 |
let state = 'DONE'; |
|
83 |
if (i % 3 === 1) { |
|
84 |
state = 'IN_PROGRESS'; |
|
85 |
} |
|
86 |
if (i % 3 === 2) { |
|
87 |
state = 'NEW'; |
|
88 |
} |
|
89 |
|
|
90 |
data.push({ |
|
91 |
key: i, |
|
92 |
documentName: `Dokument ${i}`, |
|
93 |
state: state, |
|
94 |
annotationId: i, |
|
95 |
}); |
|
96 |
} |
|
97 |
|
|
98 | 78 |
return redirecting || role !== 'ANNOTATOR' ? null : ( |
99 | 79 |
<MainLayout> |
100 | 80 |
<Typography.Title level={2}> |
101 | 81 |
<FontAwesomeIcon icon={faFileLines} /> Dokumenty |
102 | 82 |
</Typography.Title> |
103 |
<Table columns={columns} dataSource={data} size="small" scroll={{ y: 500 }} /> |
|
83 |
<Table |
|
84 |
columns={columns} |
|
85 |
dataSource={documents} |
|
86 |
size="small" |
|
87 |
scroll={{ y: 500 }} |
|
88 |
/> |
|
104 | 89 |
</MainLayout> |
105 | 90 |
); |
106 | 91 |
} |
Také k dispozici: Unified diff
Refactoring