mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +00:00
refactor(services): Remove services switch on services screen cards
This commit is contained in:
parent
f24137cd98
commit
e342727181
|
@ -4,14 +4,11 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:selfprivacy/config/brand_theme.dart';
|
import 'package:selfprivacy/config/brand_theme.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
|
||||||
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/job.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/service.dart';
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
import 'package:selfprivacy/logic/models/state_types.dart';
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_switch/brand_switch.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||||
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
||||||
|
@ -21,14 +18,6 @@ import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||||
import 'package:selfprivacy/utils/ui_helpers.dart';
|
import 'package:selfprivacy/utils/ui_helpers.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
const switchableServices = [
|
|
||||||
'bitwarden',
|
|
||||||
'nextcloud',
|
|
||||||
'pleroma',
|
|
||||||
'gitea',
|
|
||||||
'ocserv',
|
|
||||||
];
|
|
||||||
|
|
||||||
class ServicesPage extends StatefulWidget {
|
class ServicesPage extends StatefulWidget {
|
||||||
const ServicesPage({super.key});
|
const ServicesPage({super.key});
|
||||||
|
|
||||||
|
@ -100,24 +89,28 @@ class _Card extends StatelessWidget {
|
||||||
final isReady = context.watch<ServerInstallationCubit>().state
|
final isReady = context.watch<ServerInstallationCubit>().state
|
||||||
is ServerInstallationFinished;
|
is ServerInstallationFinished;
|
||||||
|
|
||||||
final serviceState = context.watch<ServicesCubit>().state;
|
|
||||||
final jobsCubit = context.watch<JobsCubit>();
|
|
||||||
final jobState = jobsCubit.state;
|
|
||||||
|
|
||||||
final switchableService = switchableServices.contains(service.id);
|
|
||||||
final hasSwitchJob = switchableService &&
|
|
||||||
jobState is JobsStateWithJobs &&
|
|
||||||
jobState.clientJobList.any(
|
|
||||||
(final el) => el is ServiceToggleJob && el.id == service.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
final isSwitchOn = isReady &&
|
|
||||||
(!switchableServices.contains(service.id) ||
|
|
||||||
serviceState.isEnableByType(service));
|
|
||||||
|
|
||||||
final config = context.watch<ServerInstallationCubit>().state;
|
final config = context.watch<ServerInstallationCubit>().state;
|
||||||
final domainName = UiHelpers.getDomainName(config);
|
final domainName = UiHelpers.getDomainName(config);
|
||||||
|
|
||||||
|
StateType getStatus(final ServiceStatus status) {
|
||||||
|
switch (status) {
|
||||||
|
case ServiceStatus.active:
|
||||||
|
return StateType.stable;
|
||||||
|
case ServiceStatus.activating:
|
||||||
|
return StateType.stable;
|
||||||
|
case ServiceStatus.deactivating:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.inactive:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.failed:
|
||||||
|
return StateType.error;
|
||||||
|
case ServiceStatus.off:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.reloading:
|
||||||
|
return StateType.stable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: isReady
|
onTap: isReady
|
||||||
? () => Navigator.of(context)
|
? () => Navigator.of(context)
|
||||||
|
@ -130,8 +123,7 @@ class _Card extends StatelessWidget {
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
IconStatusMask(
|
IconStatusMask(
|
||||||
status:
|
status: getStatus(service.status),
|
||||||
isSwitchOn ? StateType.stable : StateType.uninitialized,
|
|
||||||
icon: SvgPicture.string(
|
icon: SvgPicture.string(
|
||||||
service.svgIcon,
|
service.svgIcon,
|
||||||
width: 30.0,
|
width: 30.0,
|
||||||
|
@ -139,33 +131,6 @@ class _Card extends StatelessWidget {
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
color: Theme.of(context).colorScheme.onBackground,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (isReady && switchableService) ...[
|
|
||||||
const Spacer(),
|
|
||||||
Builder(
|
|
||||||
builder: (final context) {
|
|
||||||
late bool isActive;
|
|
||||||
if (hasSwitchJob) {
|
|
||||||
isActive = (jobState.clientJobList.firstWhere(
|
|
||||||
(final el) =>
|
|
||||||
el is ServiceToggleJob && el.id == service.id,
|
|
||||||
) as ServiceToggleJob)
|
|
||||||
.needToTurnOn;
|
|
||||||
} else {
|
|
||||||
isActive = serviceState.isEnableByType(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BrandSwitch(
|
|
||||||
value: isActive,
|
|
||||||
onChanged: (final value) => jobsCubit.addJob(
|
|
||||||
ServiceToggleJob(
|
|
||||||
service: service,
|
|
||||||
needToTurnOn: value,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ClipRect(
|
ClipRect(
|
||||||
|
@ -215,22 +180,6 @@ class _Card extends StatelessWidget {
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (hasSwitchJob)
|
|
||||||
Positioned(
|
|
||||||
bottom: 24,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
child: BackdropFilter(
|
|
||||||
filter: ImageFilter.blur(
|
|
||||||
sigmaX: 3,
|
|
||||||
sigmaY: 2,
|
|
||||||
),
|
|
||||||
child: BrandText.h2(
|
|
||||||
'jobs.run_jobs'.tr(),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue