refactor(ui): Extract ServerJobsListTitle

This commit is contained in:
Inex Code 2024-11-06 00:57:56 +03:00
parent 529a9e515a
commit 791e895dc7
2 changed files with 33 additions and 21 deletions

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:selfprivacy/logic/models/json/server_job.dart'; import 'package:selfprivacy/logic/models/json/server_job.dart';
IconData getJobIcon(final JobStatusEnum status) { IconData getJobIcon(final JobStatusEnum status) {
switch (status) { switch (status) {
case JobStatusEnum.created: case JobStatusEnum.created:

View file

@ -123,26 +123,8 @@ class JobsContent extends StatelessWidget {
const Divider(height: 0), const Divider(height: 0),
const Gap(16), const Gap(16),
if (serverJobs.isNotEmpty) if (serverJobs.isNotEmpty)
Padding( _ServerJobsListTitle(
padding: const EdgeInsets.all(8.0), hasRemovableJobs: hasRemovableJobs,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'jobs.server_jobs'.tr(),
style: Theme.of(context).textTheme.titleMedium,
),
IconButton(
onPressed: hasRemovableJobs
? () => context
.read<ServerJobsBloc>()
.add(RemoveAllFinishedJobs())
: null,
icon: const Icon(Icons.clear_all),
color: Theme.of(context).colorScheme.onSurface,
),
],
),
), ),
...serverJobs ...serverJobs
.whereNot((final job) => job.uid == state.rebuildJobUid) .whereNot((final job) => job.uid == state.rebuildJobUid)
@ -361,3 +343,34 @@ class _ServerJobStatusCardInClientJobs extends StatelessWidget {
], ],
); );
} }
class _ServerJobsListTitle extends StatelessWidget {
const _ServerJobsListTitle({
required this.hasRemovableJobs,
});
final bool hasRemovableJobs;
@override
Widget build(final BuildContext context) => Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'jobs.server_jobs'.tr(),
style: Theme.of(context).textTheme.titleMedium,
),
IconButton(
onPressed: hasRemovableJobs
? () => context
.read<ServerJobsBloc>()
.add(RemoveAllFinishedJobs())
: null,
icon: const Icon(Icons.clear_all),
color: Theme.of(context).colorScheme.onSurface,
),
],
),
);
}