This commit is contained in:
roxy 2026-05-16 01:08:30 +08:00
parent e5fdb78fd6
commit 06d4b62190

View File

@ -801,22 +801,25 @@ 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;
} else { _loadingMore = false;
_loadingMore = true; _hasMore = true;
} _cursor = 1;
_rawRecords.clear();
_records = null;
}); });
var requestCursor = 1;
final allRecords = <SCRoomRocketRewardRecordRes>[];
try { try {
while (mounted) {
_rocketUiDebug( _rocketUiDebug(
'request reward-records roomId=${widget.roomId} ' 'request reward-records roomId=${widget.roomId} '
'cursor=$requestCursor limit=$_rocketPageSize', 'cursor=$requestCursor limit=$_rocketPageSize',
@ -830,31 +833,43 @@ class _RoomRocketRecordDialogLoaderState
return; return;
} }
final nextRecords = res.records; 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) {
return;
}
setState(() { setState(() {
if (reset) {
_rawRecords _rawRecords
..clear() ..clear()
..addAll(nextRecords); ..addAll(allRecords);
} 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,
); );