Skip to content

Commit

Permalink
Merge pull request #120 from DemocraciaEnRed/develop
Browse files Browse the repository at this point in the history
Ready for 1.9.3
  • Loading branch information
guillecro authored Apr 22, 2021
2 parents 32f5c26 + e525c88 commit 0d44a9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
28 changes: 22 additions & 6 deletions containers/projects/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TitleH2 from '../../elements/title-h2/component'
import SubtitleH3 from '../../elements/subtitle-h3/component'
import Button from '../../elements/button/component'
import getConfig from 'next/config'
import router, {withRouter} from 'next/router'
import Masonry from 'react-masonry-component';
import TagsSelect from '../../elements/tags-select/component.js'
import WithDocumentTagsContext from '../../components/document-tags-context/component'
Expand Down Expand Up @@ -96,6 +97,7 @@ width: 100%;
`

class Projects extends Component {

constructor(props) {
super(props)
this.state = {
Expand Down Expand Up @@ -125,7 +127,6 @@ class Projects extends Component {
return encodeURIComponent(key) + '=' +
encodeURIComponent(sort[key])
}).join('&');
console.log(theQuery)
return theQuery
}

Expand All @@ -140,7 +141,12 @@ class Projects extends Component {
}

async fetchDocuments() {
let query = this.createQuery(this.state.query);
let tag = this.props.router.query.tag;
let currentQuery = {...this.state.query};
currentQuery.tag = tag;

let query = this.createQuery(currentQuery);

const projects = await (await fetch(`${API_URL}/api/v1/documents${query}`)).json()
// let mergedProjects = this.state.projects.concat(projects.results)
// const projectsFiltered = mergedProjects.filter((p) => {
Expand All @@ -156,7 +162,10 @@ class Projects extends Component {
projects: prevState.projects.concat(projects.results),
// projectsFiltered: projects.results,
loadMoreAvailable: projects.pagination.page < projects.pagination.pages,
query: query,
query: {
...query,
tag
},
loading: false
}
})
Expand Down Expand Up @@ -185,6 +194,13 @@ class Projects extends Component {
}, () => {
this.getDocuments()
})
let tag = newQuery["tag"]
if(tag){
router.push({
pathname: this.props.router.pathname,
query: {tag}
})
}
}

// toggleFilter = (parameter, value) => {
Expand Down Expand Up @@ -223,8 +239,8 @@ class Projects extends Component {
{query.closed === null && <OptionChoice onClick={() => this.toggleSort('closed', true)}>TODOS</OptionChoice>}
{query.closed === true && <OptionChoice onClick={() => this.toggleSort('closed', false)}>FINALIZADOS</OptionChoice>}
{query.closed === false && <OptionChoice onClick={() => this.toggleSort('closed', null)}>ABIERTOS</OptionChoice>}
<OptionLabel>Por etiqueta</OptionLabel>
<TagsSelect onTagChange={(tagId) => this.toggleSort('tag', tagId)} />
<OptionLabel>Por etiqueta</OptionLabel>
{tags.length > 0 && <TagsSelect allTags={tags} selected={query.tag} onTagChange={(tagId) => this.toggleSort('tag', tagId)} />}
</Options>
{projects &&
<Fragment>
Expand Down Expand Up @@ -254,4 +270,4 @@ class Projects extends Component {
}
}

export default WithDocumentTagsContext(Projects)
export default withRouter(WithDocumentTagsContext(Projects))
17 changes: 11 additions & 6 deletions elements/tags-select/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ const WrapperDiv = styled.div`

class TagsSelect extends Component {
static propTypes = {
onTagChange: PropTypes.func.isRequired
onTagChange: PropTypes.func.isRequired,
selected : PropTypes.string,
}

state = {
allTags: [],
selectedOption: null,
}

/*
async componentWillMount () {
this.setState({
allTags: (await this.props.fetchDocumentTags()).map(
tag => ({ value: tag._id, label: tag.name })
)
})
}

*/
componentDidMount(){
let firstValue = this.props.allTags.find((tag)=>{return tag.value == this.props.selected})
this.setState({selectedOption: firstValue})
}
handleChange = selectedOption => {
//console.log(`Option selected:`, selectedOption);
this.setState(
{ selectedOption },
() => this.props.onTagChange(selectedOption && selectedOption.value)
Expand All @@ -44,7 +48,7 @@ class TagsSelect extends Component {
className='react-select-container'
value={this.state.selectedOption}
onChange={this.handleChange}
options={this.state.allTags}
options={this.props.allTags}
isSearchable={true}
isClearable={true}
placeholder={'Buscar...'}
Expand All @@ -54,4 +58,5 @@ class TagsSelect extends Component {
}
}

export default WithDocumentTagsContext(TagsSelect)
//export default WithDocumentTagsContext(TagsSelect)
export default TagsSelect
Binary file modified static/assets/images/ambiente.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0d44a9a

Please sign in to comment.