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