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 '../../sources/models.dart';
|
||||||
import '../hooks/use_paging_controller.dart';
|
import '../hooks/use_paging_controller.dart';
|
||||||
import '../state/database.dart';
|
import '../state/database.dart';
|
||||||
import '../state/settings.dart';
|
import '../state/source.dart';
|
||||||
import 'list_items.dart';
|
import 'list_items.dart';
|
||||||
|
|
||||||
const kPageSize = 60;
|
const kPageSize = 60;
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|||||||
import '../../sources/models.dart';
|
import '../../sources/models.dart';
|
||||||
import '../hooks/use_paging_controller.dart';
|
import '../hooks/use_paging_controller.dart';
|
||||||
import '../state/database.dart';
|
import '../state/database.dart';
|
||||||
import '../state/settings.dart';
|
import '../state/source.dart';
|
||||||
import 'list_items.dart';
|
import 'list_items.dart';
|
||||||
|
|
||||||
const kPageSize = 30;
|
const kPageSize = 30;
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class PreloadScreen extends HookConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final initializers = [
|
final initializers = [
|
||||||
ref.watch(databaseInitializer),
|
ref.watch(databaseInitializer),
|
||||||
ref.watch(sourceInitializer),
|
ref.watch(activeSourceInitializer),
|
||||||
ref.watch(packageInfoInitializer),
|
ref.watch(packageInfoInitializer),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ final databaseInitializer = FutureProvider<SubtracksDatabase>((ref) async {
|
|||||||
SourcesCompanion.insert(
|
SourcesCompanion.insert(
|
||||||
id: Value(1),
|
id: Value(1),
|
||||||
name: 'test navidrome',
|
name: 'test navidrome',
|
||||||
|
isActive: Value(true),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await db
|
await db
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
|
|
||||||
import '../../services/sync_service.dart';
|
import '../../services/sync_service.dart';
|
||||||
import 'database.dart';
|
import 'database.dart';
|
||||||
import 'settings.dart';
|
|
||||||
import 'source.dart';
|
import 'source.dart';
|
||||||
|
|
||||||
final syncServiceProvider = Provider<SyncService>((ref) {
|
final syncServiceProvider = Provider<SyncService>((ref) {
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
final sourceIdProvider = Provider<int>((ref) {
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
final packageInfoInitializer = FutureProvider<PackageInfo>((ref) {
|
final packageInfoInitializer = FutureProvider<PackageInfo>((ref) {
|
||||||
return PackageInfo.fromPlatform();
|
return PackageInfo.fromPlatform();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,38 +1,43 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
import '../../sources/music_source.dart';
|
|
||||||
import '../../sources/subsonic/client.dart';
|
import '../../sources/subsonic/client.dart';
|
||||||
import '../../sources/subsonic/source.dart';
|
import '../../sources/subsonic/source.dart';
|
||||||
import '../../util/http.dart';
|
import '../../util/http.dart';
|
||||||
import 'database.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 db = ref.watch(databaseProvider);
|
||||||
final sourceId = ref.watch(sourceIdProvider);
|
|
||||||
|
|
||||||
final query = db.sources.select().join([
|
final activeSource = db.managers.sources
|
||||||
leftOuterJoin(
|
.filter((f) => f.isActive.equals(true))
|
||||||
db.subsonicSettings,
|
.watchSingle();
|
||||||
db.subsonicSettings.sourceId.equalsExp(db.sources.id),
|
|
||||||
),
|
|
||||||
])..where(db.sources.id.equals(sourceId));
|
|
||||||
|
|
||||||
final result = await query.getSingle();
|
await for (final source in activeSource) {
|
||||||
final subsonicSettings = result.readTable(db.subsonicSettings);
|
final subsonicSettings = await db.managers.subsonicSettings
|
||||||
|
.filter((f) => f.sourceId.equals(source.id))
|
||||||
|
.getSingle();
|
||||||
|
|
||||||
return SubsonicSource(
|
yield (
|
||||||
SubsonicClient(
|
source.id,
|
||||||
http: SubtracksHttpClient(),
|
SubsonicSource(
|
||||||
address: subsonicSettings.address,
|
SubsonicClient(
|
||||||
username: subsonicSettings.username,
|
http: SubtracksHttpClient(),
|
||||||
password: subsonicSettings.password,
|
address: subsonicSettings.address,
|
||||||
useTokenAuth: subsonicSettings.useTokenAuth,
|
username: subsonicSettings.username,
|
||||||
),
|
password: subsonicSettings.password,
|
||||||
);
|
useTokenAuth: subsonicSettings.useTokenAuth,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final sourceProvider = Provider<MusicSource>((ref) {
|
final sourceProvider = Provider<SubsonicSource>((ref) {
|
||||||
return ref.watch(sourceInitializer).value!;
|
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