refactor: Unify calls to show jobs modal sheets

Also open a jobs modal sheet when starting nix collect garbage

Closes #541
This commit is contained in:
Inex Code 2024-08-14 06:26:12 +03:00
parent e13b324afa
commit a490f5391b
5 changed files with 30 additions and 45 deletions

View file

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ionicons/ionicons.dart'; import 'package:ionicons/ionicons.dart';
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart'; import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart'; import 'package:selfprivacy/utils/show_jobs_modal.dart';
class BrandFab extends StatefulWidget { class BrandFab extends StatefulWidget {
const BrandFab({ const BrandFab({
@ -60,19 +60,7 @@ class _BrandFabState extends State<BrandFab>
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () { onPressed: () {
// TODO: Make a hero animation to the screen // TODO: Make a hero animation to the screen
showModalBottomSheet( showModalJobsSheet(context: context);
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (final BuildContext context) => DraggableScrollableSheet(
expand: false,
maxChildSize: 0.9,
minChildSize: 0.4,
initialChildSize: 0.6,
builder: (final context, final scrollController) =>
JobsContent(controller: scrollController),
),
);
}, },
isExtended: widget.extended, isExtended: widget.extended,
tooltip: 'jobs.title'.tr(), tooltip: 'jobs.title'.tr(),

View file

@ -4,9 +4,9 @@ import 'package:flutter/material.dart';
import 'package:ionicons/ionicons.dart'; import 'package:ionicons/ionicons.dart';
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart'; import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
import 'package:selfprivacy/ui/components/drawers/support_drawer.dart'; import 'package:selfprivacy/ui/components/drawers/support_drawer.dart';
import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart';
import 'package:selfprivacy/ui/helpers/widget_size.dart'; import 'package:selfprivacy/ui/helpers/widget_size.dart';
import 'package:selfprivacy/utils/breakpoints.dart'; import 'package:selfprivacy/utils/breakpoints.dart';
import 'package:selfprivacy/utils/show_jobs_modal.dart';
class BrandHeroScreen extends StatelessWidget { class BrandHeroScreen extends StatelessWidget {
const BrandHeroScreen({ const BrandHeroScreen({
@ -146,20 +146,7 @@ class _HeroSliverAppBarState extends State<HeroSliverAppBar> {
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {
showModalBottomSheet( showModalJobsSheet(context: context);
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (final BuildContext context) =>
DraggableScrollableSheet(
expand: false,
maxChildSize: 0.9,
minChildSize: 0.4,
initialChildSize: 0.6,
builder: (final context, final scrollController) =>
JobsContent(controller: scrollController),
),
);
}, },
icon: Icon( icon: Icon(
isJobsListEmpty ? Ionicons.flash_outline : Ionicons.flash, isJobsListEmpty ? Ionicons.flash_outline : Ionicons.flash,

View file

@ -9,9 +9,9 @@ import 'package:selfprivacy/logic/models/service.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/buttons/brand_button.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
import 'package:selfprivacy/ui/components/info_box/info_box.dart'; import 'package:selfprivacy/ui/components/info_box/info_box.dart';
import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart';
import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart'; import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart';
import 'package:selfprivacy/ui/components/storage_list_items/service_migration_list_item.dart'; import 'package:selfprivacy/ui/components/storage_list_items/service_migration_list_item.dart';
import 'package:selfprivacy/utils/show_jobs_modal.dart';
@RoutePage() @RoutePage()
class ServicesMigrationPage extends StatefulWidget { class ServicesMigrationPage extends StatefulWidget {
@ -191,20 +191,7 @@ class _ServicesMigrationPageState extends State<ServicesMigrationPage> {
} }
} }
context.router.popUntilRoot(); context.router.popUntilRoot();
showModalBottomSheet( showModalJobsSheet(context: context);
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (final BuildContext context) =>
DraggableScrollableSheet(
expand: false,
maxChildSize: 0.9,
minChildSize: 0.4,
initialChildSize: 0.6,
builder: (final context, final scrollController) =>
JobsContent(controller: scrollController),
),
);
}, },
), ),
const SizedBox(height: 32), const SizedBox(height: 32),

View file

@ -12,6 +12,7 @@ import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart'; import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart';
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
import 'package:selfprivacy/ui/router/router.dart'; import 'package:selfprivacy/ui/router/router.dart';
import 'package:selfprivacy/utils/show_jobs_modal.dart';
@RoutePage() @RoutePage()
class ServerStoragePage extends StatefulWidget { class ServerStoragePage extends StatefulWidget {
@ -73,7 +74,10 @@ class _ServerStoragePageState extends State<ServerStoragePage> {
padding: const EdgeInsets.symmetric(horizontal: 16.0), padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: BrandOutlinedButton( child: BrandOutlinedButton(
title: 'jobs.collect_nix_garbage'.tr(), title: 'jobs.collect_nix_garbage'.tr(),
onPressed: context.read<JobsCubit>().collectNixGarbage, onPressed: () {
context.read<JobsCubit>().collectNixGarbage();
showModalJobsSheet(context: context);
},
), ),
), ),
], ],

View file

@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart';
Future<T?> showModalJobsSheet<T>({
required final BuildContext context,
}) =>
showModalBottomSheet<T>(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (final BuildContext context) => DraggableScrollableSheet(
expand: false,
maxChildSize: 0.9,
minChildSize: 0.4,
initialChildSize: 0.6,
builder: (final context, final scrollController) =>
JobsContent(controller: scrollController),
),
);