Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Fix: Dates of updates reflect the API's response (#1220)
Browse files Browse the repository at this point in the history
* Updates in notifications are now displayed datewise.
* Updated notification panel for zero updates
  • Loading branch information
shubhamjain2998 committed Apr 17, 2020
1 parent 23c8d6d commit ce0345b
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions src/components/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import axios from 'axios';
function Updates(props) {
const [updates, setUpdates] = useState([]);
const [fetched, setFetched] = useState(false);
let currentDate = new Date();

useEffect(() => {
if (fetched === false) {
Expand All @@ -23,29 +24,51 @@ function Updates(props) {
return (
<React.Fragment>
<div className="updates-header">
<h2>{format(new Date(), 'd MMM')}</h2>
<h2>{format(currentDate, 'd MMM')}</h2>
</div>

<div className="updates">
{updates
.slice(-5)
.reverse()
.map(function (activity, index) {
activity.update = activity.update.replace('\n', '<br/>');
const activityDate = new Date(activity.timestamp * 1000);
const addHeader = () => {
currentDate = activityDate;
return (
<>
{index === 0 ? (
<div className="update">
<h4>No updates yet!</h4>
</div>
) : (
''
)}
<div className="updates-header">
<h2>{format(activityDate, 'd MMM')}</h2>
</div>
</>
);
};
return (
<div key={index} className="update">
<h5>
{formatDistance(
new Date(activity.timestamp * 1000),
new Date()
) + ' ago'}
</h5>
<h4
dangerouslySetInnerHTML={{
__html: activity.update,
}}
></h4>
</div>
<>
{activityDate.getDate() !== currentDate.getDate()
? addHeader()
: ' '}
<div key={index} className="update">
<h5>
{formatDistance(
new Date(activity.timestamp * 1000),
new Date()
) + ' ago'}
</h5>
<h4
dangerouslySetInnerHTML={{
__html: activity.update,
}}
></h4>
</div>
</>
);
})}
</div>
Expand Down

1 comment on commit ce0345b

@vercel
Copy link

@vercel vercel bot commented on ce0345b Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.