Browse Source

fix(neon_dashboard): Limit dashboard widget items

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1148/head
jld3103 1 year ago
parent
commit
ecd70190d7
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 29
      packages/neon/neon_dashboard/lib/src/blocs/dashboard.dart

29
packages/neon/neon_dashboard/lib/src/blocs/dashboard.dart

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:neon/blocs.dart';
@ -29,6 +30,7 @@ class DashboardBloc extends InteractiveBloc implements DashboardBlocEvents, Dash
final Account _account;
late final NeonTimer _timer;
static const int _maxItems = 7;
@override
BehaviorSubject<Result<Map<dashboard.Widget, dashboard.WidgetItems?>>> widgets = BehaviorSubject();
@ -64,11 +66,15 @@ class DashboardBloc extends InteractiveBloc implements DashboardBlocEvents, Dash
if (v1WidgetIDs.isNotEmpty) {
debugPrint('Loading v1 widgets: ${v1WidgetIDs.join(', ')}');
final response = await _account.client.dashboard.dashboardApi.getWidgetItems(widgets: v1WidgetIDs);
final response = await _account.client.dashboard.dashboardApi.getWidgetItems(
widgets: v1WidgetIDs,
// ignore: avoid_redundant_argument_values
limit: _maxItems,
);
for (final entry in response.body.ocs.data.entries) {
widgets[entry.key] = dashboard.WidgetItems(
(final b) => b
..items.replace(entry.value)
..items = entry.value.sublist(0, min(entry.value.length, _maxItems)).toBuilder()
..emptyContentMessage = ''
..halfEmptyContentMessage = '',
);
@ -78,8 +84,23 @@ class DashboardBloc extends InteractiveBloc implements DashboardBlocEvents, Dash
if (v2WidgetIDs.isNotEmpty) {
debugPrint('Loading v2 widgets: ${v2WidgetIDs.join(', ')}');
final response = await _account.client.dashboard.dashboardApi.getWidgetItemsV2(widgets: v2WidgetIDs);
widgets.addEntries(response.body.ocs.data.entries);
final response = await _account.client.dashboard.dashboardApi.getWidgetItemsV2(
widgets: v2WidgetIDs,
// ignore: avoid_redundant_argument_values
limit: _maxItems,
);
widgets.addEntries(
response.body.ocs.data.entries.map(
(final entry) => MapEntry(
entry.key,
entry.value.rebuild((final b) {
if (b.items.length > _maxItems) {
b.items.removeRange(_maxItems, b.items.length);
}
}),
),
),
);
}
this.widgets.add(

Loading…
Cancel
Save