David Pomerenke
commited on
Commit
·
b6b84c7
1
Parent(s):
6baf3ad
Store filter state globally
Browse files
frontend/src/App.js
CHANGED
@@ -8,13 +8,23 @@ import WorldMap from './components/WorldMap'
|
|
8 |
import AutoComplete from './components/AutoComplete'
|
9 |
import LanguagePlot from './components/LanguagePlot'
|
10 |
import { Carousel } from 'primereact/carousel'
|
|
|
11 |
|
12 |
function App () {
|
13 |
const [data, setData] = useState(null)
|
14 |
const [loading, setLoading] = useState(true)
|
15 |
const [error, setError] = useState(null)
|
16 |
const [allSuggestions, setAllSuggestions] = useState([])
|
17 |
-
const [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
useEffect(() => {
|
19 |
fetch('/results.json')
|
20 |
.then(response => {
|
@@ -93,7 +103,25 @@ function App () {
|
|
93 |
</p>
|
94 |
<AutoComplete
|
95 |
allSuggestions={allSuggestions}
|
96 |
-
onComplete={item =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
/>
|
98 |
</header>
|
99 |
<main
|
@@ -121,7 +149,11 @@ function App () {
|
|
121 |
maxWidth: 'min(100vw, 800px)'
|
122 |
}}
|
123 |
>
|
124 |
-
<ModelTable
|
|
|
|
|
|
|
|
|
125 |
</div>
|
126 |
<div
|
127 |
style={{
|
@@ -129,7 +161,11 @@ function App () {
|
|
129 |
maxWidth: 'min(100vw, 800px)'
|
130 |
}}
|
131 |
>
|
132 |
-
<LanguageTable
|
|
|
|
|
|
|
|
|
133 |
</div>
|
134 |
<div
|
135 |
style={{
|
|
|
8 |
import AutoComplete from './components/AutoComplete'
|
9 |
import LanguagePlot from './components/LanguagePlot'
|
10 |
import { Carousel } from 'primereact/carousel'
|
11 |
+
import { FilterMatchMode } from 'primereact/api'
|
12 |
|
13 |
function App () {
|
14 |
const [data, setData] = useState(null)
|
15 |
const [loading, setLoading] = useState(true)
|
16 |
const [error, setError] = useState(null)
|
17 |
const [allSuggestions, setAllSuggestions] = useState([])
|
18 |
+
const [languageFilters, setLanguageFilters] = useState({
|
19 |
+
language_name: { value: null, matchMode: FilterMatchMode.EQUALS }, // via global search
|
20 |
+
family: { value: null, matchMode: FilterMatchMode.IN },
|
21 |
+
speakers: { value: null, matchMode: FilterMatchMode.BETWEEN }
|
22 |
+
})
|
23 |
+
const [modelFilters, setModelFilters] = useState({
|
24 |
+
model: { value: null, matchMode: FilterMatchMode.ENDS_WITH }, // via global search
|
25 |
+
type: { value: null, matchMode: FilterMatchMode.IN },
|
26 |
+
size: { value: null, matchMode: FilterMatchMode.BETWEEN }
|
27 |
+
})
|
28 |
useEffect(() => {
|
29 |
fetch('/results.json')
|
30 |
.then(response => {
|
|
|
103 |
</p>
|
104 |
<AutoComplete
|
105 |
allSuggestions={allSuggestions}
|
106 |
+
onComplete={item => {
|
107 |
+
const languageValue =
|
108 |
+
item.type === 'Language' ? item.detail : null
|
109 |
+
const modelValue = item.type === 'Model' ? item.value : null
|
110 |
+
setLanguageFilters(prevFilters => ({
|
111 |
+
...prevFilters,
|
112 |
+
language_name: {
|
113 |
+
value: languageValue,
|
114 |
+
matchMode: FilterMatchMode.EQUALS
|
115 |
+
}
|
116 |
+
}))
|
117 |
+
setModelFilters(prevFilters => ({
|
118 |
+
...prevFilters,
|
119 |
+
model: {
|
120 |
+
value: modelValue,
|
121 |
+
matchMode: FilterMatchMode.ENDS_WITH
|
122 |
+
}
|
123 |
+
}))
|
124 |
+
}}
|
125 |
/>
|
126 |
</header>
|
127 |
<main
|
|
|
149 |
maxWidth: 'min(100vw, 800px)'
|
150 |
}}
|
151 |
>
|
152 |
+
<ModelTable
|
153 |
+
data={data}
|
154 |
+
filters={modelFilters}
|
155 |
+
setFilters={setModelFilters}
|
156 |
+
/>
|
157 |
</div>
|
158 |
<div
|
159 |
style={{
|
|
|
161 |
maxWidth: 'min(100vw, 800px)'
|
162 |
}}
|
163 |
>
|
164 |
+
<LanguageTable
|
165 |
+
data={data}
|
166 |
+
filters={languageFilters}
|
167 |
+
setFilters={setLanguageFilters}
|
168 |
+
/>
|
169 |
</div>
|
170 |
<div
|
171 |
style={{
|
frontend/src/components/AutoComplete.js
CHANGED
@@ -44,7 +44,7 @@ const AutoComplete = ({ allSuggestions, onComplete }) => {
|
|
44 |
onChange={e => setAutoComplete(e.value)}
|
45 |
onSelect={e => {
|
46 |
setAutoComplete(e.value.value)
|
47 |
-
onComplete(e.value
|
48 |
}}
|
49 |
suggestions={suggestions}
|
50 |
completeMethod={search}
|
|
|
44 |
onChange={e => setAutoComplete(e.value)}
|
45 |
onSelect={e => {
|
46 |
setAutoComplete(e.value.value)
|
47 |
+
onComplete(e.value)
|
48 |
}}
|
49 |
suggestions={suggestions}
|
50 |
completeMethod={search}
|
frontend/src/components/LanguageTable.js
CHANGED
@@ -6,12 +6,7 @@ import { useState, useEffect } from 'react'
|
|
6 |
import { Slider } from 'primereact/slider'
|
7 |
import ScoreField from './ScoreField'
|
8 |
|
9 |
-
const LanguageTable = ({ data }) => {
|
10 |
-
const [filters, setFilters] = useState({
|
11 |
-
language_name: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
12 |
-
family: { value: null, matchMode: FilterMatchMode.IN },
|
13 |
-
speakers: { value: null, matchMode: FilterMatchMode.BETWEEN },
|
14 |
-
})
|
15 |
const table = data.language_table
|
16 |
|
17 |
const families = [...new Set(table.map(item => item.family))].slice(0, 10)
|
|
|
6 |
import { Slider } from 'primereact/slider'
|
7 |
import ScoreField from './ScoreField'
|
8 |
|
9 |
+
const LanguageTable = ({ data, filters, setFilters }) => {
|
|
|
|
|
|
|
|
|
|
|
10 |
const table = data.language_table
|
11 |
|
12 |
const families = [...new Set(table.map(item => item.family))].slice(0, 10)
|
frontend/src/components/ModelTable.js
CHANGED
@@ -7,13 +7,7 @@ import Medal from './Medal'
|
|
7 |
import { Slider } from 'primereact/slider'
|
8 |
import ScoreField from './ScoreField'
|
9 |
|
10 |
-
const ModelTable = ({ data }) => {
|
11 |
-
const [filters, setFilters] = useState({
|
12 |
-
provider: { value: null, matchMode: FilterMatchMode.IN },
|
13 |
-
model: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
14 |
-
type: { value: null, matchMode: FilterMatchMode.IN },
|
15 |
-
size: { value: null, matchMode: FilterMatchMode.BETWEEN }
|
16 |
-
})
|
17 |
const table = data.model_table
|
18 |
const rankBodyTemplate = rowData => {
|
19 |
return <Medal rank={rowData.rank} />
|
|
|
7 |
import { Slider } from 'primereact/slider'
|
8 |
import ScoreField from './ScoreField'
|
9 |
|
10 |
+
const ModelTable = ({ data, filters, setFilters }) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
const table = data.model_table
|
12 |
const rankBodyTemplate = rowData => {
|
13 |
return <Medal rank={rowData.rank} />
|