1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

sort arrays before putting it in state

This commit is contained in:
Matthias Kretschmann 2020-10-22 16:19:26 +02:00
parent f397d51858
commit 4a201e7325
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 22 additions and 16 deletions

View File

@ -114,13 +114,12 @@ export default function ComputeJobs(): ReactElement {
})
})
}
setJobs(
jobs.sort((a, b) => {
if (a.dateCreated > b.dateCreated) return -1
if (a.dateCreated < b.dateCreated) return 1
return 0
})
)
const jobsSorted = jobs.sort((a, b) => {
if (a.dateCreated > b.dateCreated) return -1
if (a.dateCreated < b.dateCreated) return 1
return 0
})
setJobs(jobsSorted)
} catch (error) {
Logger.log(error.message)
} finally {
@ -130,5 +129,13 @@ export default function ComputeJobs(): ReactElement {
getJobs()
}, [ocean, account])
return <Table columns={columns} data={jobs} isLoading={isLoading} />
return (
<Table
columns={columns}
data={jobs}
isLoading={isLoading}
defaultSortField="row.dateCreated"
defaultSortAsc={false}
/>
)
}

View File

@ -75,14 +75,13 @@ export default function PoolTransactions(): ReactElement {
if (!ocean || !accountId) return
setIsLoading(true)
const logs = await ocean.pool.getAllPoolLogs(accountId)
setLogs(
// sort logs by date, newest first
logs.sort((a, b) => {
if (a.timestamp > b.timestamp) return -1
if (a.timestamp < b.timestamp) return 1
return 0
})
)
// sort logs by date, newest first
const logsSorted = logs.sort((a, b) => {
if (a.timestamp > b.timestamp) return -1
if (a.timestamp < b.timestamp) return 1
return 0
})
setLogs(logsSorted)
setIsLoading(false)
}
getLogs()