From 4acd1873f51fb319f313648a767fac4dbf3399f9 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sat, 25 Aug 2018 12:08:34 +0500 Subject: Date type filter in top nav --- src/components/repository-grid/index.js | 2 ++ src/components/repository-grid/styles.css | 4 +++ src/components/top-nav/index.js | 51 +++++++++++++++++++++++++++++-- src/components/top-nav/styles.css | 1 + src/containers/feed/index.js | 10 ++++-- src/containers/feed/styles.css | 4 --- src/redux/preference/actions.js | 11 ++++++- src/redux/preference/reducer.js | 8 ++++- src/redux/preference/types.js | 1 + 9 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 src/components/repository-grid/styles.css (limited to 'src') diff --git a/src/components/repository-grid/index.js b/src/components/repository-grid/index.js index 8b9a276..78c8dfc 100644 --- a/src/components/repository-grid/index.js +++ b/src/components/repository-grid/index.js @@ -1,5 +1,7 @@ import React from 'react'; + import GridItem from './grid-item'; +import './styles.css'; class RepositoryGrid extends React.Component { render() { diff --git a/src/components/repository-grid/styles.css b/src/components/repository-grid/styles.css new file mode 100644 index 0000000..ddda54a --- /dev/null +++ b/src/components/repository-grid/styles.css @@ -0,0 +1,4 @@ +.grid-container { + margin-top: 20px; + padding: 0 5px; +} diff --git a/src/components/top-nav/index.js b/src/components/top-nav/index.js index 24f0747..7f36321 100644 --- a/src/components/top-nav/index.js +++ b/src/components/top-nav/index.js @@ -1,4 +1,7 @@ import React from 'react'; +import PropTypes from 'prop-types'; +import classNames from 'classnames'; + import './styles.css'; const TopNav = (props) => ( @@ -12,12 +15,54 @@ const TopNav = (props) => (
- Weekly - Monthly - Daily + props.updateDateType('yearly') } + className={ + classNames('btn', { + 'btn-primary': props.selectedDateType === 'yearly', + 'btn-light': props.selectedDateType !== 'yearly', + }) + }> + Yearly + + props.updateDateType('monthly') } + className={ + classNames('btn', { + 'btn-primary': props.selectedDateType === 'monthly', + 'btn-light': props.selectedDateType !== 'monthly', + }) + }> + Monthly + + props.updateDateType('weekly') } + className={ + classNames('btn', { + 'btn-primary': props.selectedDateType === 'weekly', + 'btn-light': props.selectedDateType !== 'weekly', + }) + }> + Weekly + + props.updateDateType('daily') } + className={ + classNames('btn', { + 'btn-primary': props.selectedDateType === 'daily', + 'btn-light': props.selectedDateType !== 'daily', + }) + }> + Daily +
); +TopNav.propTypes = { + updateDateType: PropTypes.func.isRequired, + selectedDateType: PropTypes.string +}; + export default TopNav; diff --git a/src/components/top-nav/styles.css b/src/components/top-nav/styles.css index c91d753..15230f8 100644 --- a/src/components/top-nav/styles.css +++ b/src/components/top-nav/styles.css @@ -34,5 +34,6 @@ .duration-btns a.btn { margin-left: 10px; margin-top: 24px; + box-shadow: none; } diff --git a/src/containers/feed/index.js b/src/containers/feed/index.js index 12441ee..224d5b8 100644 --- a/src/containers/feed/index.js +++ b/src/containers/feed/index.js @@ -5,14 +5,17 @@ import './styles.css'; import TopNav from '../../components/top-nav'; import Filters from '../../components/filters'; import RepositoryGrid from '../../components/repository-grid'; -import { updateLanguage, updateViewType } from '../../redux/preference/actions'; import RepositoryList from '../../components/repository-list'; +import { updateDateType, updateLanguage, updateViewType } from '../../redux/preference/actions'; class FeedContainer extends React.Component { render() { return (
- +
@@ -45,7 +48,8 @@ const mapStateToProps = store => { const mapDispatchToProps = { updateLanguage, - updateViewType + updateViewType, + updateDateType }; export default connect(mapStateToProps, mapDispatchToProps)(FeedContainer); diff --git a/src/containers/feed/styles.css b/src/containers/feed/styles.css index 11fbe5d..9d43a7b 100644 --- a/src/containers/feed/styles.css +++ b/src/containers/feed/styles.css @@ -22,10 +22,6 @@ float: right; } -.grid-container { - margin-top: 20px; -} - .row-group { margin-top: 35px; } diff --git a/src/redux/preference/actions.js b/src/redux/preference/actions.js index 3183b81..8f115c0 100644 --- a/src/redux/preference/actions.js +++ b/src/redux/preference/actions.js @@ -1,4 +1,4 @@ -import { UPDATE_LANGUAGE, UPDATE_OPTIONS, UPDATE_VIEW_TYPE } from './types'; +import { UPDATE_DATE_TYPE, UPDATE_LANGUAGE, UPDATE_OPTIONS, UPDATE_VIEW_TYPE } from './types'; export const updateOptions = function (setting) { return dispatch => { @@ -26,3 +26,12 @@ export const updateLanguage = function (language) { }); }; }; + +export const updateDateType = function (dateType) { + return dispatch => { + dispatch({ + type: UPDATE_DATE_TYPE, + payload: dateType + }); + }; +}; diff --git a/src/redux/preference/reducer.js b/src/redux/preference/reducer.js index 8c1819f..dfdec5c 100644 --- a/src/redux/preference/reducer.js +++ b/src/redux/preference/reducer.js @@ -1,7 +1,8 @@ -import { RESET_OPTIONS, UPDATE_LANGUAGE, UPDATE_OPTIONS, UPDATE_VIEW_TYPE } from './types'; +import { RESET_OPTIONS, UPDATE_DATE_TYPE, UPDATE_LANGUAGE, UPDATE_OPTIONS, UPDATE_VIEW_TYPE } from './types'; const initialState = { viewType: 'grid', + dateType: 'weekly', language: '', options: { token: '', @@ -20,6 +21,11 @@ export default function reducer(state = initialState, action) { ...state, options: initialState.options }; + case UPDATE_DATE_TYPE: + return { + ...state, + dateType: action.payload + }; case UPDATE_VIEW_TYPE: return { ...state, diff --git a/src/redux/preference/types.js b/src/redux/preference/types.js index 9874e13..e5e52a4 100644 --- a/src/redux/preference/types.js +++ b/src/redux/preference/types.js @@ -1,4 +1,5 @@ export const UPDATE_OPTIONS = 'UPDATE_OPTIONS'; export const RESET_OPTIONS = 'RESET_OPTIONS'; export const UPDATE_VIEW_TYPE = 'UPDATE_VIEW_TYPE'; +export const UPDATE_DATE_TYPE = 'UPDATE_DATE_TYPE'; export const UPDATE_LANGUAGE = 'UPDATE_LANGUAGE'; -- cgit v1.3