mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-09-21 07:28:30 +03:00
Merge pull request #1660 from pkova/master
Update sidebar most recent message timestamp every minute
This commit is contained in:
commit
d5799e20fd
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,15 +1,42 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
export class SidebarItem extends Component {
|
export class SidebarItem extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
timeSinceNewestMessage: this.getTimeSinceNewestMessage()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.updateTimeSinceNewestMessageInterval = setInterval( () => {
|
||||||
|
this.setState({timeSinceNewestMessage: this.getTimeSinceNewestMessage()});
|
||||||
|
}, 60000);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.updateTimeSinceNewestMessageInterval) {
|
||||||
|
clearInterval(this.updateTimeSinceNewestMessageInterval);
|
||||||
|
this.updateTimeSinceNewestMessageInterval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getTimeSinceNewestMessage() {
|
||||||
|
return !!this.props.wen ?
|
||||||
|
moment.unix(this.props.wen / 1000).from(moment.utc())
|
||||||
|
: '';
|
||||||
|
}
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
props.history.push('/~chat/' + props.cir);
|
props.history.push('/~chat/' + props.cir);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props, state } = this;
|
||||||
|
|
||||||
let unreadElem = !!props.unread ? (
|
let unreadElem = !!props.unread ? (
|
||||||
<div
|
<div
|
||||||
@ -29,7 +56,7 @@ export class SidebarItem extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="w-100">
|
<div className="w-100">
|
||||||
<p className='dib gray label-small-mono mr3 lh-16'>{props.ship}</p>
|
<p className='dib gray label-small-mono mr3 lh-16'>{props.ship}</p>
|
||||||
<p className='dib gray label-small-mono lh-16'>{props.datetime}</p>
|
<p className='dib gray label-small-mono lh-16'>{state.timeSinceNewestMessage}</p>
|
||||||
</div>
|
</div>
|
||||||
<p className='label-small gray clamp-3 lh-16 pt1'>{props.description}</p>
|
<p className='label-small gray clamp-3 lh-16 pt1'>{props.description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import moment from 'moment';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { SidebarItem } from '/components/lib/sidebar-item';
|
import { SidebarItem } from '/components/lib/sidebar-item';
|
||||||
@ -122,13 +121,8 @@ export class Sidebar extends Component {
|
|||||||
: 'No messages yet';
|
: 'No messages yet';
|
||||||
let aut = !!msg ? msg.gam.aut : '';
|
let aut = !!msg ? msg.gam.aut : '';
|
||||||
let wen = !!msg ? msg.gam.wen : 0;
|
let wen = !!msg ? msg.gam.wen : 0;
|
||||||
let datetime =
|
|
||||||
!!msg ?
|
|
||||||
moment.unix(wen / 1000).from(moment.utc())
|
|
||||||
: '';
|
|
||||||
return {
|
return {
|
||||||
msg,
|
msg,
|
||||||
datetime,
|
|
||||||
wen,
|
wen,
|
||||||
aut,
|
aut,
|
||||||
content,
|
content,
|
||||||
@ -145,11 +139,11 @@ export class Sidebar extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
key={obj.cir}
|
key={obj.cir + '/' + obj.wen}
|
||||||
title={obj.title}
|
title={obj.title}
|
||||||
description={obj.content}
|
description={obj.content}
|
||||||
cir={obj.cir}
|
cir={obj.cir}
|
||||||
datetime={obj.datetime}
|
wen={obj.wen}
|
||||||
ship={obj.aut}
|
ship={obj.aut}
|
||||||
selected={obj.selected}
|
selected={obj.selected}
|
||||||
unread={unread}
|
unread={unread}
|
||||||
|
Loading…
Reference in New Issue
Block a user