This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
184 lines (149 loc) · 4.82 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// @flow
import React from 'react';
import startCase from 'lodash/startCase';
import includes from 'lodash/includes';
import get from 'lodash/get';
import T from 'i18n-react';
import styles from './styles.less';
import SimpleTooltip from '../Simple';
import colours from 'common/styles/colours.less';
import { markup, attributeToName } from 'lib/gw2/parse';
import Icon from 'common/components/Icon';
import ItemHeader from '../ItemHeader';
import Gold from '../../Gold';
import Upgrade from '../Upgrade';
import Infusion from '../Infusion';
import Background from '../Background';
const addCount = (str, count) => (count > 1 ? `${count} ${str}` : str);
const minutes = ms => `${Math.floor(ms / 60000)} m`;
function buildName(item, skin, upgrades, count) {
let name;
if (!skin.name) {
name = item.name;
} else {
const regex = /[\w'-]+/;
const prefix = regex.exec(item.name);
const prefixedName = `${prefix} ${skin.name}`;
const [upgradeOne] = upgrades;
if (upgradeOne && prefixedName.indexOf(upgradeOne.details.suffix)) {
name = `${prefixedName} ${upgradeOne.details.suffix}`;
}
name = prefixedName;
}
return addCount(name, count);
}
type Props = {
data: Object,
};
const ItemsTooltip = ({
data: {
count,
item,
skin,
name,
upgrades,
upgradeCounts,
infusions,
stats: { attributes = {} },
equipped,
},
}: Props) => {
if (Object.keys(item).length === 0) {
return (
<Background>
<SimpleTooltip data={name} />
</Background>
);
}
const isTransmuted = !!skin.name;
return (
<Background>
{equipped && <SimpleTooltip data={T.translate('items.currentlyEquipped')} />}
<ItemHeader
name={buildName(item, skin, upgrades, count)}
icon={skin.icon || item.icon}
rarity={item.rarity}
/>
<div>
{item.details &&
!!item.details.defense && (
<div>
{T.translate('items.defense')}:
<span className={colours.green}> {item.details.defense}</span>
</div>
)}
{item.type === 'Weapon' && (
<div>
<span>{T.translate('items.weaponStrength')}: </span>
<span className={colours.green}>
{`${item.details.min_power} - ${item.details.max_power}`}
</span>
</div>
)}
{get(item, 'details.infix_upgrade.attributes', []).map(({ modifier, attribute }) => (
<div key={attribute} className={colours.green}>
{`+${modifier} ${attributeToName(attribute)}`}
</div>
))}
{item.type === 'UpgradeComponent' &&
!includes(item.name, 'Infusion') &&
get(item, 'details.infix_upgrade.buff.description', []).map(buff => (
<div key={buff}>{markup(buff)}</div>
))}
{Object.keys(attributes).map(attribute => {
const modifier = attributes[attribute];
return (
<div key={attribute} className={colours.green}>
{`+${modifier} ${attributeToName(attribute)}`}
</div>
);
})}
{item.details && (
<span className={styles.description}>
{item.details.icon && <Icon src={item.details.icon} className={styles.detailsIcon} />}
<span className={colours.green}>
{item.details.name && (
<div>{`${item.details.name} (${minutes(item.details.duration_ms)}): `}</div>
)}
{markup(item.details.description)}
</span>
</span>
)}
{get(item, 'details.bonuses', []).map((bonusName, bonusId) => (
<div className={colours.blue}>{markup(`(${bonusId + 1}): ${bonusName}`)}</div>
))}
<br />
{upgrades.map(upgrade => (
<span key={upgrade.id}>
<Upgrade data={upgrade} count={upgradeCounts[upgrade.id]} />
<br />
</span>
))}
{infusions.map((infusion, index) => (
// eslint-disable-next-line react/no-array-index-key
<span key={index}>
<Infusion data={infusion} />
<br />
</span>
))}
{equipped && (
<div>
{isTransmuted ? T.translate('items.transmuted') : T.translate('items.skinLocked')}
</div>
)}
<div>{item.rarity}</div>
{item.details && <div>{item.details.weight_class}</div>}
{item.details && <div>{startCase(item.type)}</div>}
<div>{markup(item.description)}</div>
{!!item.level && (
<div>
{T.translate('items.requiredLevel')}: {item.level}
</div>
)}
<div>{startCase(item.boundStatus)}</div>
{item.rarity !== 'Legendary' && <Gold coins={item.vendor_value} />}
</div>
</Background>
);
};
export default ItemsTooltip;