From 791e895dc743f1e5308392b414d20682d4b3d8f5 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 6 Nov 2024 00:57:56 +0300 Subject: [PATCH] refactor(ui): Extract ServerJobsListTitle --- lib/ui/components/jobs_content/job_icon.dart | 1 - .../components/jobs_content/jobs_content.dart | 53 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/ui/components/jobs_content/job_icon.dart b/lib/ui/components/jobs_content/job_icon.dart index 5eba420d..d3b0c211 100644 --- a/lib/ui/components/jobs_content/job_icon.dart +++ b/lib/ui/components/jobs_content/job_icon.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:selfprivacy/logic/models/json/server_job.dart'; - IconData getJobIcon(final JobStatusEnum status) { switch (status) { case JobStatusEnum.created: diff --git a/lib/ui/components/jobs_content/jobs_content.dart b/lib/ui/components/jobs_content/jobs_content.dart index fbd52b9f..24465cb4 100644 --- a/lib/ui/components/jobs_content/jobs_content.dart +++ b/lib/ui/components/jobs_content/jobs_content.dart @@ -123,26 +123,8 @@ class JobsContent extends StatelessWidget { const Divider(height: 0), const Gap(16), if (serverJobs.isNotEmpty) - 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() - .add(RemoveAllFinishedJobs()) - : null, - icon: const Icon(Icons.clear_all), - color: Theme.of(context).colorScheme.onSurface, - ), - ], - ), + _ServerJobsListTitle( + hasRemovableJobs: hasRemovableJobs, ), ...serverJobs .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() + .add(RemoveAllFinishedJobs()) + : null, + icon: const Icon(Icons.clear_all), + color: Theme.of(context).colorScheme.onSurface, + ), + ], + ), + ); +}