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

View File

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