-
Notifications
You must be signed in to change notification settings - Fork 295
/
UpdateItem.tsx
78 lines (71 loc) · 2.01 KB
/
UpdateItem.tsx
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
77
78
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classNames from 'classnames';
import moment from 'moment';
import News /* , { NewsTypes } */ from '../../domains/News';
import styles from './UpdateItem.scss';
type Props = {
updateItem: News.News,
onOpenAppUpdate: Function,
currentDateFormat: string,
downloadProgress: number,
isUpdatePostponed: boolean,
};
@observer
export default class UpdateItem extends Component<Props> {
static defaultProps = {
onupdateItemActionClick: null,
expandWithoutTransition: false,
};
generateTitleWithBadge = (title: string) => {
const wordsArray = title.split(' ');
const lastWordIndex = wordsArray.length - 1;
const lastWord = wordsArray[lastWordIndex];
// Remove last word from array
wordsArray.splice(lastWordIndex, 1);
// Join words without last one
const firstSentencePart = wordsArray.join(' ');
return (
<h4 className={styles.title}>
{firstSentencePart ? `${firstSentencePart} ` : null}
<span className={styles.lastWordWrapper}>
{lastWord}
{<span className={styles.badge} />}
</span>
</h4>
);
};
render() {
const {
updateItem,
currentDateFormat,
onOpenAppUpdate,
downloadProgress,
isUpdatePostponed,
} = this.props;
const componentClasses = classNames([
styles.component,
updateItem.type ? styles[updateItem.type] : null,
]);
const title = this.generateTitleWithBadge(updateItem.title);
return (
<div
className={componentClasses}
role="presentation"
onClick={onOpenAppUpdate}
>
{title}
<div className={styles.date}>
{moment(updateItem.date).format(currentDateFormat)}
</div>
{!isUpdatePostponed && (
<div className={styles.downloadProgress}>
<span style={{ width: `${downloadProgress}%` }} />
<em />
</div>
)}
</div>
);
}
}