selfprivacy.org.app/lib/ui/components/jobs_content/jobs_content.dart

110 lines
3.9 KiB
Dart
Raw Normal View History

2021-05-25 21:53:54 +00:00
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
2021-07-29 05:24:42 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
2021-05-25 21:53:54 +00:00
import 'package:selfprivacy/config/brand_colors.dart';
2021-06-20 21:08:52 +00:00
import 'package:selfprivacy/config/brand_theme.dart';
2021-12-06 18:31:19 +00:00
import 'package:selfprivacy/config/get_it_config.dart';
2021-05-25 21:53:54 +00:00
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
2021-12-06 18:31:19 +00:00
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
2021-05-25 21:53:54 +00:00
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
2021-07-29 05:24:42 +00:00
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
2021-05-25 21:53:54 +00:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
class JobsContent extends StatelessWidget {
const JobsContent({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2021-07-29 05:24:42 +00:00
return BlocBuilder<JobsCubit, JobsState>(
builder: (context, state) {
late final List<Widget> widgets;
if (state is JobsStateEmpty) {
widgets = [
SizedBox(height: 80),
Center(child: BrandText.body1('jobs.empty'.tr())),
2021-12-06 18:31:19 +00:00
SizedBox(height: 80),
BrandButton.rised(
onPressed: () => context.read<JobsCubit>().upgradeServer(),
text: 'jobs.upgradeServer'.tr(),
),
SizedBox(height: 10),
BrandButton.text(
onPressed: () {
var nav = getIt<NavigationService>();
nav.showPopUpDialog(BrandAlert(
title: 'jobs.rebootServer'.tr(),
contentText: 'modals.3'.tr(),
actions: [
ActionButton(
text: 'basis.cancel'.tr(),
),
ActionButton(
onPressed: () =>
{context.read<JobsCubit>().rebootServer()},
text: 'modals.9'.tr(),
)
],
));
},
title: 'jobs.rebootServer'.tr(),
),
2021-07-29 05:24:42 +00:00
];
} else if (state is JobsStateLoading) {
widgets = [
SizedBox(height: 80),
BrandLoader.horizontal(),
];
} else if (state is JobsStateWithJobs) {
widgets = [
...state.jobList
.map(
(j) => Row(
children: [
Expanded(
child: BrandCards.small(
2021-08-29 15:02:51 +00:00
child: Text(j.title),
2021-05-25 21:53:54 +00:00
),
),
2021-07-29 05:24:42 +00:00
SizedBox(width: 10),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: BrandColors.red1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
2021-05-25 21:53:54 +00:00
),
2021-07-29 05:24:42 +00:00
onPressed: () =>
context.read<JobsCubit>().removeJob(j.id),
child: Text('basis.remove'.tr()),
2021-05-25 21:53:54 +00:00
),
2021-07-29 05:24:42 +00:00
],
),
)
.toList(),
SizedBox(height: 20),
BrandButton.rised(
onPressed: () => context.read<JobsCubit>().applyAll(),
text: 'jobs.start'.tr(),
),
];
}
return ListView(
padding: paddingH15V0,
children: [
SizedBox(height: 15),
Center(
child: BrandText.h2(
'jobs.title'.tr(),
),
),
SizedBox(height: 20),
...widgets
],
);
},
2021-05-25 21:53:54 +00:00
);
}
}