2019-06-06 08:24:21 +08:00
|
|
|
import { Button, InputNumber, Select } from "antd";
|
2019-06-01 22:02:06 +08:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import React from "react";
|
2019-06-06 08:24:21 +08:00
|
|
|
import { AutoSizer, Column, Table, TableCellRenderer } from "react-virtualized";
|
2019-06-04 03:41:18 +08:00
|
|
|
import { huntOptimizerStore, WantedItem } from "../../stores/HuntOptimizerStore";
|
2019-06-01 22:02:06 +08:00
|
|
|
import { itemStore } from "../../stores/ItemStore";
|
|
|
|
import './WantedItemsComponent.css';
|
|
|
|
|
|
|
|
@observer
|
|
|
|
export class WantedItemsComponent extends React.Component {
|
|
|
|
render() {
|
|
|
|
// Make sure render is called on updates.
|
2019-06-04 03:41:18 +08:00
|
|
|
huntOptimizerStore.wantedItems.slice(0, 0);
|
2019-06-01 22:02:06 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="ho-WantedItemsComponent">
|
2019-06-06 08:24:21 +08:00
|
|
|
<h3>Wanted Items</h3>
|
2019-06-04 03:41:18 +08:00
|
|
|
<div>
|
|
|
|
<Select
|
|
|
|
value={undefined}
|
|
|
|
showSearch
|
|
|
|
placeholder="Add an item"
|
|
|
|
optionFilterProp="children"
|
|
|
|
style={{ width: 200 }}
|
|
|
|
filterOption
|
|
|
|
onChange={this.addWanted}
|
|
|
|
>
|
|
|
|
{itemStore.items.current.value.map(item => (
|
|
|
|
<Select.Option key={item.name}>
|
|
|
|
{item.name}
|
|
|
|
</Select.Option>
|
|
|
|
))}
|
|
|
|
</Select>
|
2019-06-06 18:47:19 +08:00
|
|
|
<Button
|
|
|
|
onClick={huntOptimizerStore.optimize}
|
|
|
|
style={{ marginLeft: 10 }}
|
|
|
|
>
|
|
|
|
Optimize
|
|
|
|
</Button>
|
2019-06-04 03:41:18 +08:00
|
|
|
</div>
|
2019-06-06 08:24:21 +08:00
|
|
|
<div className="ho-WantedItemsComponent-table">
|
|
|
|
<AutoSizer>
|
|
|
|
{({ width, height }) => (
|
|
|
|
<Table
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
headerHeight={30}
|
|
|
|
rowHeight={30}
|
|
|
|
rowCount={huntOptimizerStore.wantedItems.length}
|
|
|
|
rowGetter={({ index }) => huntOptimizerStore.wantedItems[index]}
|
|
|
|
>
|
|
|
|
<Column
|
|
|
|
label="Amount"
|
|
|
|
dataKey="amount"
|
|
|
|
width={70}
|
|
|
|
cellRenderer={({ rowData }) =>
|
|
|
|
<WantedAmountCell wantedItem={rowData} />
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Column
|
|
|
|
label="Item"
|
|
|
|
dataKey="item"
|
|
|
|
width={150}
|
2019-06-06 18:47:19 +08:00
|
|
|
flexGrow={1}
|
2019-06-06 08:24:21 +08:00
|
|
|
cellDataGetter={({ rowData }) => rowData.item.name}
|
|
|
|
/>
|
|
|
|
<Column
|
|
|
|
dataKey="remove"
|
|
|
|
width={30}
|
|
|
|
cellRenderer={this.tableRemoveCellRenderer}
|
|
|
|
/>
|
|
|
|
</Table>
|
2019-06-01 22:02:06 +08:00
|
|
|
)}
|
2019-06-06 08:24:21 +08:00
|
|
|
</AutoSizer>
|
|
|
|
</div>
|
2019-06-01 22:02:06 +08:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private addWanted = (itemName: string) => {
|
2019-06-04 03:41:18 +08:00
|
|
|
let added = huntOptimizerStore.wantedItems.find(w => w.item.name === itemName);
|
2019-06-01 22:02:06 +08:00
|
|
|
|
|
|
|
if (!added) {
|
2019-06-04 03:41:18 +08:00
|
|
|
const item = itemStore.items.current.value.find(i => i.name === itemName)!;
|
|
|
|
huntOptimizerStore.wantedItems.push(new WantedItem(item, 1));
|
2019-06-01 22:02:06 +08:00
|
|
|
}
|
2019-06-04 03:41:18 +08:00
|
|
|
}
|
2019-06-01 22:02:06 +08:00
|
|
|
|
|
|
|
private removeWanted = (wanted: WantedItem) => () => {
|
2019-06-04 03:41:18 +08:00
|
|
|
const i = huntOptimizerStore.wantedItems.findIndex(w => w === wanted);
|
2019-06-01 22:02:06 +08:00
|
|
|
|
|
|
|
if (i !== -1) {
|
2019-06-04 03:41:18 +08:00
|
|
|
huntOptimizerStore.wantedItems.splice(i, 1);
|
2019-06-01 22:02:06 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-06 08:24:21 +08:00
|
|
|
|
|
|
|
private tableRemoveCellRenderer: TableCellRenderer = ({ rowData }) => {
|
|
|
|
return <Button type="link" icon="delete" onClick={this.removeWanted(rowData)} />;
|
|
|
|
}
|
2019-06-01 22:02:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@observer
|
|
|
|
class WantedAmountCell extends React.Component<{ wantedItem: WantedItem }> {
|
|
|
|
render() {
|
|
|
|
const wanted = this.props.wantedItem;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<InputNumber
|
2019-06-06 21:42:02 +08:00
|
|
|
min={0}
|
2019-06-06 08:24:21 +08:00
|
|
|
max={10}
|
2019-06-01 22:02:06 +08:00
|
|
|
value={wanted.amount}
|
|
|
|
onChange={this.wantedAmountChanged}
|
2019-06-06 08:24:21 +08:00
|
|
|
size="small"
|
|
|
|
style={{ width: '100%' }}
|
2019-06-01 22:02:06 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private wantedAmountChanged = (value?: number) => {
|
2019-06-06 21:42:02 +08:00
|
|
|
if (value != null && value >= 0) {
|
2019-06-01 22:02:06 +08:00
|
|
|
this.props.wantedItem.amount = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|