Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3-day Filter to Ulog Stories; Remove noUsers Check #257

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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