diff --git a/containers/projects/component.js b/containers/projects/component.js index 4689ea1..eee78c9 100644 --- a/containers/projects/component.js +++ b/containers/projects/component.js @@ -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' @@ -96,6 +97,7 @@ width: 100%; ` class Projects extends Component { + constructor(props) { super(props) this.state = { @@ -125,7 +127,6 @@ class Projects extends Component { return encodeURIComponent(key) + '=' + encodeURIComponent(sort[key]) }).join('&'); - console.log(theQuery) return theQuery } @@ -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) => { @@ -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 } }) @@ -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) => { @@ -223,8 +239,8 @@ class Projects extends Component { {query.closed === null && this.toggleSort('closed', true)}>TODOS} {query.closed === true && this.toggleSort('closed', false)}>FINALIZADOS} {query.closed === false && this.toggleSort('closed', null)}>ABIERTOS} - Por etiqueta - this.toggleSort('tag', tagId)} /> + Por etiqueta + {tags.length > 0 && this.toggleSort('tag', tagId)} />} {projects && @@ -254,4 +270,4 @@ class Projects extends Component { } } -export default WithDocumentTagsContext(Projects) +export default withRouter(WithDocumentTagsContext(Projects)) diff --git a/elements/tags-select/component.js b/elements/tags-select/component.js index 769121f..21365b1 100644 --- a/elements/tags-select/component.js +++ b/elements/tags-select/component.js @@ -13,14 +13,15 @@ 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( @@ -28,9 +29,12 @@ class TagsSelect extends Component { ) }) } - + */ + 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) @@ -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...'} @@ -54,4 +58,5 @@ class TagsSelect extends Component { } } -export default WithDocumentTagsContext(TagsSelect) +//export default WithDocumentTagsContext(TagsSelect) +export default TagsSelect \ No newline at end of file diff --git a/static/assets/images/ambiente.jpg b/static/assets/images/ambiente.jpg index 593d702..98a7b43 100644 Binary files a/static/assets/images/ambiente.jpg and b/static/assets/images/ambiente.jpg differ