-
Notifications
You must be signed in to change notification settings - Fork 2k
/
view.js
76 lines (65 loc) · 1.99 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-disable wpcalypso/jsx-classname-namespace */
// disabled CSS class rule due to existing code already
// that users the non-conformant classnames
/**
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
const view = ( { attributes, className, isEditView } ) => {
// Expected values in save.
let days = ' ';
let hours = ' ';
let mins = ' ';
let secs = ' ';
if ( isEditView ) {
// Zero out.
days = hours = mins = secs = 0;
const eventTime = new Date( attributes.eventDate ).getTime();
const now = Date.now();
const diff = eventTime - now;
if ( diff > 0 ) {
// Convert diff to seconds.
let rem = Math.round( diff / 1000 );
days = Math.floor( rem / ( 24 * 60 * 60 ) );
rem = rem - days * 24 * 60 * 60;
hours = Math.floor( rem / ( 60 * 60 ) );
rem = rem - hours * 60 * 60;
mins = Math.floor( rem / 60 );
rem = rem - mins * 60;
secs = rem;
}
}
return (
<div className={ className }>
<div className="event-countdown__date">{ attributes.eventDate }</div>
<div className="event-countdown__counter">
<p>
<strong className="event-countdown__day">{ days }</strong>{ ' ' }
{ _x( 'days', 'Countdown days remaining', 'full-site-editing' ) }
</p>
<p>
<span>
<strong className="event-countdown__hour">{ hours }</strong>{ ' ' }
{ _x( 'hours', 'Countdown hours remaining', 'full-site-editing' ) }
</span>
<span>
<strong className="event-countdown__minute">{ mins }</strong>{ ' ' }
{ _x( 'minutes', 'Countdown minutes remaining', 'full-site-editing' ) }
</span>
<span>
<strong className="event-countdown__second">{ secs }</strong>{ ' ' }
{ _x( 'seconds', 'Countdown seconds remaining', 'full-site-editing' ) }
</span>
</p>
<p>{ __( 'until', 'full-site-editing' ) }</p>
</div>
<div className="event-countdown__event-title">
<p>{ attributes.eventTitle }</p>
</div>
</div>
);
};
export default view;