Skip to content

Commit 2b3a81a

Browse files
Merge pull request #93 from Detaysoft/moment-remove
Moment.js replaced timeago.js
2 parents bec9213 + a82b286 commit 2b3a81a

12 files changed

Lines changed: 12386 additions & 56 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ npm-debug.log*
1111
yarn-debug.log*
1212
yarn-error.log*
1313
dist
14+
package-lock.json
1415

1516
# -------- React Native -------- #
1617

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import { ChatItem } from 'react-chat-elements'
8686
| title | none | string | ChatItem title |
8787
| subtitle | none | string | ChatItem subtitle |
8888
| date | none | date | ChatItem date |
89-
| dateString | none | string | ChatItem represents dateString or moment(date).fromNow() |
89+
| dateString | none | string | ChatItem represents dateString or timeagojs(now, date) |
9090
| unread | 0 | int | ChatItem unread count |
9191
| onClick | none | function | ChatItem on click |
9292
| onContextMenu | none | function | ChatItem on context menu |
@@ -131,7 +131,7 @@ import { MessageBox } from 'react-chat-elements'
131131
| titleColor | none | string(color) | message title color |
132132
| data | {} | object | message data |
133133
| date | new Date() | Date | message date |
134-
| dateString | none | string | message represents dateString or moment(date).fromNow() |
134+
| dateString | none | string | message represents dateString or timeagojs(now, date) |
135135
| onClick | none | function | message on click (message(object) is returned) |
136136
| onOpen | none | function | message on open (file or photo) (message(object) is returned) |
137137
| onDownload | none | function | message on download (file or photo) (message(object) is returned) |
@@ -501,4 +501,4 @@ import { SpotifyMessage } from 'react-chat-elements'
501501
| view | list | string | spotify view type (list or coverart) |
502502
| data | {} | object | message data |
503503
| width | 300 | int | spotify embed width |
504-
| height | 380 | int | spotify embed height |
504+
| height | 380 | int | spotify embed height |

example/App.css

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
body {
2-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, ubuntu;
3-
background: navajowhite;
4-
margin: 0;
5-
padding: 0;
2+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, ubuntu;
3+
background: navajowhite;
4+
margin: 0;
5+
padding: 0;
66
}
77

88
html,
99
body {
10-
height: 100%;
11-
overflow: hidden;
10+
height: 100%;
11+
overflow: hidden;
1212
}
1313

1414
input,
1515
button {
16-
font-family: verdana, ubuntu;
16+
font-family: verdana, ubuntu;
1717
}
1818

1919
.container {
20-
display: flex;
21-
flex-direction: row;
22-
min-height: 100%;
23-
overflow: auto;
24-
position: absolute;
25-
top: 0;
26-
bottom: 0;
27-
left: 0;
28-
right: 0;
20+
display: flex;
21+
flex-direction: row;
22+
min-height: 100%;
23+
overflow: auto;
24+
position: absolute;
25+
top: 0;
26+
bottom: 0;
27+
left: 0;
28+
right: 0;
2929
}
3030

3131
.chat-list {
32-
min-width: 240px;
33-
max-width: 380px;
34-
overflow: auto;
32+
min-width: 240px;
33+
max-width: 380px;
34+
overflow: auto;
3535
}
3636

3737
.right-panel {
38-
flex: 1;
39-
display: flex;
40-
flex-direction: column;
38+
flex: 1;
39+
display: flex;
40+
flex-direction: column;
4141
}
4242

4343
.message-list {
44-
flex: 1;
45-
min-width: 140px;
44+
flex: 1;
45+
min-width: 140px;
46+
overflow: auto;
4647
}
4748

4849
.input-area {
49-
height: 50px;
50-
background: red;
50+
height: 50px;
51+
background: red;
5152
}

example/App.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import FaSearch from 'react-icons/lib/fa/search';
1818
import FaComments from 'react-icons/lib/fa/comments';
1919
import FaClose from 'react-icons/lib/fa/close';
2020
import FaMenu from 'react-icons/lib/md/more-vert';
21+
import {
22+
format,
23+
} from 'timeago.js';
2124

22-
const loremIpsum = require('lorem-ipsum');
23-
const Identicon = require('identicon.js')
24-
const moment = require('moment');
25+
import loremIpsum from 'lorem-ipsum';
26+
import Identicon from 'identicon.js';
2527

2628
export class App extends Component {
2729

@@ -113,8 +115,7 @@ export class App extends Component {
113115
console.log('Photo loaded');
114116
},
115117
status: status,
116-
date: new Date(),
117-
dateString: moment(new Date()).format('HH:mm'),
118+
date: +new Date(),
118119
avatar: `data:image/png;base64,${this.photo()}`,
119120
};
120121
case 'chat':
@@ -145,7 +146,6 @@ export class App extends Component {
145146
'Menu Item3',
146147
]} />
147148
),
148-
dateString: moment(new Date()).format('HH:mm'),
149149
};
150150
}
151151
}

