frontend/src/containers/Results.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-12-13 19:04:55 +02:00
import React from 'react';
2018-12-19 18:08:22 +02:00
import Grid from "react-css-grid";
import VideoItem from "../components/VideoItem";
import PropTypes from "prop-types";
import {getSearchResults} from "../actions/search";
import connect from "react-redux/es/connect/connect";
2018-12-13 19:04:55 +02:00
class Results extends React.Component {
componentDidMount() {
2018-12-19 18:08:22 +02:00
// get params from url
2018-12-13 19:04:55 +02:00
const categoryKey = this.props.match.params.categoryKey;
const searchValue = this.props.match.params.searchValue;
2018-12-19 18:08:22 +02:00
console.log(categoryKey)
console.log(searchValue)
2018-12-13 19:04:55 +02:00
}
render() {
return (
2018-12-19 18:08:22 +02:00
<Grid className="random-topics"
width={220}
gap={12}>
{this.props.searchResults.map(video =>
<VideoItem id={video.id} key={video.id} title={video.title}/>
)}
</Grid>
2018-12-13 19:04:55 +02:00
);
}
}
const mapStateToProps = state => ({
searchResults: this.state.results.currentItems,
2018-12-19 18:08:22 +02:00
currentKey: this.state.results.currentKey,
currentValue: this.state.results.currentValue,
currentQuery: this.state.results.queryParams
2018-12-13 19:04:55 +02:00
});
const mapDispatchToProps = dispatch => ({
2018-12-19 18:08:22 +02:00
// the category key is either {topic, date, date}
// the search value could be something like 25th-jan.
getSearchResults: (categoryKey, searchValue) => dispatch(getSearchResults(categoryKey, searchValue)),
2018-12-13 19:04:55 +02:00
});
2018-12-19 18:08:22 +02:00
// each result page has :
// - currentKey: 858.ma/{key}/ where key could be like 'topic'
// - currentValue: 858.ma/topic/{value} where value could be like 'alaa abd al fatah'
// - currentQuery: 858.ma/{query} ?? not getting this! @TODO: clarify this please.
// - currentItems: the list of items/videos.
Results.propTypes = {
// the category key is either a {topic, location, date}.
currentKey: PropTypes.string,
currentValue: PropTypes.string,
currentItems: PropTypes.array,
loading: PropTypes.bool,
categoryItemCount: PropTypes.number,
getSearchResults: PropTypes.func
};
export default connect(mapStateToProps, mapDispatchToProps)(Results);