refactor container assign logic
This commit is contained in:
@@ -1,16 +1,41 @@
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/providers.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container.dart';
|
||||
|
||||
part 'tab.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class TabDataRepository extends _$TabDataRepository {
|
||||
Future<void> assignContainer(String tabId, String? containerId) {
|
||||
return ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.assignContainer(tabId, containerId: containerId);
|
||||
Future<void> assignContainer(
|
||||
String tabId,
|
||||
ContainerData targetContainer,
|
||||
) async {
|
||||
final currentContainerId = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.containerTabId(tabId);
|
||||
|
||||
final currentContainerData = await currentContainerId.mapNotNull(
|
||||
(containerId) => ref
|
||||
.read(containerRepositoryProvider.notifier)
|
||||
.getContainerData(containerId),
|
||||
);
|
||||
|
||||
if (targetContainer.metadata.contextualIdentity ==
|
||||
currentContainerData?.metadata.contextualIdentity) {
|
||||
await ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.assignContainer(tabId, containerId: targetContainer.id);
|
||||
} else {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(selectTabId: tabId, containerId: targetContainer.id);
|
||||
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignOrderKey(String tabId, String orderKey) {
|
||||
|
||||
@@ -6,7 +6,7 @@ part of 'tab.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$tabDataRepositoryHash() => r'0de1de9f948e38cc0a6d2fc18a06b1327d41c7ca';
|
||||
String _$tabDataRepositoryHash() => r'15be3ca749b329c293e8e18c61d6ed92e4979072';
|
||||
|
||||
/// See also [TabDataRepository].
|
||||
@ProviderFor(TabDataRepository)
|
||||
|
||||
@@ -108,6 +108,9 @@ class ContainerListScreen extends HookConsumerWidget {
|
||||
child: ContainerListTile(
|
||||
container,
|
||||
isSelected: container.id == selectedContainer,
|
||||
onTap: () async {
|
||||
await ContainerEditRoute(container).push(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -119,6 +122,7 @@ class ContainerListScreen extends HookConsumerWidget {
|
||||
itemCount: 3,
|
||||
itemBuilder: (context, index) => ContainerListTile(
|
||||
ContainerData(id: 'null', color: Colors.transparent),
|
||||
onTap: null,
|
||||
isSelected: false,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -6,10 +6,8 @@ import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/core/providers/global_drop.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/data/models/drag_data.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
|
||||
|
||||
@@ -103,40 +101,13 @@ class ContainerChips extends HookConsumerWidget {
|
||||
overlayController.hide();
|
||||
},
|
||||
onAcceptWithDetails: (details) async {
|
||||
final containerId = await ref
|
||||
await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.containerTabId(details.data.tabId);
|
||||
|
||||
final containerData = await containerId
|
||||
.mapNotNull(
|
||||
(containerId) => ref
|
||||
.read(
|
||||
containerRepositoryProvider.notifier,
|
||||
)
|
||||
.getContainerData(containerId),
|
||||
.assignContainer(
|
||||
details.data.tabId,
|
||||
container,
|
||||
);
|
||||
|
||||
if (container.metadata.contextualIdentity ==
|
||||
containerData?.metadata.contextualIdentity) {
|
||||
await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.assignContainer(
|
||||
details.data.tabId,
|
||||
container.id,
|
||||
);
|
||||
} else {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(
|
||||
selectTabId: details.data.tabId,
|
||||
containerId: container.id,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(details.data.tabId);
|
||||
}
|
||||
|
||||
dragTargetTabId.value = null;
|
||||
overlayController.hide();
|
||||
},
|
||||
|
||||
+3
-4
@@ -1,14 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||
|
||||
class ContainerListTile extends HookWidget {
|
||||
final ContainerData container;
|
||||
final GestureTapCallback? onTap;
|
||||
final bool isSelected;
|
||||
|
||||
const ContainerListTile(
|
||||
this.container, {
|
||||
required this.onTap,
|
||||
required this.isSelected,
|
||||
super.key,
|
||||
});
|
||||
@@ -22,9 +23,7 @@ class ContainerListTile extends HookWidget {
|
||||
selected: isSelected,
|
||||
leading: CircleAvatar(backgroundColor: container.color),
|
||||
title: Text(container.name ?? 'New Container'),
|
||||
onTap: () async {
|
||||
await ContainerEditRoute(container).push(context);
|
||||
},
|
||||
onTap: onTap,
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user