mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 00:59:28 +01:00
refresh lists on source change and sync
This commit is contained in:
parent
798a907cca
commit
064440b0ee
22
lib/app/hooks/use_on_source.dart
Normal file
22
lib/app/hooks/use_on_source.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
|
import '../state/services.dart';
|
||||||
|
import '../state/source.dart';
|
||||||
|
|
||||||
|
void useOnSourceChange(WidgetRef ref, void Function(int sourceId) callback) {
|
||||||
|
final sourceId = ref.watch(sourceIdProvider);
|
||||||
|
|
||||||
|
useEffect(() {
|
||||||
|
callback(sourceId);
|
||||||
|
return;
|
||||||
|
}, [sourceId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void useOnSourceSync(WidgetRef ref, void Function() callback) {
|
||||||
|
final syncService = ref.watch(syncServiceProvider);
|
||||||
|
|
||||||
|
useOnListenableChange(syncService, () {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,13 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||||
|
|
||||||
import '../../sources/models.dart';
|
import '../../sources/models.dart';
|
||||||
|
import '../hooks/use_on_source.dart';
|
||||||
import '../hooks/use_paging_controller.dart';
|
import '../hooks/use_paging_controller.dart';
|
||||||
import '../state/database.dart';
|
import '../state/database.dart';
|
||||||
import '../state/source.dart';
|
|
||||||
import 'list_items.dart';
|
import 'list_items.dart';
|
||||||
|
|
||||||
const kPageSize = 60;
|
const kPageSize = 60;
|
||||||
@ -18,8 +17,6 @@ class AlbumsGrid extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final db = ref.watch(databaseProvider);
|
final db = ref.watch(databaseProvider);
|
||||||
final sourceId = ref.watch(sourceIdProvider);
|
|
||||||
|
|
||||||
final controller = usePagingController<int, Album>(
|
final controller = usePagingController<int, Album>(
|
||||||
getNextPageKey: (state) =>
|
getNextPageKey: (state) =>
|
||||||
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
||||||
@ -29,10 +26,8 @@ class AlbumsGrid extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() {
|
useOnSourceChange(ref, (_) => controller.refresh());
|
||||||
controller.refresh();
|
useOnSourceSync(ref, controller.refresh);
|
||||||
return;
|
|
||||||
}, [sourceId]);
|
|
||||||
|
|
||||||
return PagingListener(
|
return PagingListener(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||||
|
|
||||||
import '../../sources/models.dart';
|
import '../../sources/models.dart';
|
||||||
|
import '../hooks/use_on_source.dart';
|
||||||
import '../hooks/use_paging_controller.dart';
|
import '../hooks/use_paging_controller.dart';
|
||||||
import '../state/database.dart';
|
import '../state/database.dart';
|
||||||
import '../state/source.dart';
|
|
||||||
import 'list_items.dart';
|
import 'list_items.dart';
|
||||||
|
|
||||||
const kPageSize = 30;
|
const kPageSize = 30;
|
||||||
@ -20,8 +19,6 @@ class ArtistsList extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final db = ref.watch(databaseProvider);
|
final db = ref.watch(databaseProvider);
|
||||||
final sourceId = ref.watch(sourceIdProvider);
|
|
||||||
|
|
||||||
final controller = usePagingController<int, _ArtistItem>(
|
final controller = usePagingController<int, _ArtistItem>(
|
||||||
getNextPageKey: (state) =>
|
getNextPageKey: (state) =>
|
||||||
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
||||||
@ -31,10 +28,8 @@ class ArtistsList extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() {
|
useOnSourceChange(ref, (_) => controller.refresh());
|
||||||
controller.refresh();
|
useOnSourceSync(ref, controller.refresh);
|
||||||
return;
|
|
||||||
}, [sourceId]);
|
|
||||||
|
|
||||||
return PagingListener(
|
return PagingListener(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ final databaseInitializer = FutureProvider<SubtracksDatabase>((ref) async {
|
|||||||
SourcesCompanion.insert(
|
SourcesCompanion.insert(
|
||||||
id: Value(1),
|
id: Value(1),
|
||||||
name: 'test subsonic',
|
name: 'test subsonic',
|
||||||
// isActive: Value(true),
|
isActive: Value(true),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await db
|
await db
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import 'package:async/async.dart';
|
import 'package:async/async.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
import '../database/database.dart';
|
import '../database/database.dart';
|
||||||
import '../sources/music_source.dart';
|
import '../sources/music_source.dart';
|
||||||
|
|
||||||
const kSliceSize = 200;
|
const kSliceSize = 200;
|
||||||
|
|
||||||
class SyncService {
|
class SyncService with ChangeNotifier {
|
||||||
SyncService({
|
SyncService({
|
||||||
required this.source,
|
required this.source,
|
||||||
required this.db,
|
required this.db,
|
||||||
@ -28,6 +29,7 @@ class SyncService {
|
|||||||
syncPlaylistSongs(),
|
syncPlaylistSongs(),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> syncArtists() async {
|
Future<void> syncArtists() async {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user