upsert container when cloning
This commit is contained in:
@@ -127,8 +127,10 @@ class TabRepository extends _$TabRepository {
|
||||
.toSet();
|
||||
|
||||
// Batch validate parent IDs that aren't in the current creation batch
|
||||
final existingParentIds =
|
||||
await tabDao.getExistingTabIds(parentIdsToValidate).get().then((ids) => ids.toSet());
|
||||
final existingParentIds = await tabDao
|
||||
.getExistingTabIds(parentIdsToValidate)
|
||||
.get()
|
||||
.then((ids) => ids.toSet());
|
||||
|
||||
// Upsert all tabs in the database
|
||||
for (var i = 0; i < createdTabIds.length; i++) {
|
||||
@@ -160,17 +162,11 @@ class TabRepository extends _$TabRepository {
|
||||
|
||||
Future<String> duplicateTab({
|
||||
required String selectTabId,
|
||||
required String? containerId,
|
||||
required ContainerData? containerData,
|
||||
required bool selectTab,
|
||||
}) async {
|
||||
final tabDao = ref.read(tabDatabaseProvider).tabDao;
|
||||
|
||||
final containerData = await containerId.mapNotNull(
|
||||
(containerId) => ref
|
||||
.read(containerRepositoryProvider.notifier)
|
||||
.getContainerData(containerId),
|
||||
);
|
||||
|
||||
return await tabDao.upsertTabTransactional(
|
||||
() {
|
||||
return _tabsService.duplicateTab(
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabRepositoryHash() => r'6a66c2f1f8d00767d19e6125d4eafc6d93381c8a';
|
||||
String _$tabRepositoryHash() => r'ab4ba2bf11ccbd99497819b9068cbbd733a93d81';
|
||||
|
||||
abstract class _$TabRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -195,6 +196,9 @@ class TabMenu extends HookConsumerWidget {
|
||||
child: const Text('Regular'),
|
||||
onPressed: () async {
|
||||
final tabState = ref.read(tabStateProvider(selectedTabId))!;
|
||||
final containerData = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.getTabContainerData(selectedTabId);
|
||||
|
||||
final tabId = (tabState.isPrivate)
|
||||
? await ref
|
||||
@@ -202,13 +206,14 @@ class TabMenu extends HookConsumerWidget {
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: false,
|
||||
container: Value(containerData),
|
||||
selectTab: false,
|
||||
)
|
||||
: await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(
|
||||
selectTabId: selectedTabId,
|
||||
containerId: tabState.contextId,
|
||||
containerData: containerData,
|
||||
selectTab: false,
|
||||
);
|
||||
|
||||
@@ -230,6 +235,9 @@ class TabMenu extends HookConsumerWidget {
|
||||
child: const Text('Private'),
|
||||
onPressed: () async {
|
||||
final tabState = ref.read(tabStateProvider(selectedTabId))!;
|
||||
final containerData = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.getTabContainerData(selectedTabId);
|
||||
|
||||
final tabId = (!tabState.isPrivate)
|
||||
? await ref
|
||||
@@ -237,13 +245,14 @@ class TabMenu extends HookConsumerWidget {
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: true,
|
||||
container: Value(containerData),
|
||||
selectTab: false,
|
||||
)
|
||||
: await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(
|
||||
selectTabId: selectedTabId,
|
||||
containerId: tabState.contextId,
|
||||
containerData: containerData,
|
||||
selectTab: false,
|
||||
);
|
||||
|
||||
|
||||
@@ -193,6 +193,14 @@ class TabDataRepository extends _$TabDataRepository {
|
||||
.getSingleOrNull();
|
||||
}
|
||||
|
||||
Future<ContainerData?> getTabContainerData(String tabId) {
|
||||
return ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.getTabContainerData(tabId)
|
||||
.getSingleOrNull();
|
||||
}
|
||||
|
||||
Future<Map<String, String?>> getTabsContainerId(Iterable<String> tabIds) {
|
||||
return ref
|
||||
.read(tabDatabaseProvider)
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabDataRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabDataRepositoryHash() => r'e6d8f328368e7525bdd970d8cb3fdea6f0f03a85';
|
||||
String _$tabDataRepositoryHash() => r'0ab598656accfc90a15a9bfef3899cd3bb577b66';
|
||||
|
||||
abstract class _$TabDataRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
Reference in New Issue
Block a user