Skip to content

Commit

Permalink
Merge pull request #257 from surpassinggoogle/feature/ulog-stories-bu…
Browse files Browse the repository at this point in the history
…g-fix

Add 3-day Filter to Ulog Stories; Remove noUsers Check
  • Loading branch information
eastmaels committed Apr 19, 2019
2 parents e513c08 + 309e82e commit f6c1128
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/client/components/Sidebar/UlogStories.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class UlogStories extends React.Component {
ulogStoriesObj: {},
ulogStoriesArr: [],
loading: true,
noUsers: false,
showModalLogin: false,
displayStories: 0,
};
Expand Down Expand Up @@ -104,10 +103,20 @@ class UlogStories extends React.Component {
.then(result => {
const posts = Array.isArray(result) ? result : [];
const post = posts[0];
this.setState({
loading: false,
});

// filter-out posts from non-certified users
if(certifiedUloggerNames.indexOf(post.author) < 0) return;

// filter posts that have been created more than 3 days ago
const today = new Date();
const threeDaysAgo = new Date();
threeDaysAgo.setDate(today.getDate() - 3);
const created = new Date(post.created);
if(created < threeDaysAgo) return;

// Add 'ulog' and 'ulogs' as valid ulog story tags
ulogStoriesTags.push('ulog', 'ulogs');
// filter posts that do not contain valid ulog tags
Expand All @@ -134,8 +143,6 @@ class UlogStories extends React.Component {
// set loading and no users to false to display ulog stories
this.setState({
ulogStoriesArr,
loading: false,
noUsers: false,
});
});

Expand All @@ -144,16 +151,7 @@ class UlogStories extends React.Component {
// set the initial list to display the first 5 ulog stories
this.setState({ displayStories: 5 });

} else {
this.setState({
noUsers: true,
});
}
})
.catch(() => {
this.setState({
noUsers: true,
});
});
}

Expand All @@ -170,7 +168,7 @@ class UlogStories extends React.Component {
};

render() {
const { ulogStoriesArr, loading, noUsers, showModalLogin, displayStories } = this.state;
const { ulogStoriesArr, loading, showModalLogin, displayStories } = this.state;
// sort ulog stories by descending created date
ulogStoriesArr.sort((a, b) => {
var keyA = new Date(a.created),
Expand All @@ -185,10 +183,6 @@ class UlogStories extends React.Component {
const hasMoreStories = (displayStories < ulogStoriesArr.length);
const next = location.pathname.length > 1 ? location.pathname : '';

if (noUsers) {
return <div />;
}

if (loading) {
return <Loading />;
}
Expand Down

0 comments on commit f6c1128

Please sign in to comment.