feat: add user list sorting and pagination enhancements (#1178)

* feat: add user list sorting and pagination enhancements

* feat: add user list sorting for THEME=air

* feat: add token list sorting and pagination enhancements

* feat: add token list sorting for THEME=air
This commit is contained in:
Benny
2024-03-17 19:25:36 +08:00
committed by GitHub
parent 08831881f1
commit 9821bc7281
8 changed files with 184 additions and 42 deletions

View File

@@ -48,9 +48,10 @@ const TokensTable = () => {
const [searching, setSearching] = useState(false);
const [showTopUpModal, setShowTopUpModal] = useState(false);
const [targetTokenIdx, setTargetTokenIdx] = useState(0);
const [orderBy, setOrderBy] = useState('');
const loadTokens = async (startIdx) => {
const res = await API.get(`/api/token/?p=${startIdx}`);
const res = await API.get(`/api/token/?p=${startIdx}&order=${orderBy}`);
const { success, message, data } = res.data;
if (success) {
if (startIdx === 0) {
@@ -70,7 +71,7 @@ const TokensTable = () => {
(async () => {
if (activePage === Math.ceil(tokens.length / ITEMS_PER_PAGE) + 1) {
// In this case we have to load more data and then append them.
await loadTokens(activePage - 1);
await loadTokens(activePage - 1, orderBy);
}
setActivePage(activePage);
})();
@@ -160,12 +161,12 @@ const TokensTable = () => {
}
useEffect(() => {
loadTokens(0)
loadTokens(0, orderBy)
.then()
.catch((reason) => {
showError(reason);
});
}, []);
}, [orderBy]);
const manageToken = async (id, action, idx) => {
let data = { id };
@@ -205,6 +206,7 @@ const TokensTable = () => {
// if keyword is blank, load files instead.
await loadTokens(0);
setActivePage(1);
setOrderBy('');
return;
}
setSearching(true);
@@ -243,6 +245,11 @@ const TokensTable = () => {
setLoading(false);
};
const handleOrderByChange = (e, { value }) => {
setOrderBy(value);
setActivePage(1);
};
return (
<>
<Form onSubmit={searchTokens}>
@@ -427,6 +434,18 @@ const TokensTable = () => {
添加新的令牌
</Button>
<Button size='small' onClick={refresh} loading={loading}>刷新</Button>
<Dropdown
placeholder='排序方式'
selection
options={[
{ key: '', text: '默认排序', value: '' },
{ key: 'remain_quota', text: '按剩余额度排序', value: 'remain_quota' },
{ key: 'used_quota', text: '按已用额度排序', value: 'used_quota' },
]}
value={orderBy}
onChange={handleOrderByChange}
style={{ marginLeft: '10px' }}
/>
<Pagination
floated='right'
activePage={activePage}