Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/components/ItemKeywords.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Box, makeStyles } from '@material-ui/core';
import Chip from '@material-ui/core/Chip'
import { secondary, themeVariables } from '../theme'
import keywordDuck from '../redux/keywordDuck'
import { useDispatch } from 'react-redux'

const useStyles = makeStyles((theme) => ({
root: {
Expand All @@ -18,29 +20,31 @@ const useStyles = makeStyles((theme) => ({
}));

const ItemKeywords = (props) => {
const dispatch = useDispatch()

const handleSelect = (keyword) => {
dispatch(keywordDuck.actions.setKeyword(keyword))
}

const classes = useStyles()
if (!props.data) {
return (
<Box></Box>
)
} else {
return (
<Box component="ul" className={classes.root}>
{props.data.map((keyword, index) => {
return (
<li key={index}>
return (
props.data &&
<Box component="ul" className={classes.root}>
{props.data.map((keyword, index) => {
return (
<li key={index}>
<Chip
className={classes.chip}
label={keyword}
clickable
size='small'
clickable={true}
onClick={() => handleSelect(keyword)}
/>
</li>
)}
</li>
)}
</Box>
)
}

)}
</Box>
)
}

export default ItemKeywords
22 changes: 17 additions & 5 deletions src/containers/ReactiveSearchContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DataSearch } from '@appbaseio/reactivesearch';
import { useSelector } from 'react-redux'

import { getMapBoundsDebounced } from '../redux/mapSelector'
import { getActiveFilters, getDataType } from '../redux/filterSelector'
import { getActiveFilters, getDataType, keywords } from '../redux/filterSelector'
import useDebounce from '../hooks/useDebounce'


Expand All @@ -12,9 +12,20 @@ function ReactiveSearchContainer () {
const bbox = useSelector(getMapBoundsDebounced)
const dataFilter = useSelector(getDataType)
const dbbox = useDebounce(bbox, 800)

const keyword = useSelector(keywords)
const extensions = useSelector(getActiveFilters)

const [qValue, setqValue] = React.useState('')

React.useEffect(()=>{
setqValue(keyword)
}, [keyword])

const handleChange = (value, triggerQuery) => {
setqValue(value)
triggerQuery()
}

const geoQuery = (value) => {
let query = {
query: {
Expand Down Expand Up @@ -71,12 +82,11 @@ function ReactiveSearchContainer () {
}
}
}

return query
}

return (
<DataSearch
<DataSearch
customQuery={geoQuery}
dataField={[
'properties.title',
Expand All @@ -96,8 +106,10 @@ function ReactiveSearchContainer () {
innerClass={{
input: 'form-search',
}}
value={qValue}
onChange={handleChange}
// onKeyPress={handleKey}
/>

)
}

Expand Down
1 change: 1 addition & 0 deletions src/redux/filterSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit'

export const filters = state => state.filters
export const formatFilter = state => state.dataType
export const keywords = state => state.keywords.keywords

export const getFilters = createSelector([filters], filter => {
return filter
Expand Down
24 changes: 24 additions & 0 deletions src/redux/keywordDuck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createSlice } from '@reduxjs/toolkit'

const initialState = {
keywords: ''
}

function setKeyword(state, action) {
const { payload } = action

return {
...state,
keywords: payload
}
}

const keywords = createSlice({
name: 'keywords',
initialState,
reducers: {
setKeyword
}
})

export default keywords
2 changes: 2 additions & 0 deletions src/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { combineReducers } from 'redux'
import mapDuck from './mapDuck'
import filterDuck from './filterDuck'
import dataTypeDuck from './dataTypeDuck'
import keywordDuck from './keywordDuck'

const reducer = combineReducers({
map: mapDuck.reducer,
filters: filterDuck.reducer,
dataType: dataTypeDuck.reducer,
keywords: keywordDuck.reducer
})

const store = configureStore({
Expand Down