Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
7c67cb59
Commit
7c67cb59
authored
7 years ago
by
Nolan Lawson
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
implement shouldComponentUpdate for relative_timestamp (#3320)
parent
a098d08d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/javascript/mastodon/components/relative_timestamp.js
+33
-12
33 additions, 12 deletions
app/javascript/mastodon/components/relative_timestamp.js
with
33 additions
and
12 deletions
app/javascript/mastodon/components/relative_timestamp.js
+
33
−
12
View file @
7c67cb59
...
...
@@ -2,19 +2,40 @@ import React from 'react';
import
{
injectIntl
,
FormattedRelative
}
from
'
react-intl
'
;
import
PropTypes
from
'
prop-types
'
;
const
RelativeTimestamp
=
({
intl
,
timestamp
})
=>
{
const
date
=
new
Date
(
timestamp
);
return
(
<
time
dateTime
=
{
timestamp
}
title
=
{
intl
.
formatDate
(
date
,
{
hour12
:
false
,
year
:
'
numeric
'
,
month
:
'
short
'
,
day
:
'
2-digit
'
,
hour
:
'
2-digit
'
,
minute
:
'
2-digit
'
})}
>
<
FormattedRelative
value
=
{
date
}
/
>
<
/time
>
);
const
dateFormatOptions
=
{
hour12
:
false
,
year
:
'
numeric
'
,
month
:
'
short
'
,
day
:
'
2-digit
'
,
hour
:
'
2-digit
'
,
minute
:
'
2-digit
'
,
};
RelativeTimestamp
.
propTypes
=
{
intl
:
PropTypes
.
object
.
isRequired
,
timestamp
:
PropTypes
.
string
.
isRequired
,
};
class
RelativeTimestamp
extends
React
.
Component
{
static
propTypes
=
{
intl
:
PropTypes
.
object
.
isRequired
,
timestamp
:
PropTypes
.
string
.
isRequired
,
};
shouldComponentUpdate
(
nextProps
)
{
// As of right now the locale doesn't change without a new page load,
// but we might as well check in case that ever changes.
return
this
.
props
.
timestamp
!==
nextProps
.
timestamp
||
this
.
props
.
intl
.
locale
!==
nextProps
.
intl
.
locale
;
}
render
()
{
const
{
timestamp
,
intl
}
=
this
.
props
;
const
date
=
new
Date
(
timestamp
);
return
(
<
time
dateTime
=
{
timestamp
}
title
=
{
intl
.
formatDate
(
date
,
dateFormatOptions
)}
>
<
FormattedRelative
value
=
{
date
}
/
>
<
/time
>
);
}
}
export
default
injectIntl
(
RelativeTimestamp
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment