summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKamran Ahmed <kamranahmed.se@gmail.com>2018-08-27 23:14:08 +0500
committerKamran Ahmed <kamranahmed.se@gmail.com>2018-08-27 23:14:08 +0500
commit16873dad5bc3989a5cef561bdc31c9ddcda63029 (patch)
treeb1000a759765ba606055364f911c7fc46874920b /src
parentAdd dynamic group headings (diff)
downloadgithunt-16873dad5bc3989a5cef561bdc31c9ddcda63029.tar.gz
Load next batch and group headings
Diffstat (limited to 'src')
-rw-r--r--src/components/group-heading/index.js12
-rw-r--r--src/components/repository-grid/index.js9
-rw-r--r--src/components/repository-list/index.js9
-rw-r--r--src/containers/feed/index.js14
-rw-r--r--src/containers/feed/styles.css6
-rw-r--r--src/redux/github/actions.js9
6 files changed, 47 insertions, 12 deletions
diff --git a/src/components/group-heading/index.js b/src/components/group-heading/index.js
index 762d36d..2ba89a2 100644
--- a/src/components/group-heading/index.js
+++ b/src/components/group-heading/index.js
@@ -10,7 +10,7 @@ class GroupHeading extends React.Component {
const currentMoment = moment();
const yesterdayMoment = moment().subtract(1, 'day');
- // For "day" jumps show the day name
+ // For "day" jumps return the day name
if (this.props.dateJump === 'day') {
if (startMoment.isSame(currentMoment, 'day')) {
return 'Today';
@@ -21,14 +21,20 @@ class GroupHeading extends React.Component {
return startMoment.format('dddd');
}
- return startMoment.fromNow();
+ // Return the relative date
+ const formattedDate = startMoment.fromNow();
+ if (formattedDate === 'a year ago') {
+ return 'Last Year';
+ }
+
+ return formattedDate;
}
getSubtitle() {
const startMoment = moment(this.props.start);
const endMoment = moment(this.props.end);
- if (startMoment.isSame(endMoment, 'day')) {
+ if (startMoment.isSame(endMoment, 'day') || this.props.dateJump === 'day') {
return startMoment.format('MMMM D, YYYY');
}
diff --git a/src/components/repository-grid/index.js b/src/components/repository-grid/index.js
index d99a38f..8413a8e 100644
--- a/src/components/repository-grid/index.js
+++ b/src/components/repository-grid/index.js
@@ -13,7 +13,11 @@ class RepositoryGrid extends React.Component {
if (counter !== 0) {
groupHeading = (
<div className="row row-group">
- <GroupHeading/>
+ <GroupHeading
+ start={ repositoryGroup.start }
+ end={ repositoryGroup.end }
+ dateJump={ this.props.dateJump }
+ />
</div>
);
}
@@ -45,7 +49,8 @@ class RepositoryGrid extends React.Component {
}
RepositoryGrid.propTypes = {
- repositories: PropTypes.array.isRequired
+ repositories: PropTypes.array.isRequired,
+ dateJump: PropTypes.string.isRequired
};
export default RepositoryGrid;
diff --git a/src/components/repository-list/index.js b/src/components/repository-list/index.js
index be6cc76..862df11 100644
--- a/src/components/repository-list/index.js
+++ b/src/components/repository-list/index.js
@@ -15,7 +15,11 @@ class RepositoryList extends React.Component {
if (counter !== 0) {
groupHeading = (
<div className="row row-group">
- <GroupHeading/>
+ <GroupHeading
+ start={ repositoryGroup.start }
+ end={ repositoryGroup.end }
+ dateJump={ this.props.dateJump }
+ />
</div>
);
}
@@ -47,7 +51,8 @@ class RepositoryList extends React.Component {
}
RepositoryGrid.propTypes = {
- repositories: PropTypes.array.isRequired
+ repositories: PropTypes.array.isRequired,
+ dateJump: PropTypes.string.isRequired
};
export default RepositoryList;
diff --git a/src/containers/feed/index.js b/src/containers/feed/index.js
index 6121ec5..d39da28 100644
--- a/src/containers/feed/index.js
+++ b/src/containers/feed/index.js
@@ -107,11 +107,21 @@ class FeedContainer extends React.Component {
<div className="body-row">
{
this.props.preference.viewType === 'grid'
- ? <RepositoryGrid repositories={ this.props.github.repositories || [] }/>
- : <RepositoryList repositories={ this.props.github.repositories || [] }/>
+ ? <RepositoryGrid repositories={ this.props.github.repositories || [] } dateJump={ this.props.preference.dateJump }/>
+ : <RepositoryList repositories={ this.props.github.repositories || [] } dateJump={ this.props.preference.dateJump }/>
}
{ this.props.github.processing && <Loader/> }
+
+ {
+ !this.props.github.processing && (
+ <button className="btn btn-primary shadow load-next-date"
+ onClick={ () => this.fetchNextRepositories() }>
+ <i className="fa fa-refresh mr-2"></i>
+ Load next { this.props.preference.dateJump }
+ </button>
+ )
+ }
</div>
</div>
</div>
diff --git a/src/containers/feed/styles.css b/src/containers/feed/styles.css
index 9d43a7b..8ab4795 100644
--- a/src/containers/feed/styles.css
+++ b/src/containers/feed/styles.css
@@ -29,3 +29,9 @@
.row-group .group-heading {
margin: auto;
}
+
+.load-next-date {
+ padding: 10px 20px;
+ display: block;
+ margin: 25px auto auto;
+}
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js
index c61fd50..5474144 100644
--- a/src/redux/github/actions.js
+++ b/src/redux/github/actions.js
@@ -1,4 +1,5 @@
import axios from 'axios';
+import moment from 'moment';
import {
FETCH_TRENDING_FAILED,
@@ -12,7 +13,9 @@ const API_URL = 'https://api.github.com/search/repositories';
const transformFilters = (filters) => {
const transformedFilters = {};
- const reposDate = `created:${filters.dateRange.start.format('YYYY-MM-DD')}..${filters.dateRange.end.format('YYYY-MM-DD')}`;
+ const startMoment = moment(filters.dateRange.start);
+ const endMoment = moment(filters.dateRange.end);
+ const reposDate = `created:${startMoment.format('YYYY-MM-DD')}..${endMoment.format('YYYY-MM-DD')}`;
const reposLanguage = filters.language ? `language:${filters.language} ` : '';
if (filters.token) {
@@ -40,8 +43,8 @@ export const fetchTrending = function (filters) {
dispatch({
type: FETCH_TRENDING_SUCCESS,
payload: {
- start: filters.dateRange.start.format(),
- end: filters.dateRange.end.format(),
+ start: moment(filters.dateRange.start).format(),
+ end: moment(filters.dateRange.end).format(),
data: response.data
}
});