selfprivacy.org.app/lib/ui/pages/providers/providers.dart

132 lines
4.7 KiB
Dart
Raw Normal View History

import 'package:auto_route/auto_route.dart';
import 'package:easy_localization/easy_localization.dart';
2020-12-03 16:52:53 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_theme.dart';
import 'package:selfprivacy/logic/bloc/backups/backups_bloc.dart';
import 'package:selfprivacy/logic/bloc/outdated_server_checker/outdated_server_checker_bloc.dart';
import 'package:selfprivacy/logic/bloc/volumes/volumes_bloc.dart';
2022-02-16 07:09:53 +00:00
import 'package:selfprivacy/logic/cubit/dns_records/dns_records_cubit.dart';
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
import 'package:selfprivacy/logic/models/state_types.dart';
import 'package:selfprivacy/ui/atoms/icons/brand_icons.dart';
import 'package:selfprivacy/ui/molecules/cards/not_ready_card.dart';
import 'package:selfprivacy/ui/molecules/cards/providers_page_card.dart';
import 'package:selfprivacy/ui/molecules/cards/server_outdated_card.dart';
import 'package:selfprivacy/ui/organisms/headers/brand_header.dart';
import 'package:selfprivacy/ui/router/router.dart';
import 'package:selfprivacy/utils/breakpoints.dart';
2021-03-26 13:38:39 +00:00
2022-06-05 19:36:32 +00:00
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
2020-12-03 16:52:53 +00:00
@RoutePage()
2020-12-03 16:52:53 +00:00
class ProvidersPage extends StatefulWidget {
const ProvidersPage({super.key});
2020-12-03 16:52:53 +00:00
@override
State<ProvidersPage> createState() => _ProvidersPageState();
2020-12-03 16:52:53 +00:00
}
class _ProvidersPageState extends State<ProvidersPage> {
@override
2022-06-05 19:36:32 +00:00
Widget build(final BuildContext context) {
final bool isReady = context.watch<ServerInstallationCubit>().state
is ServerInstallationFinished;
final bool isBackupInitialized =
context.watch<BackupsBloc>().state.isInitialized;
final DnsRecordsStatus dnsStatus =
context.watch<DnsRecordsCubit>().state.dnsState;
2022-02-16 07:09:53 +00:00
final diskStatus = context.watch<VolumesBloc>().state.diskStatus;
2022-09-15 21:08:14 +00:00
final ServerInstallationState appConfig =
context.watch<ServerInstallationCubit>().state;
final OutdatedServerCheckerState outdatedServerCheckerState =
context.watch<OutdatedServerCheckerBloc>().state;
2022-09-15 21:08:14 +00:00
StateType getServerStatus() {
if (!isReady) {
return StateType.uninitialized;
}
if (!diskStatus.isDiskOkay) {
return StateType.warning;
}
return StateType.stable;
}
bool isClickable() => getServerStatus() != StateType.uninitialized;
2022-02-16 07:09:53 +00:00
StateType getDnsStatus() {
if (dnsStatus == DnsRecordsStatus.uninitialized ||
dnsStatus == DnsRecordsStatus.refreshing) {
return StateType.uninitialized;
}
if (dnsStatus == DnsRecordsStatus.error) {
return StateType.warning;
}
return StateType.stable;
}
2021-01-06 17:35:57 +00:00
2020-12-03 16:52:53 +00:00
return Scaffold(
appBar: Breakpoints.small.isActive(context)
? BrandHeader(
title: 'basis.providers_title'.tr(),
)
: null,
2020-12-03 16:52:53 +00:00
body: ListView(
padding: paddingH16V0,
2021-01-06 17:35:57 +00:00
children: [
if (!isReady) ...[
2022-05-24 18:55:39 +00:00
const NotReadyCard(),
const SizedBox(height: 16),
2021-01-06 17:35:57 +00:00
],
if (outdatedServerCheckerState is OutdatedServerCheckerOutdated) ...[
ServerOutdatedCard(
requiredVersion:
outdatedServerCheckerState.requiredVersion.toString(),
currentVersion:
outdatedServerCheckerState.currentVersion.toString(),
),
const SizedBox(height: 16),
],
ProvidersPageCard(
2022-09-15 21:08:14 +00:00
state: getServerStatus(),
icon: BrandIcons.server,
title: 'server.card_title'.tr(),
2022-09-15 21:08:14 +00:00
subtitle: diskStatus.isDiskOkay
? 'storage.status_ok'.tr()
: 'storage.status_error'.tr(),
onTap: isClickable()
? () => context.pushRoute(const ServerDetailsRoute())
: null,
2022-09-15 21:08:14 +00:00
),
const SizedBox(height: 16),
ProvidersPageCard(
2022-09-15 21:08:14 +00:00
state: getDnsStatus(),
icon: BrandIcons.globe,
title: 'domain.screen_title'.tr(),
2022-09-15 21:08:14 +00:00
subtitle: appConfig.isDomainSelected
? appConfig.serverDomain!.domainName
: '',
onTap: isClickable()
? () => context.pushRoute(const DnsDetailsRoute())
: null,
2022-09-15 21:08:14 +00:00
),
const SizedBox(height: 16),
ProvidersPageCard(
2023-06-29 09:52:09 +00:00
state: isBackupInitialized
? StateType.stable
: StateType.uninitialized,
icon: BrandIcons.save,
title: 'backup.card_title'.tr(),
subtitle: isBackupInitialized ? 'backup.card_subtitle'.tr() : '',
onTap: isClickable()
? () => context.pushRoute(const BackupDetailsRoute())
: null,
2023-06-29 09:52:09 +00:00
),
2021-01-06 17:35:57 +00:00
],
2020-12-03 16:52:53 +00:00
),
);
}
}