feat: redesign and lots of progress
This commit is contained in:
@ -32,6 +32,15 @@ class NConnectedDevices extends _$NConnectedDevices {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<Result<void>> updateConnectedDeviceLastConnected(int id) async {
|
||||
final db = ref.watch(databaseProvider);
|
||||
final res = await db.updateConnectedDeviceLastConnected(id);
|
||||
if (res.isOk()) {
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for the [AppDatabase] instance
|
||||
@ -137,6 +146,22 @@ class AppDatabase extends _$AppDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Result<void>> updateConnectedDeviceLastConnected(int id) async {
|
||||
try {
|
||||
final count = await (update(connectedDevices)
|
||||
..where((tbl) => tbl.id.equals(id)))
|
||||
.write(ConnectedDevicesCompanion(
|
||||
lastConnectedAt: Value(DateTime.now())));
|
||||
if (count == 0) {
|
||||
return bail('Device with id $id not found.');
|
||||
}
|
||||
return Ok(());
|
||||
} catch (e, st) {
|
||||
return bail(
|
||||
'Failed to update last connected time for device $id: $e', st);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<ConnectedDevice>> getAllConnectedDevicesStream() {
|
||||
return select(connectedDevices).watch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user