example/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import './App.css';
44
import App from './App';
55

66
const render = Component => {
7-
ReactDOM.render(
8-
<Component/>,
9-
document.getElementById('app'),
10-
);
7+
ReactDOM.render(
8+
<Component/>,
9+
document.getElementById('app'),
10+
);
1111
};
1212

13-
render(App);
13+
render(App);

native/MessageBox/MessageBox.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
Image,
1010
} from 'react-native';
1111

12+
import {
13+
format,
14+
} from'timeago.js';
15+
1216
import IconI from 'react-native-vector-icons/Ionicons';
1317
import IconM from 'react-native-vector-icons/MaterialIcons';
1418

@@ -90,7 +94,7 @@ export class MessageBox extends Component {
9094
!isNaN(this.props.date) &&
9195
(
9296
this.props.dateString ||
93-
moment(this.props.date).fromNow()
97+
format(new Date(), undefined, this.props.date)
9498
)
9599
}
96100
</Text>

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-elements",
3-
"version": "10.3.1",
3+
"version": "10.4.1",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <abdurrahmaneker58@gmail.com>",
66
"main": "dist/main.js",
@@ -16,9 +16,7 @@
1616
"enzyme": "^2.9.1",
1717
"enzyme-to-json": "^1.5.1",
1818
"extract-text-webpack-plugin": "^3.0.0",
19-
"identicon": "^2.1.1",
2019
"identicon.js": "^2.3.1",
21-
"isomorphic-style-loader": "^2.0.0",
2220
"lorem-ipsum": "^1.0.4",
2321
"nwb": "^0.18.10",
2422
"react": "16.0.0-beta.5",
@@ -65,11 +63,11 @@
6563
},
6664
"dependencies": {
6765
"classnames": "^2.2.5",
68-
"moment": "^2.18.1",
6966
"react-icons": "^2.2.5",
67+
"react-native-icons": "^0.7.1",
68+
"react-native-vector-icons": "^4.4.2",
7069
"react-progress-bar.js": "^0.2.3",
7170
"react-spinkit": "^3.0.0",
72-
"react-native-icons": "^0.7.1",
73-
"react-native-vector-icons": "^4.4.2"
71+
"timeago.js": "^4.0.0-beta.2"
7472
}
7573
}

src/ChatItem/ChatItem.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import './ChatItem.css';
33

44
import Avatar from '../Avatar/Avatar';
55

6-
const moment = require('moment');
7-
const classNames = require('classnames');
6+
import {
7+
format,
8+
} from'timeago.js';
9+
10+
import classNames from 'classnames';
811

912
export class ChatItem extends Component {
1013

@@ -42,7 +45,7 @@ export class ChatItem extends Component {
4245
!isNaN(this.props.date) &&
4346
(
4447
this.props.dateString ||
45-
moment(this.props.date).fromNow()
48+
format(new Date(), undefined, this.props.date)
4649
)
4750
}
4851
</div>

src/ChatItem/__tests__/__snapshots__/ChatItem.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`ChatItem component should render without issues 1`] = `
3232
<div
3333
className="rce-citem-body--top-time"
3434
>
35-
a few seconds ago
35+
right now
3636
</div>
3737
</div>
3838
<div

src/MessageBox/MessageBox.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import IoDoneAll from 'react-icons/lib/io/android-done-all';
1616
import MdIosTime from 'react-icons/lib/md/access-time';
1717
import MdCheck from 'react-icons/lib/md/check';
1818

19-
const moment = require('moment');
19+
import {
20+
format,
21+
} from 'timeago.js';
2022

21-
const classNames = require('classnames');
23+
import classNames from 'classnames';
2224

2325
export class MessageBox extends Component {
2426
render() {
@@ -28,7 +30,7 @@ export class MessageBox extends Component {
2830

2931
const dateText = this.props.date && !isNaN(this.props.date) && (
3032
this.props.dateString ||
31-
moment(this.props.date).fromNow()
33+
format(new Date(), undefined, this.props.date)
3234
);
3335

3436
return (
@@ -152,7 +154,7 @@ export class MessageBox extends Component {
152154
!isNaN(this.props.date) &&
153155
(
154156
this.props.dateString ||
155-
moment(this.props.date).fromNow()
157+
format(new Date(), undefined, this.props.date)
156158
)
157159
}
158160
{

0 commit comments

Comments
 (0)