Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
e26e1557
Commit
e26e1557
authored
Oct 20, 2022
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix sorting
parent
aa3ca7e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
TxsContent.tsx
ui/txs/TxsContent.tsx
+27
-2
TxsWithSort.tsx
ui/txs/TxsWithSort.tsx
+5
-30
No files found.
ui/txs/TxsContent.tsx
View file @
e26e1557
import
{
Alert
,
Box
,
HStack
,
Show
,
Button
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useState
,
useCallback
}
from
'
react
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
...
...
@@ -28,6 +28,31 @@ const TxsContent = ({
}:
Props
)
=>
{
const
[
sorting
,
setSorting
]
=
useState
<
Sort
>
();
const
sort
=
useCallback
((
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
{
if
(
field
===
'
val
'
)
{
setSorting
((
prevVal
=>
{
if
(
prevVal
===
'
val-asc
'
)
{
return
undefined
;
}
if
(
prevVal
===
'
val-desc
'
)
{
return
'
val-asc
'
;
}
return
'
val-desc
'
;
}));
}
if
(
field
===
'
fee
'
)
{
setSorting
((
prevVal
=>
{
if
(
prevVal
===
'
fee-asc
'
)
{
return
undefined
;
}
if
(
prevVal
===
'
fee-desc
'
)
{
return
'
fee-asc
'
;
}
return
'
fee-desc
'
;
}));
}
},
[
setSorting
]);
const
{
data
,
isLoading
,
...
...
@@ -59,7 +84,7 @@ const TxsContent = ({
);
if
(
!
isLoading
&&
txs
)
{
content
=
<
TxsWithSort
txs=
{
txs
}
sorting=
{
sorting
}
s
etSorting=
{
setSorting
}
/>;
content
=
<
TxsWithSort
txs=
{
txs
}
sorting=
{
sorting
}
s
ort=
{
sort
}
/>;
}
return
(
...
...
ui/txs/TxsWithSort.tsx
View file @
e26e1557
import
{
Box
,
Show
}
from
'
@chakra-ui/react
'
;
import
React
,
{
use
Callback
,
use
Effect
,
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
type
{
TransactionsResponse
}
from
'
types/api/transaction
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
...
...
@@ -12,41 +12,16 @@ import TxsTable from './TxsTable';
type
Props
=
{
txs
:
TransactionsResponse
[
'
items
'
];
sorting
?:
Sort
;
s
etSorting
:
(
sorting
:
Sort
|
((
val
:
Sort
)
=>
Sort
)
)
=>
void
;
s
ort
:
(
field
:
'
val
'
|
'
fee
'
)
=>
(
)
=>
void
;
}
const
Txs
Conten
t
=
({
const
Txs
WithSor
t
=
({
txs
,
sorting
,
s
etSorting
,
s
ort
,
}:
Props
)
=>
{
const
[
sortedTxs
,
setSortedTxs
]
=
useState
(
txs
);
const
sort
=
useCallback
((
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
{
if
(
field
===
'
val
'
)
{
setSorting
((
prevVal
=>
{
if
(
prevVal
===
'
val-asc
'
)
{
return
undefined
;
}
if
(
prevVal
===
'
val-desc
'
)
{
return
'
val-asc
'
;
}
return
'
val-desc
'
;
}));
}
if
(
field
===
'
fee
'
)
{
setSorting
((
prevVal
=>
{
if
(
prevVal
===
'
fee-asc
'
)
{
return
undefined
;
}
if
(
prevVal
===
'
fee-desc
'
)
{
return
'
fee-asc
'
;
}
return
'
fee-desc
'
;
}));
}
},
[
setSorting
]);
useEffect
(()
=>
{
switch
(
sorting
)
{
case
'
val-desc
'
:
...
...
@@ -75,4 +50,4 @@ const TxsContent = ({
};
export
default
Txs
Conten
t
;
export
default
Txs
WithSor
t
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment