mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(job): Fix server settings toogles not creating upgrade server job
This commit is contained in:
parent
e619d6351f
commit
db2f5c1342
|
@ -24,14 +24,10 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
final ServicesCubit servicesCubit;
|
||||
|
||||
void addJob(final ClientJob job) {
|
||||
final List<ClientJob> newJobsList = [];
|
||||
if (state is JobsStateWithJobs) {
|
||||
final JobsStateWithJobs jobsState = state as JobsStateWithJobs;
|
||||
newJobsList.addAll(jobsState.clientJobList);
|
||||
}
|
||||
newJobsList.add(job);
|
||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||
emit(JobsStateWithJobs(newJobsList));
|
||||
_updateJobsState([
|
||||
...currentJobList,
|
||||
...[job]
|
||||
]);
|
||||
}
|
||||
|
||||
void removeJob(final String id) {
|
||||
|
@ -58,17 +54,28 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
}
|
||||
}
|
||||
|
||||
void createShhJobIfNotExist(final CreateSSHKeyJob job) {
|
||||
final List<ClientJob> newJobsList = <ClientJob>[];
|
||||
List<ClientJob> get currentJobList {
|
||||
final List<ClientJob> jobs = <ClientJob>[];
|
||||
if (state is JobsStateWithJobs) {
|
||||
newJobsList.addAll((state as JobsStateWithJobs).clientJobList);
|
||||
jobs.addAll((state as JobsStateWithJobs).clientJobList);
|
||||
}
|
||||
final bool isExistInJobList =
|
||||
newJobsList.any((final el) => el is CreateSSHKeyJob);
|
||||
if (!isExistInJobList) {
|
||||
newJobsList.add(job);
|
||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||
emit(JobsStateWithJobs(newJobsList));
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
void _updateJobsState(final List<ClientJob> newJobs) {
|
||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||
emit(JobsStateWithJobs(newJobs));
|
||||
}
|
||||
|
||||
void addUniqueJob<J extends ClientJob>(final J job) {
|
||||
final List<ClientJob> jobs = currentJobList;
|
||||
final bool exists = jobs.any((final el) => el is J);
|
||||
if (!exists) {
|
||||
_updateJobsState([
|
||||
...jobs,
|
||||
...[job]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ class _ServerSettings extends StatefulWidget {
|
|||
class _ServerSettingsState extends State<_ServerSettings> {
|
||||
bool? allowAutoUpgrade;
|
||||
bool? rebootAfterUpgrade;
|
||||
bool? didSomethingChange;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
|
@ -25,18 +24,14 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
rebootAfterUpgrade = serverDetailsState.autoUpgradeSettings.allowReboot;
|
||||
}
|
||||
|
||||
didSomethingChange ??= false;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
value: allowAutoUpgrade ?? false,
|
||||
onChanged: (final switched) {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
}
|
||||
context.read<JobsCubit>().addUniqueJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
context
|
||||
.read<ServerDetailsCubit>()
|
||||
.repository
|
||||
|
@ -48,7 +43,6 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
);
|
||||
setState(() {
|
||||
allowAutoUpgrade = switched;
|
||||
didSomethingChange = true;
|
||||
});
|
||||
},
|
||||
title: Text('server.allow_autoupgrade'.tr()),
|
||||
|
@ -60,11 +54,9 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
SwitchListTile(
|
||||
value: rebootAfterUpgrade ?? false,
|
||||
onChanged: (final switched) {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
}
|
||||
context.read<JobsCubit>().addUniqueJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
context
|
||||
.read<ServerDetailsCubit>()
|
||||
.repository
|
||||
|
@ -76,7 +68,6 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
);
|
||||
setState(() {
|
||||
rebootAfterUpgrade = switched;
|
||||
didSomethingChange = true;
|
||||
});
|
||||
},
|
||||
title: Text('server.reboot_after_upgrade'.tr()),
|
||||
|
@ -91,14 +82,9 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
serverDetailsState.serverTimezone.toString(),
|
||||
),
|
||||
onTap: () {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
didSomethingChange = true;
|
||||
});
|
||||
context.read<JobsCubit>().addUniqueJob(
|
||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||
);
|
||||
Navigator.of(context).push(
|
||||
materialRoute(
|
||||
const SelectTimezone(),
|
||||
|
|
Loading…
Reference in a new issue