record
This commit is contained in:
parent
e5fdb78fd6
commit
06d4b62190
@ -801,60 +801,75 @@ class _RoomRocketRecordDialogLoaderState
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
unawaited(_load(reset: true));
|
unawaited(_loadAllRecords());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _load({bool reset = false}) async {
|
Future<void> _loadAllRecords() async {
|
||||||
if (_loadingMore || (!reset && (!_hasMore || _loading))) {
|
if (_loadingMore) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final requestCursor = reset ? 1 : _cursor;
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (reset) {
|
_loading = true;
|
||||||
_loading = true;
|
_loadingMore = false;
|
||||||
} else {
|
_hasMore = true;
|
||||||
_loadingMore = true;
|
_cursor = 1;
|
||||||
}
|
_rawRecords.clear();
|
||||||
|
_records = null;
|
||||||
});
|
});
|
||||||
|
var requestCursor = 1;
|
||||||
|
final allRecords = <SCRoomRocketRewardRecordRes>[];
|
||||||
try {
|
try {
|
||||||
_rocketUiDebug(
|
while (mounted) {
|
||||||
'request reward-records roomId=${widget.roomId} '
|
_rocketUiDebug(
|
||||||
'cursor=$requestCursor limit=$_rocketPageSize',
|
'request reward-records roomId=${widget.roomId} '
|
||||||
);
|
'cursor=$requestCursor limit=$_rocketPageSize',
|
||||||
final res = await SCChatRoomRepository().roomRocketRewardRecords(
|
);
|
||||||
widget.roomId,
|
final res = await SCChatRoomRepository().roomRocketRewardRecords(
|
||||||
cursor: requestCursor,
|
widget.roomId,
|
||||||
limit: _rocketPageSize,
|
cursor: requestCursor,
|
||||||
);
|
limit: _rocketPageSize,
|
||||||
|
);
|
||||||
|
if (!mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final nextRecords = res.records;
|
||||||
|
allRecords.addAll(nextRecords);
|
||||||
|
_rocketUiDebug(
|
||||||
|
'reward-records loaded cursor=$requestCursor '
|
||||||
|
'count=${nextRecords.length} total=${allRecords.length}',
|
||||||
|
);
|
||||||
|
if (nextRecords.length < _rocketPageSize) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
requestCursor += 1;
|
||||||
|
}
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final nextRecords = res.records;
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (reset) {
|
_rawRecords
|
||||||
_rawRecords
|
..clear()
|
||||||
..clear()
|
..addAll(allRecords);
|
||||||
..addAll(nextRecords);
|
|
||||||
} else {
|
|
||||||
_rawRecords.addAll(nextRecords);
|
|
||||||
}
|
|
||||||
_records = RoomRocketApiMapper.recordItemsFromRecords(_rawRecords);
|
_records = RoomRocketApiMapper.recordItemsFromRecords(_rawRecords);
|
||||||
_hasMore = nextRecords.length >= _rocketPageSize;
|
_hasMore = false;
|
||||||
if (_hasMore) {
|
_cursor = requestCursor;
|
||||||
_cursor = requestCursor + 1;
|
|
||||||
}
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
_loadingMore = false;
|
_loadingMore = false;
|
||||||
});
|
});
|
||||||
_rocketUiDebug(
|
_rocketUiDebug(
|
||||||
'reward-records loaded cursor=$requestCursor '
|
'reward-records all loaded total=${_rawRecords.length} '
|
||||||
'count=${nextRecords.length} total=${_rawRecords.length} '
|
'lastCursor=$_cursor',
|
||||||
'hasMore=$_hasMore nextCursor=$_cursor',
|
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
_rocketUiDebug('reward-records request failed: $error');
|
_rocketUiDebug('reward-records request failed: $error');
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
if (allRecords.isNotEmpty) {
|
||||||
|
_rawRecords
|
||||||
|
..clear()
|
||||||
|
..addAll(allRecords);
|
||||||
|
_records = RoomRocketApiMapper.recordItemsFromRecords(_rawRecords);
|
||||||
|
}
|
||||||
_loading = false;
|
_loading = false;
|
||||||
_loadingMore = false;
|
_loadingMore = false;
|
||||||
_hasMore = false;
|
_hasMore = false;
|
||||||
@ -871,7 +886,7 @@ class _RoomRocketRecordDialogLoaderState
|
|||||||
loadingText: _loading ? 'Loading data......' : '',
|
loadingText: _loading ? 'Loading data......' : '',
|
||||||
isLoadingMore: _loadingMore,
|
isLoadingMore: _loadingMore,
|
||||||
hasMore: _hasMore,
|
hasMore: _hasMore,
|
||||||
onLoadMore: () => unawaited(_load()),
|
onLoadMore: null,
|
||||||
limitText: 'Show only records from the last 35 days',
|
limitText: 'Show only records from the last 35 days',
|
||||||
onClose: widget.onClose,
|
onClose: widget.onClose,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user