[WIP] Implement sticky date separators
This commit is contained in:
parent
0e876fd213
commit
84c696de2e
1 changed files with 2 additions and 32 deletions
|
@ -15,44 +15,14 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
|
||||||
import DateUtils from 'matrix-react-sdk/lib/DateUtils';
|
import DateUtils from 'matrix-react-sdk/lib/DateUtils';
|
||||||
import { Sticky } from 'react-sticky';
|
import { Sticky } from 'react-sticky';
|
||||||
|
|
||||||
function getdaysArray() {
|
|
||||||
return [
|
|
||||||
_t('Sunday'),
|
|
||||||
_t('Monday'),
|
|
||||||
_t('Tuesday'),
|
|
||||||
_t('Wednesday'),
|
|
||||||
_t('Thursday'),
|
|
||||||
_t('Friday'),
|
|
||||||
_t('Saturday'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'DateSeparator',
|
displayName: 'DateSeparator',
|
||||||
render: function() {
|
render: function() {
|
||||||
var date = new Date(this.props.ts);
|
const date = new Date(this.props.ts);
|
||||||
var today = new Date();
|
const label = DateUtils.formatDateSeparator(date);
|
||||||
var yesterday = new Date();
|
|
||||||
var days = getdaysArray();
|
|
||||||
yesterday.setDate(today.getDate() - 1);
|
|
||||||
var label;
|
|
||||||
if (date.toDateString() === today.toDateString()) {
|
|
||||||
label = _t('Today');
|
|
||||||
}
|
|
||||||
else if (date.toDateString() === yesterday.toDateString()) {
|
|
||||||
label = _t('Yesterday');
|
|
||||||
}
|
|
||||||
else if (today.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
|
|
||||||
label = days[date.getDay()];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
label = DateUtils.formatFullDate(date, this.props.showTwelveHour);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sticky relative={true} disableCompensation={true}>
|
<Sticky relative={true} disableCompensation={true}>
|
||||||
{({style, isSticky, wasSticky, distanceFromTop}) => {
|
{({style, isSticky, wasSticky, distanceFromTop}) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue