Commit ef696ec1 authored by zeroleak's avatar zeroleak
Browse files

cleanup

parent 73a99ba7
import React from 'react';
import React, { useEffect, useState } from 'react';
import BTable from 'react-bootstrap/Table';
import { useRowSelect, useSortBy, useTable } from 'react-table';
import * as Icon from 'react-feather';
......@@ -20,21 +20,36 @@ const IndeterminateCheckbox = React.forwardRef(
}
)
export default function TableGeneric({ columns, data, size='sm', /*onFetchData, pageIndex, pageSize, filters, */sortBy, getRowStyle=()=>{}, getRowClassName=()=>{}, onSelect=undefined }) {
export default function TableGeneric({ columns, data, tableKey, size='sm', /*onFetchData, pageIndex, pageSize, filters, */sortBy, getRowStyle=()=>{}, getRowClassName=()=>{}, onSelect=undefined }) {
if (!data) {
return
}
const [lastTableKey, setLastTableKey] = useState()
const resetTable = !lastTableKey || lastTableKey != tableKey
useEffect(() => {
setLastTableKey(tableKey)
}, [tableKey])
const initialState = {};
if (sortBy) {
initialState.sortBy = sortBy;
}
// Use the state and functions returned from useTable to build your UI
const { getTableProps, headerGroups, rows, prepareRow, selectedFlatRows, state: { selectedRowIds } } = useTable(
{
columns,
data,
initialState,
autoResetPage: resetTable,
autoResetExpanded: resetTable,
autoResetGroupBy: resetTable,
autoResetSelectedRows: resetTable,
autoResetSortBy: resetTable,
autoResetFilters: resetTable,
autoResetRowState: resetTable,
},
useSortBy,
useRowSelect,
......@@ -60,7 +75,7 @@ export default function TableGeneric({ columns, data, size='sm', /*onFetchData,
},
...columns,
])
}
},
);
// When these table states change, fetch new data!
......
......@@ -29,7 +29,7 @@ const UtxoControls = React.memo(({ utxo }) => {
});
/* eslint-disable react/prefer-stateless-function */
const UtxosTable = ({ controls, account, utxos }) => {
const UtxosTable = ({ controls, account, utxos, tableKey }) => {
const [showReadOnly, setShowReadOnly] = useState(false)
......@@ -154,6 +154,7 @@ const UtxosTable = ({ controls, account, utxos }) => {
</div>}
<div className='table-utxos'>
<TableGeneric
tableKey={tableKey}
columns={columns}
data={visibleUtxos}
sortBy={[{ id: 'lastActivityElapsed', desc: true }]}
......
......@@ -44,7 +44,7 @@ class DepositPage extends Component {
</div>
<div className='row h-100 d-flex flex-column'>
<div className='col-sm-12 flex-grow-1 tablescroll'>
<UtxosTable utxos={utxos} controls={true} account={false}/>
<UtxosTable tableKey='DepositPage' utxos={utxos} controls={true} account={false}/>
</div>
</div>
</div>
......
......@@ -44,7 +44,7 @@ class LastActivityPage extends Component {
</div>
<div className='row h-100 d-flex flex-column'>
<div className='col-sm-12 flex-grow-1 tablescroll'>
<UtxosTable utxos={utxos} controls={false} account={true}/>
<UtxosTable tableKey='LastActivityPage' utxos={utxos} controls={false} account={true}/>
</div>
</div>
</div>
......
......@@ -39,7 +39,7 @@ export default class PostmixPage extends Component<Props> {
</div>
<div className='row h-100 d-flex flex-column'>
<div className='col-sm-12 flex-grow-1 tablescroll'>
<UtxosTable utxos={utxos} controls={true} account={false}/>
<UtxosTable tableKey='PostmixPage' utxos={utxos} controls={true} account={false}/>
</div>
</div>
</div>
......
......@@ -39,7 +39,7 @@ export default class PremixPage extends Component<Props> {
</div>
<div className='row h-100 d-flex flex-column'>
<div className='col-sm-12 flex-grow-1 tablescroll'>
<UtxosTable utxos={utxos} controls={true} account={false}/>
<UtxosTable tableKey='PremixPage' utxos={utxos}tableKey controls={true} account={false}/>
</div>
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment