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

Implement sticky date separators #4939

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"react-dnd-html5-backend": "^2.1.2",
"react-dom": "^15.6.0",
"react-gemini-scrollbar": "matrix-org/react-gemini-scrollbar#5e97aef",
"react-sticky": "^6.0.1",
"sanitize-html": "^1.11.1",
"text-encoding-utf-8": "^1.0.1",
"ua-parser-js": "^0.7.10",
Expand Down
49 changes: 15 additions & 34 deletions src/components/views/messages/DateSeparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,26 @@ limitations under the License.
*/

import React from 'react';
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import DateUtils from 'matrix-react-sdk/lib/DateUtils';

function getdaysArray() {
return [
_t('Sunday'),
_t('Monday'),
_t('Tuesday'),
_t('Wednesday'),
_t('Thursday'),
_t('Friday'),
_t('Saturday'),
];
}
import { Sticky } from 'react-sticky';

module.exports = React.createClass({
displayName: 'DateSeparator',
render: function() {
var date = new Date(this.props.ts);
var today = new 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);
}

const date = new Date(this.props.ts);
const label = DateUtils.formatDateSeparator(date);
return (
<h2 className="mx_DateSeparator">{ label }</h2>
<Sticky relative={true} disableCompensation={true}>
{({style, isSticky, wasSticky, distanceFromTop}) => {
return (
<div className={"mx_DateSeparator_container mx_DateSeparator_container" + (isSticky ? '_sticky' : '')}
style={{top: isSticky ? -distanceFromTop + "px" : 0}}
>
<h2 className="mx_DateSeparator">{ label }</h2>
</div>
);
}}
</Sticky>
);
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ limitations under the License.

.mx_DateSeparator {
clear: both;
margin-top: 32px;
margin-bottom: 8px;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 63px;
padding-top: 5px;
padding-bottom: 6px;
border-bottom: 1px solid $primary-hairline-color;
}

.mx_DateSeparator_container {
margin-top: 27px;
margin-bottom: 8px;
background-color: $primary-bg-color;
z-index: 3;
}

.mx_DateSeparator_container_sticky {
position: relative;
border-bottom: 1px solid $primary-hairline-color;
}

.mx_DateSeparator_container_sticky .mx_DateSeparator {
border: 0px;
}