2019-06-05 01:46:36 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import classnames from 'classnames';
|
2019-06-20 03:05:18 +03:00
|
|
|
import _ from 'lodash';
|
2019-06-05 01:46:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
export default class ChatTile extends Component {
|
|
|
|
|
2019-06-08 02:46:46 +03:00
|
|
|
render() {
|
2019-07-12 02:26:33 +03:00
|
|
|
const { props } = this;
|
2019-06-20 03:05:18 +03:00
|
|
|
let inviteNum = 0;
|
|
|
|
let msgNum = 0;
|
|
|
|
let inviteCircle = `~${window.ship}/i`;
|
|
|
|
|
2019-07-12 02:26:33 +03:00
|
|
|
let propNumbers = _.get(props, 'data.numbers.chat.numbers', false);
|
|
|
|
let propConfigs = _.get(props, 'data.config.chat.configs', false);
|
|
|
|
|
|
|
|
if (propNumbers && propConfigs) {
|
2019-06-20 03:05:18 +03:00
|
|
|
let numbers = {};
|
|
|
|
|
2019-07-12 02:26:33 +03:00
|
|
|
for (let i = 0; i < propNumbers.length; i++) {
|
|
|
|
let num = propNumbers[i];
|
2019-06-20 03:05:18 +03:00
|
|
|
numbers[num.circle] = num.length;
|
2019-06-24 23:29:56 +03:00
|
|
|
}
|
2019-06-20 03:05:18 +03:00
|
|
|
|
2019-07-12 02:26:33 +03:00
|
|
|
let configs = Object.keys(propConfigs);
|
|
|
|
|
2019-06-24 23:29:56 +03:00
|
|
|
for (let i = 0; i < configs.length; i++) {
|
|
|
|
let key = configs[i];
|
2019-06-22 02:09:04 +03:00
|
|
|
let host = key.split('/')[0];
|
2019-06-24 23:29:56 +03:00
|
|
|
|
2019-07-12 02:26:33 +03:00
|
|
|
if (!propConfigs[key]) { break; }
|
2019-06-27 23:31:00 +03:00
|
|
|
if (!(key in numbers)) { break; }
|
2019-06-24 23:29:56 +03:00
|
|
|
|
2019-07-12 02:26:33 +03:00
|
|
|
let red = propConfigs[key].red;
|
2019-06-24 23:29:56 +03:00
|
|
|
|
2019-06-22 02:09:04 +03:00
|
|
|
if (key === inviteCircle) {
|
2019-06-24 23:29:56 +03:00
|
|
|
inviteNum = inviteNum - red + numbers[key];
|
|
|
|
} else if (host === `~${window.ship}`) {
|
|
|
|
msgNum = msgNum - red + numbers[key];
|
2019-06-22 02:09:04 +03:00
|
|
|
} else {
|
2019-06-24 23:29:56 +03:00
|
|
|
msgNum = msgNum + numbers[key];
|
2019-06-20 03:05:18 +03:00
|
|
|
}
|
2019-06-24 23:29:56 +03:00
|
|
|
}
|
2019-06-22 02:09:04 +03:00
|
|
|
}
|
|
|
|
|
2019-07-20 00:38:02 +03:00
|
|
|
let invSuffix = (inviteNum === 1) ? (
|
2019-07-20 01:01:44 +03:00
|
|
|
<span>Invite</span>
|
2019-07-20 00:38:02 +03:00
|
|
|
) : (
|
2019-07-20 01:01:44 +03:00
|
|
|
<span>Invites</span>
|
2019-07-20 00:38:02 +03:00
|
|
|
);
|
2019-07-12 21:05:26 +03:00
|
|
|
let numInvElem = (inviteNum > 0) ? (
|
|
|
|
<p className="absolute white"
|
|
|
|
style={{
|
|
|
|
top: 180,
|
|
|
|
fontWeight: 600,
|
|
|
|
fontSize: 16,
|
|
|
|
lineHeight: '20px'
|
|
|
|
}}>
|
2019-07-20 00:38:02 +03:00
|
|
|
<span style={{
|
|
|
|
color: '#2AA779'
|
|
|
|
}}>{inviteNum} </span>
|
|
|
|
{invSuffix}
|
2019-07-12 21:05:26 +03:00
|
|
|
</p>
|
|
|
|
) : (
|
|
|
|
<div />
|
|
|
|
);
|
2019-07-20 00:38:02 +03:00
|
|
|
|
|
|
|
let msgSuffix = (msgNum === 1) ? (
|
2019-07-20 01:01:44 +03:00
|
|
|
<span>New Message</span>
|
2019-07-20 00:38:02 +03:00
|
|
|
) : (
|
2019-07-20 01:01:44 +03:00
|
|
|
<span>New Messages</span>
|
2019-07-20 00:38:02 +03:00
|
|
|
);
|
2019-07-12 21:05:26 +03:00
|
|
|
let numMsgElem = (msgNum > 0) ? (
|
|
|
|
<p className="absolute white"
|
|
|
|
style={{
|
|
|
|
top: 207,
|
|
|
|
fontWeight: 600,
|
|
|
|
fontSize: 16,
|
|
|
|
lineHeight: '20px'
|
|
|
|
}}>
|
2019-07-20 00:38:02 +03:00
|
|
|
<span style={{
|
|
|
|
color: '#2AA779'
|
|
|
|
}}>{msgNum} </span>
|
|
|
|
{msgSuffix}
|
2019-07-12 21:05:26 +03:00
|
|
|
</p>
|
|
|
|
) : (
|
|
|
|
<div />
|
|
|
|
);
|
|
|
|
|
2019-06-05 01:46:36 +03:00
|
|
|
return (
|
2019-06-20 03:05:18 +03:00
|
|
|
<div className="w-100 h-100 relative" style={{ background: '#1a1a1a' }}>
|
|
|
|
<a className="w-100 h-100 db pa2 no-underline" href="/~chat">
|
2019-07-15 20:35:20 +03:00
|
|
|
<p className="gray label-regular b absolute" style={{left: 8, top: 4}}>Chat</p>
|
2019-06-20 03:05:18 +03:00
|
|
|
<img
|
|
|
|
className="absolute"
|
|
|
|
style={{ left: 68, top: 65 }}
|
|
|
|
src="/~chat/img/Tile.png"
|
|
|
|
width={106}
|
|
|
|
height={98} />
|
2019-07-12 21:05:26 +03:00
|
|
|
{numInvElem}
|
|
|
|
{numMsgElem}
|
2019-06-08 02:46:46 +03:00
|
|
|
</a>
|
2019-06-05 01:46:36 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
window.chatTile = ChatTile;
|