-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathTable.tsx
More file actions
87 lines (80 loc) · 2.38 KB
/
Table.tsx
File metadata and controls
87 lines (80 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { SearchInput } from '@/components/common'
import { useDebounce } from '@uidotdev/usehooks'
import React, { useCallback, useContext, useEffect, useState } from 'react'
import { GlossaryEntriesListContext } from '.'
import { GlossaryEntriesTableList } from './GlossaryEntriesTableList'
import { Tabs } from './Tabs'
import { Toaster } from 'react-hot-toast'
import { LocaleSelect } from './LocaleSelect'
import { ProposeTermModal } from './ProposeTermModal'
export function Table() {
const { setCriteria, request, translationLocales, setQuery, setPage } =
React.useContext(GlossaryEntriesListContext)
const [isOpen, setIsOpen] = React.useState(false)
const [inputValue, setInputValue] = React.useState(
request.query.criteria || ''
)
const [selectedLocale, setSelectedLocale] = React.useState(
request.query.filter_locale || ''
)
const debouncedValue = useDebounce(inputValue, 300)
useEffect(() => {
setCriteria(debouncedValue)
setPage(0)
}, [debouncedValue, setCriteria])
return (
<div className="originals-table">
<div className="flex items-center justify-between mb-16">
<Tabs />
<ProposeTermButton
onClick={() => {
setIsOpen(true)
}}
/>
</div>
<div className="container">
<header className="c-search-bar flex items-center justify-between">
<SearchInput
setFilter={setInputValue}
filter={inputValue}
placeholder="Search for translation"
/>
<LocaleSelect
locales={translationLocales || []}
value={selectedLocale}
onChange={(locale) => {
setSelectedLocale(locale)
setQuery({
...request.query,
filter_locale: locale || undefined,
page: null,
})
}}
/>
</header>
<GlossaryEntriesTableList />
</div>
<ProposeTermModal
isOpen={isOpen}
onClose={() => {
setIsOpen(false)
}}
/>
<Toaster />
</div>
)
}
function ProposeTermButton({ onClick }) {
const { mayCreateTranslationProposals } = useContext(
GlossaryEntriesListContext
)
return (
<button
disabled={!mayCreateTranslationProposals}
onClick={onClick}
className="btn btn-primary btn-m"
>
+ Propose
</button>
)
}