selfprivacy.org.app/lib/logic/cubit/server_volumes/server_volume_cubit.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
2022-08-24 23:45:02 +00:00
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
import 'package:selfprivacy/logic/models/json/server_disk_volume.dart';
part 'server_volume_state.dart';
class ApiServerVolumeCubit
extends ServerInstallationDependendCubit<ApiServerVolumeState> {
ApiServerVolumeCubit(final ServerInstallationCubit serverInstallationCubit)
: super(serverInstallationCubit, const ApiServerVolumeState.initial());
final ServerApi serverApi = ServerApi();
@override
Future<void> load() async {
if (serverInstallationCubit.state is ServerInstallationFinished) {
_refetch();
}
}
Future<void> _refetch() async {
2022-09-02 05:59:46 +00:00
final volumes = await serverApi.getServerDiskVolumes();
final usesBinds = await serverApi.isUsingBinds();
var status = LoadingStatus.error;
2022-08-24 23:45:02 +00:00
if (volumes.isNotEmpty) {
2022-09-02 05:59:46 +00:00
status = LoadingStatus.success;
2022-08-24 23:45:02 +00:00
}
2022-09-02 05:59:46 +00:00
emit(ApiServerVolumeState(volumes, status, usesBinds));
2022-08-24 23:45:02 +00:00
}
@override
void clear() {
emit(const ApiServerVolumeState.initial());
}
}