mirror of
https://github.com/friebetill/TubeCards.git
synced 2025-08-16 02:57:29 +08:00
33 lines
762 B
Dart
33 lines
762 B
Dart
import 'dart:math';
|
|
|
|
import 'package:ferry/typed_links.dart';
|
|
|
|
import '../../queries/__generated__/cards.req.gql.dart';
|
|
import 'connection_utils.dart';
|
|
|
|
class CardsHelper {
|
|
CardsHelper(this.proxy);
|
|
|
|
final CacheProxy proxy;
|
|
|
|
void changeTotalCountBy(int amount) {
|
|
final pageRequests = getAllPageRequests(
|
|
proxy,
|
|
GCardsReq(),
|
|
(_, __) => GCardsReq(),
|
|
(_) => false,
|
|
);
|
|
|
|
for (final pageRequest in pageRequests) {
|
|
final cachedResponse = proxy.readQuery(pageRequest)!;
|
|
|
|
final updatedResponse = cachedResponse.rebuild((b) => b
|
|
.viewer
|
|
.cardConnection
|
|
.totalCount = max(0, b.viewer.cardConnection.totalCount! + amount));
|
|
|
|
proxy.writeQuery(pageRequest, updatedResponse);
|
|
}
|
|
}
|
|
}
|