Skip to content

Commit

Permalink
refactor: separate reload timeline function
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 28, 2024
1 parent f83897a commit 6b9f8c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 deletions.
25 changes: 25 additions & 0 deletions lib/util/reload_timeline.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../model/tab_settings.dart';
import '../provider/api/timeline_notes_after_note_notifier_provider.dart';
import '../provider/api/timeline_notes_notifier_provider.dart';
import '../provider/streaming/timeline_stream_notifier.dart';
import '../provider/streaming/web_socket_channel_provider.dart';
import '../provider/timeline_center_notifier_provider.dart';
import '../provider/timeline_last_viewed_note_id_notifier_provider.dart';

Future<void> reloadTimeline(WidgetRef ref, TabSettings tabSettings) async {
if (!tabSettings.disableStreaming) {
ref.invalidate(webSocketChannelProvider(tabSettings.account));
}
ref.read(timelineCenterNotifierProvider(tabSettings).notifier).reset();
await Future.wait([
ref.refresh(timelineNotesAfterNoteNotifierProvider(tabSettings).future),
ref.refresh(timelineNotesNotifierProvider(tabSettings).future),
ref
.read(timelineLastViewedNoteIdNotifierProvider(tabSettings).notifier)
.saveFromDate(DateTime.now()),
if (!tabSettings.disableStreaming)
ref.read(timelineStreamNotifierProvider(tabSettings).notifier).connect(),
]);
}
24 changes: 2 additions & 22 deletions lib/view/widget/timeline_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import '../../provider/api/timeline_notes_notifier_provider.dart';
import '../../provider/general_settings_notifier_provider.dart';
import '../../provider/streaming/incoming_message_provider.dart';
import '../../provider/streaming/timeline_stream_notifier.dart';
import '../../provider/streaming/web_socket_channel_provider.dart';
import '../../provider/timeline_center_notifier_provider.dart';
import '../../provider/timeline_last_viewed_note_id_notifier_provider.dart';
import '../../provider/timeline_scroll_controller_provider.dart';
import '../../util/reload_timeline.dart';
import 'notifications_list_view.dart';
import 'pagination_bottom_widget.dart';
import 'timeline_note.dart';
Expand Down Expand Up @@ -217,27 +217,7 @@ class TimelineListView extends HookConsumerWidget {
);

return RefreshIndicator(
onRefresh: () async {
if (!tabSettings.disableStreaming) {
ref.invalidate(webSocketChannelProvider(tabSettings.account));
}
ref.read(timelineCenterNotifierProvider(tabSettings).notifier).reset();
await Future.wait([
ref.refresh(
timelineNotesAfterNoteNotifierProvider(tabSettings).future,
),
ref.refresh(timelineNotesNotifierProvider(tabSettings).future),
ref
.read(
timelineLastViewedNoteIdNotifierProvider(tabSettings).notifier,
)
.saveFromDate(DateTime.now()),
if (!tabSettings.disableStreaming)
ref
.read(timelineStreamNotifierProvider(tabSettings).notifier)
.connect(),
]);
},
onRefresh: () => reloadTimeline(ref, tabSettings),
notificationPredicate: (_) =>
nextNotes.valueOrNull?.isLastLoaded ?? false,
child: Center(
Expand Down
23 changes: 2 additions & 21 deletions lib/view/widget/timeline_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import '../../model/id.dart';
import '../../model/tab_settings.dart';
import '../../model/tab_type.dart';
import '../../provider/api/i_notifier_provider.dart';
import '../../provider/api/timeline_notes_after_note_notifier_provider.dart';
import '../../provider/api/timeline_notes_notifier_provider.dart';
import '../../provider/streaming/web_socket_channel_provider.dart';
import '../../provider/timeline_center_notifier_provider.dart';
import '../../provider/timeline_last_viewed_note_id_notifier_provider.dart';
import '../../util/pick_date_time.dart';
import '../../util/reload_timeline.dart';

class TimelineMenu extends ConsumerWidget {
const TimelineMenu({super.key, required this.tabSettings});
Expand Down Expand Up @@ -226,24 +224,7 @@ class TimelineMenu extends ConsumerWidget {
Card(
clipBehavior: Clip.hardEdge,
child: InkWell(
onTap: () {
ref
.read(
timelineCenterNotifierProvider(tabSettings).notifier,
)
.reset();
ref.invalidate(webSocketChannelProvider(account));
ref.invalidate(
timelineNotesAfterNoteNotifierProvider(tabSettings),
);
ref.invalidate(timelineNotesNotifierProvider(tabSettings));
ref
.read(
timelineLastViewedNoteIdNotifierProvider(tabSettings)
.notifier,
)
.saveFromDate(DateTime.now());
},
onTap: () => reloadTimeline(ref, tabSettings),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down

0 comments on commit 6b9f8c1

Please sign in to comment.