mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 00:59:28 +01:00
active source/id from db watch
This commit is contained in:
parent
b5d52a034d
commit
de9bc98044
@ -7,7 +7,7 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import '../../sources/models.dart';
|
||||
import '../hooks/use_paging_controller.dart';
|
||||
import '../state/database.dart';
|
||||
import '../state/settings.dart';
|
||||
import '../state/source.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 60;
|
||||
|
||||
@ -7,7 +7,7 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import '../../sources/models.dart';
|
||||
import '../hooks/use_paging_controller.dart';
|
||||
import '../state/database.dart';
|
||||
import '../state/settings.dart';
|
||||
import '../state/source.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 30;
|
||||
|
||||
@ -13,7 +13,7 @@ class PreloadScreen extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final initializers = [
|
||||
ref.watch(databaseInitializer),
|
||||
ref.watch(sourceInitializer),
|
||||
ref.watch(activeSourceInitializer),
|
||||
ref.watch(packageInfoInitializer),
|
||||
];
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ final databaseInitializer = FutureProvider<SubtracksDatabase>((ref) async {
|
||||
SourcesCompanion.insert(
|
||||
id: Value(1),
|
||||
name: 'test navidrome',
|
||||
isActive: Value(true),
|
||||
),
|
||||
);
|
||||
await db
|
||||
|
||||
@ -2,7 +2,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../services/sync_service.dart';
|
||||
import 'database.dart';
|
||||
import 'settings.dart';
|
||||
import 'source.dart';
|
||||
|
||||
final syncServiceProvider = Provider<SyncService>((ref) {
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
final sourceIdProvider = Provider<int>((ref) {
|
||||
return 1;
|
||||
});
|
||||
|
||||
final packageInfoInitializer = FutureProvider<PackageInfo>((ref) {
|
||||
return PackageInfo.fromPlatform();
|
||||
});
|
||||
|
||||
@ -1,38 +1,43 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../sources/music_source.dart';
|
||||
import '../../sources/subsonic/client.dart';
|
||||
import '../../sources/subsonic/source.dart';
|
||||
import '../../util/http.dart';
|
||||
import 'database.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
final sourceInitializer = FutureProvider<MusicSource>((ref) async {
|
||||
final activeSourceInitializer = StreamProvider<(int, SubsonicSource)>((
|
||||
ref,
|
||||
) async* {
|
||||
final db = ref.watch(databaseProvider);
|
||||
final sourceId = ref.watch(sourceIdProvider);
|
||||
|
||||
final query = db.sources.select().join([
|
||||
leftOuterJoin(
|
||||
db.subsonicSettings,
|
||||
db.subsonicSettings.sourceId.equalsExp(db.sources.id),
|
||||
),
|
||||
])..where(db.sources.id.equals(sourceId));
|
||||
final activeSource = db.managers.sources
|
||||
.filter((f) => f.isActive.equals(true))
|
||||
.watchSingle();
|
||||
|
||||
final result = await query.getSingle();
|
||||
final subsonicSettings = result.readTable(db.subsonicSettings);
|
||||
await for (final source in activeSource) {
|
||||
final subsonicSettings = await db.managers.subsonicSettings
|
||||
.filter((f) => f.sourceId.equals(source.id))
|
||||
.getSingle();
|
||||
|
||||
return SubsonicSource(
|
||||
SubsonicClient(
|
||||
http: SubtracksHttpClient(),
|
||||
address: subsonicSettings.address,
|
||||
username: subsonicSettings.username,
|
||||
password: subsonicSettings.password,
|
||||
useTokenAuth: subsonicSettings.useTokenAuth,
|
||||
),
|
||||
);
|
||||
yield (
|
||||
source.id,
|
||||
SubsonicSource(
|
||||
SubsonicClient(
|
||||
http: SubtracksHttpClient(),
|
||||
address: subsonicSettings.address,
|
||||
username: subsonicSettings.username,
|
||||
password: subsonicSettings.password,
|
||||
useTokenAuth: subsonicSettings.useTokenAuth,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
final sourceProvider = Provider<MusicSource>((ref) {
|
||||
return ref.watch(sourceInitializer).value!;
|
||||
final sourceProvider = Provider<SubsonicSource>((ref) {
|
||||
return ref.watch(activeSourceInitializer).value!.$2;
|
||||
});
|
||||
|
||||
final sourceIdProvider = Provider<int>((ref) {
|
||||
return ref.watch(activeSourceInitializer).value!.$1;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user