From 780f0471219548052513ea39cb15929780294660 Mon Sep 17 00:00:00 2001 From: Mikhail Golovko Date: Wed, 3 Apr 2024 18:38:03 +0300 Subject: [PATCH 1/3] IOS-2591 in progress --- Anytype.xcodeproj/project.pbxproj | 60 +++++----- .../Assemblies/CoordinatorsDI.swift | 9 -- .../Assemblies/CoordinatorsDIProtocol.swift | 1 - .../LinkToObject/LinToObjectSearchView.swift | 16 +++ .../LinkToObjectSearchModuleData.swift | 18 +++ .../LinkToObjectSearchViewModel.swift | 66 +++++++---- .../Model/LinkToObjectSearchData.swift | 0 .../{ => Other}/Model/ObjectSearchData.swift | 0 .../Model/SearchViewModelProtocol.swift | 2 +- .../{ => Other}/ObjectSearchViewModel.swift | 8 +- .../ObjectLayoutSearch.swift | 0 .../WrappedSearchInteractor.swift | 0 .../{ => Other}/SearchModuleAssembly.swift | 0 .../SearchModuleAssemblyProtocol.swift | 0 .../{ => Other}/SearchModuleModel.swift | 0 .../SearchView/Cell/SearchCell.swift | 0 .../{ => Other}/SearchView/SearchBar.swift | 0 .../{ => Other}/SearchView/SearchView.swift | 2 +- .../BottomSheets/BottomSheetsFactory.swift | 6 +- .../TextAttributesView/MarkupViewModel.swift | 12 +- .../EditorPageCoordinatorView.swift | 5 + .../EditorPageCoordinatorViewModel.swift | 7 ++ .../LinkToObjectCoordinatorAssembly.swift | 37 ------ .../LinkToObjectCoordinatorOutput.swift | 5 - .../LinkToObjecttCoordinator.swift | 105 ------------------ .../SpaceSearchViewModel.swift | 8 +- .../Page/EditorPageModuleAssembly.swift | 3 - .../Page/EditorPageModuleOutput.swift | 1 + .../SimpleTableDependenciesBuilder.swift | 3 - .../Text/Base/TextBlockActionHandler.swift | 14 ++- .../Models/BlockViewModelBuilder.swift | 9 +- .../Routing/Editor/EditorRouter.swift | 15 +-- 32 files changed, 166 insertions(+), 246 deletions(-) create mode 100644 Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinToObjectSearchView.swift create mode 100644 Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchModuleData.swift rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => LinkToObject}/LinkToObjectSearchViewModel.swift (68%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/Model/LinkToObjectSearchData.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/Model/ObjectSearchData.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/Model/SearchViewModelProtocol.swift (94%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/ObjectSearchViewModel.swift (87%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchInteractors/ObjectLayoutSearch.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchInteractors/WrappedSearchInteractor.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchModuleAssembly.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchModuleAssemblyProtocol.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchModuleModel.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchView/Cell/SearchCell.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchView/SearchBar.swift (100%) rename Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/{ => Other}/SearchView/SearchView.swift (99%) delete mode 100644 Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorAssembly.swift delete mode 100644 Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorOutput.swift delete mode 100644 Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjecttCoordinator.swift diff --git a/Anytype.xcodeproj/project.pbxproj b/Anytype.xcodeproj/project.pbxproj index 20d957c4f8..ccab4cb78b 100644 --- a/Anytype.xcodeproj/project.pbxproj +++ b/Anytype.xcodeproj/project.pbxproj @@ -396,6 +396,8 @@ 2A35A6B42BBD845B00CCE4F4 /* WidgetTypeChangeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35A6B32BBD845B00CCE4F4 /* WidgetTypeChangeView.swift */; }; 2A35A6BA2BBD9B9100CCE4F4 /* WidgetSourceSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35A6B92BBD9B9100CCE4F4 /* WidgetSourceSearchView.swift */; }; 2A35A6BC2BBD9C4D00CCE4F4 /* WidgetChangeSourceSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35A6BB2BBD9C4D00CCE4F4 /* WidgetChangeSourceSearchView.swift */; }; + 2A35A6BE2BBDA4C000CCE4F4 /* LinToObjectSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35A6BD2BBDA4C000CCE4F4 /* LinToObjectSearchView.swift */; }; + 2A35A6C02BBDA5E700CCE4F4 /* LinkToObjectSearchModuleData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35A6BF2BBDA5E700CCE4F4 /* LinkToObjectSearchModuleData.swift */; }; 2A35FF8E2AAF202E00D6006D /* CodeLanguageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35FF8D2AAF202E00D6006D /* CodeLanguageListView.swift */; }; 2A35FF902AAF203C00D6006D /* CodeLanguageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35FF8F2AAF203C00D6006D /* CodeLanguageListViewModel.swift */; }; 2A35FF922AAF20FD00D6006D /* CodeLanguageRowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A35FF912AAF20FD00D6006D /* CodeLanguageRowModel.swift */; }; @@ -787,8 +789,6 @@ 2ADA5EEA28A292D000CD82A4 /* FeatureFlagViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADA5EE928A292D000CD82A4 /* FeatureFlagViewModel.swift */; }; 2ADA60EB2A681A7E0044164D /* IconViewUIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADA60EA2A681A7E0044164D /* IconViewUIKit.swift */; }; 2ADD14EF2AE2B9A50060BC33 /* HomeCreateObjectTip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD14EE2AE2B9A50060BC33 /* HomeCreateObjectTip.swift */; }; - 2ADD1EAF28FD795E00F41DE1 /* LinkToObjectCoordinatorAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD1EAD28FD795E00F41DE1 /* LinkToObjectCoordinatorAssembly.swift */; }; - 2ADD1EB028FD795E00F41DE1 /* LinkToObjecttCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD1EAE28FD795E00F41DE1 /* LinkToObjecttCoordinator.swift */; }; 2ADD556E2987CDDE009AFCB1 /* LinkWidgetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD556D2987CDDE009AFCB1 /* LinkWidgetViewModel.swift */; }; 2ADD55742987CE65009AFCB1 /* LinkWidgetModuleAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD55732987CE65009AFCB1 /* LinkWidgetModuleAssembly.swift */; }; 2ADD66732A6ECA0100266F57 /* CoreGraphics+Hash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD66722A6ECA0100266F57 /* CoreGraphics+Hash.swift */; }; @@ -796,7 +796,6 @@ 2ADF008F2ACD5DAC000D01F8 /* StatusBarStyleModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADF008E2ACD5DAC000D01F8 /* StatusBarStyleModifier.swift */; }; 2ADF00912ACD66D4000D01F8 /* NavigationGestureModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADF00902ACD66D4000D01F8 /* NavigationGestureModifier.swift */; }; 2ADF00932ACF0040000D01F8 /* HomePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADF00922ACF0040000D01F8 /* HomePath.swift */; }; - 2ADF00952AD00B04000D01F8 /* LinkToObjectCoordinatorOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADF00942AD00B04000D01F8 /* LinkToObjectCoordinatorOutput.swift */; }; 2ADF94D429CDAFB000F6FFCC /* EnvironmentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADF94D329CDAFB000F6FFCC /* EnvironmentConfiguration.swift */; }; 2ADFA9DC2949C61D00F64688 /* UIKitModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADFA9DB2949C61D00F64688 /* UIKitModule.swift */; }; 2AE10778296C258400BAB22A /* View+LegacyAdopt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AE10777296C258400BAB22A /* View+LegacyAdopt.swift */; }; @@ -2193,6 +2192,8 @@ 2A35A6B32BBD845B00CCE4F4 /* WidgetTypeChangeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetTypeChangeView.swift; sourceTree = ""; }; 2A35A6B92BBD9B9100CCE4F4 /* WidgetSourceSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetSourceSearchView.swift; sourceTree = ""; }; 2A35A6BB2BBD9C4D00CCE4F4 /* WidgetChangeSourceSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetChangeSourceSearchView.swift; sourceTree = ""; }; + 2A35A6BD2BBDA4C000CCE4F4 /* LinToObjectSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinToObjectSearchView.swift; sourceTree = ""; }; + 2A35A6BF2BBDA5E700CCE4F4 /* LinkToObjectSearchModuleData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkToObjectSearchModuleData.swift; sourceTree = ""; }; 2A35FF8D2AAF202E00D6006D /* CodeLanguageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeLanguageListView.swift; sourceTree = ""; }; 2A35FF8F2AAF203C00D6006D /* CodeLanguageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeLanguageListViewModel.swift; sourceTree = ""; }; 2A35FF912AAF20FD00D6006D /* CodeLanguageRowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeLanguageRowModel.swift; sourceTree = ""; }; @@ -2580,8 +2581,6 @@ 2ADA5EE928A292D000CD82A4 /* FeatureFlagViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlagViewModel.swift; sourceTree = ""; }; 2ADA60EA2A681A7E0044164D /* IconViewUIKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconViewUIKit.swift; sourceTree = ""; }; 2ADD14EE2AE2B9A50060BC33 /* HomeCreateObjectTip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCreateObjectTip.swift; sourceTree = ""; }; - 2ADD1EAD28FD795E00F41DE1 /* LinkToObjectCoordinatorAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkToObjectCoordinatorAssembly.swift; sourceTree = ""; }; - 2ADD1EAE28FD795E00F41DE1 /* LinkToObjecttCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkToObjecttCoordinator.swift; sourceTree = ""; }; 2ADD556D2987CDDE009AFCB1 /* LinkWidgetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkWidgetViewModel.swift; sourceTree = ""; }; 2ADD55732987CE65009AFCB1 /* LinkWidgetModuleAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkWidgetModuleAssembly.swift; sourceTree = ""; }; 2ADD66722A6ECA0100266F57 /* CoreGraphics+Hash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreGraphics+Hash.swift"; sourceTree = ""; }; @@ -2589,7 +2588,6 @@ 2ADF008E2ACD5DAC000D01F8 /* StatusBarStyleModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarStyleModifier.swift; sourceTree = ""; }; 2ADF00902ACD66D4000D01F8 /* NavigationGestureModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationGestureModifier.swift; sourceTree = ""; }; 2ADF00922ACF0040000D01F8 /* HomePath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePath.swift; sourceTree = ""; }; - 2ADF00942AD00B04000D01F8 /* LinkToObjectCoordinatorOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkToObjectCoordinatorOutput.swift; sourceTree = ""; }; 2ADF94D329CDAFB000F6FFCC /* EnvironmentConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnvironmentConfiguration.swift; sourceTree = ""; }; 2ADFA9DB2949C61D00F64688 /* UIKitModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitModule.swift; sourceTree = ""; }; 2AE10777296C258400BAB22A /* View+LegacyAdopt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+LegacyAdopt.swift"; sourceTree = ""; }; @@ -3779,7 +3777,6 @@ C91AFEEB270B4C9C005F9386 /* Debug */, 1289C50E2810278F005085E2 /* FileDownloading flow */, 0331BBD822E5D8AB002AD179 /* Settings */, - 2AFE04B128F9434C008647E0 /* LinkToObjectFlow */, 2A2C330728928BF7008BC326 /* Openers */, 2A2C330128928633008BC326 /* RelationValueFlow */, 3D2F00272B67D7EA009F3AA5 /* ObjectTypeSearch */, @@ -5643,6 +5640,30 @@ path = WidgetSourceSearch; sourceTree = ""; }; + 2A35A6C12BBDA67F00CCE4F4 /* LinkToObject */ = { + isa = PBXGroup; + children = ( + 2A35A6BD2BBDA4C000CCE4F4 /* LinToObjectSearchView.swift */, + 2A35A6BF2BBDA5E700CCE4F4 /* LinkToObjectSearchModuleData.swift */, + 538AE50E272C57300071DB0D /* LinkToObjectSearchViewModel.swift */, + ); + path = LinkToObject; + sourceTree = ""; + }; + 2A35A6C22BBDA68700CCE4F4 /* Other */ = { + isa = PBXGroup; + children = ( + 2A03FD592A7A620800CB7191 /* SearchModuleModel.swift */, + 867B2A972A9CCE050040381E /* SearchInteractors */, + 3D00F1D3278D7CCF00863D7C /* Model */, + 538F172A272C2F1E009528E7 /* SearchView */, + 538F172C272C2F74009528E7 /* ObjectSearchViewModel.swift */, + 2A7DCDE3292E7D5A001919B4 /* SearchModuleAssembly.swift */, + 2A7DCDE7292E8260001919B4 /* SearchModuleAssemblyProtocol.swift */, + ); + path = Other; + sourceTree = ""; + }; 2A376F582B85F2F700CF444A /* Subviews */ = { isa = PBXGroup; children = ( @@ -7121,16 +7142,6 @@ path = GlobalEnv; sourceTree = ""; }; - 2AFE04B128F9434C008647E0 /* LinkToObjectFlow */ = { - isa = PBXGroup; - children = ( - 2ADD1EAE28FD795E00F41DE1 /* LinkToObjecttCoordinator.swift */, - 2ADD1EAD28FD795E00F41DE1 /* LinkToObjectCoordinatorAssembly.swift */, - 2ADF00942AD00B04000D01F8 /* LinkToObjectCoordinatorOutput.swift */, - ); - path = LinkToObjectFlow; - sourceTree = ""; - }; 2AFEED192A73B7F700D7A45B /* Models */ = { isa = PBXGroup; children = ( @@ -8650,14 +8661,8 @@ 3D5A41762704541900F1F6A1 /* Search */ = { isa = PBXGroup; children = ( - 2A03FD592A7A620800CB7191 /* SearchModuleModel.swift */, - 867B2A972A9CCE050040381E /* SearchInteractors */, - 3D00F1D3278D7CCF00863D7C /* Model */, - 538F172A272C2F1E009528E7 /* SearchView */, - 538F172C272C2F74009528E7 /* ObjectSearchViewModel.swift */, - 538AE50E272C57300071DB0D /* LinkToObjectSearchViewModel.swift */, - 2A7DCDE3292E7D5A001919B4 /* SearchModuleAssembly.swift */, - 2A7DCDE7292E8260001919B4 /* SearchModuleAssemblyProtocol.swift */, + 2A35A6C22BBDA68700CCE4F4 /* Other */, + 2A35A6C12BBDA67F00CCE4F4 /* LinkToObject */, ); path = Search; sourceTree = ""; @@ -11645,6 +11650,7 @@ 2E31C9622B7281CD006DB3E2 /* RelationListSelectionView.swift in Sources */, 2A00A74229D33B25007BE598 /* EdgeInsets+Helpers.swift in Sources */, 2A65E9B22AE1290300D40657 /* InitialCoordinatorView.swift in Sources */, + 2A35A6C02BBDA5E700CCE4F4 /* LinkToObjectSearchModuleData.swift in Sources */, 2A35A6AE2BBD809C00CCE4F4 /* WidgetTypeCreateObjectView.swift in Sources */, 3DE6E3C026542151008FB0AF /* UIVIewController+Child.swift in Sources */, 1270CE9326DA84A600B2D443 /* GradientImageBuilder.swift in Sources */, @@ -11945,7 +11951,6 @@ 2E8E8D162A262D2E009BC3B0 /* CreatingSoulView.swift in Sources */, 3D24913427BD271900821595 /* LocalEvent.swift in Sources */, 127240D72846249600C6F8E2 /* NewSearchViewState.swift in Sources */, - 2ADD1EAF28FD795E00F41DE1 /* LinkToObjectCoordinatorAssembly.swift in Sources */, 2E6527632B5EBD9300F27126 /* SelectRelationListView.swift in Sources */, 2E9B40602A1F807A00A7D74E /* LocalAuthService.swift in Sources */, 12FD9D212767174E00991886 /* RelationCheckbox.swift in Sources */, @@ -12039,7 +12044,6 @@ 2E31C9662B73C8C8006DB3E2 /* ObjectRelationOption.swift in Sources */, 2A9486542950A3E7007A5586 /* HomeWidgetsModuleAssembly.swift in Sources */, 129C54D427FC83C000C390C7 /* SupportedRelationFormat.swift in Sources */, - 2ADF00952AD00B04000D01F8 /* LinkToObjectCoordinatorOutput.swift in Sources */, 2E22F9E32B600F91001EFCF3 /* RelationModuleConfiguration.swift in Sources */, 120F7D86267F9E8000327734 /* URLExtensions.swift in Sources */, 2A771F302AD6F0D8000ED2D4 /* SubscriptionUpdate.swift in Sources */, @@ -12162,7 +12166,6 @@ 127EABA32734FD6E00C731F2 /* CheckboxRelationView.swift in Sources */, 2E56F13A2A0D7E6700031167 /* AuthBackgroundView.swift in Sources */, 53F7443127F4BC7B005C9BB0 /* ObjectPreviewLayoutMenuViewModel.swift in Sources */, - 2ADD1EB028FD795E00F41DE1 /* LinkToObjecttCoordinator.swift in Sources */, 1244793D27DC626B00581174 /* NewInternalSearchViewModelProtocol.swift in Sources */, 2A7BD6E628D85993008B735C /* RelationSubscriptionDataBuilder.swift in Sources */, 2A03FD5D2A7A85DD00CB7191 /* RecentWidgetType.swift in Sources */, @@ -12325,6 +12328,7 @@ EA3D1E4F26CFC0E5001A31D9 /* TextViewAttributeSelectionInteraction.swift in Sources */, 2EAA13FE2AA63918000A712A /* SetViewSettingsImagePreviewRowConfiguration.swift in Sources */, 2E0797BC2A0965FD006F0FD7 /* JoinFlowCoordinatorAssembly.swift in Sources */, + 2A35A6BE2BBDA4C000CCE4F4 /* LinToObjectSearchView.swift in Sources */, 0A74E4FB23A90E8C00B6C406 /* AuthService.swift in Sources */, 3D3A182A2733E946000D0842 /* MarkdownListener.swift in Sources */, 2A6693752A7104EA007747DD /* StaticImageGuideline.swift in Sources */, diff --git a/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDI.swift b/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDI.swift index e741ad9f98..de673a0e20 100644 --- a/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDI.swift +++ b/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDI.swift @@ -42,15 +42,6 @@ final class CoordinatorsDI: CoordinatorsDIProtocol { return TemplatesCoordinatorAssembly(serviceLocator: serviceLocator, coordinatorsDI: self) } - func linkToObject() -> LinkToObjectCoordinatorAssemblyProtocol { - return LinkToObjectCoordinatorAssembly( - serviceLocator: serviceLocator, - modulesDI: modulesDI, - coordinatorsID: self, - uiHelopersDI: uiHelpersDI - ) - } - func objectSettings() -> ObjectSettingsCoordinatorAssemblyProtocol { return ObjectSettingsCoordinatorAssembly(modulesDI: modulesDI, uiHelpersDI: uiHelpersDI, coordinatorsDI: self, serviceLocator: serviceLocator) } diff --git a/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDIProtocol.swift b/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDIProtocol.swift index d3050ef8a6..944b552540 100644 --- a/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDIProtocol.swift +++ b/Anytype/Sources/PresentationLayer/Assemblies/CoordinatorsDIProtocol.swift @@ -5,7 +5,6 @@ protocol CoordinatorsDIProtocol: AnyObject { func relationValue() -> RelationValueCoordinatorAssemblyProtocol func relationsList() -> RelationsListCoordinatorAssemblyProtocol func templates() -> TemplatesCoordinatorAssemblyProtocol - func linkToObject() -> LinkToObjectCoordinatorAssemblyProtocol func objectSettings() -> ObjectSettingsCoordinatorAssemblyProtocol func addNewRelation() -> AddNewRelationCoordinatorAssemblyProtocol func home() -> HomeCoordinatorAssemblyProtocol diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinToObjectSearchView.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinToObjectSearchView.swift new file mode 100644 index 0000000000..89e4dc1915 --- /dev/null +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinToObjectSearchView.swift @@ -0,0 +1,16 @@ +import Foundation +import SwiftUI + +struct LinToObjectSearchView: View { + + let data: LinkToObjectSearchModuleData + let showEditorScreen: (_ data: EditorScreenData) -> Void + + var body: some View { + // TODO: Refactoring module. Migrate from Search View + SearchView( + title: Loc.linkTo, + viewModel: LinkToObjectSearchViewModel(data: data, showEditorScreen: showEditorScreen) + ) + } +} diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchModuleData.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchModuleData.swift new file mode 100644 index 0000000000..58368af573 --- /dev/null +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchModuleData.swift @@ -0,0 +1,18 @@ +import Foundation + +struct LinkToObjectSearchModuleData: Identifiable, Hashable, Equatable { + let spaceId: String + let currentLinkUrl: URL? + let currentLinkString: String? + + @EquatableNoop + var setLinkToObject: (_ blockId: String) -> Void + @EquatableNoop + var setLinkToUrl: (_ url: URL) -> Void + @EquatableNoop + var removeLink: () -> Void + @EquatableNoop + var willShowNextScreen: (() -> Void)? + + var id: Int { hashValue } +} diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift similarity index 68% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObjectSearchViewModel.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift index 6b2d81e097..5af31646de 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift @@ -15,45 +15,65 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { typealias SearchDataType = LinkToObjectSearchData - private let spaceId: String - private let searchService: SearchServiceProtocol - private let pasteboardHelper: PasteboardHelperProtocol - private let currentLink: Either? - + @Injected(\.searchService) + private var searchService: SearchServiceProtocol + @Injected(\.pasteboardHelper) + private var pasteboardHelper: PasteboardHelperProtocol + @Injected(\.defaultObjectCreationService) + private var defaultObjectService: DefaultObjectCreationServiceProtocol + + private let data: LinkToObjectSearchModuleData + private let showEditorScreen: (_ data: EditorScreenData) -> Void + let descriptionTextColor: Color = .Text.primary let shouldShowCallout: Bool = true @Published var searchData: [SearchDataSection] = [] - var onSelect: (SearchDataType) -> () var searchTask: Task<(), Never>? - var placeholder: String { Loc.Editor.LinkToObject.searchPlaceholder } - init( - spaceId: String, - currentLink: Either?, - searchService: SearchServiceProtocol, - pasteboardHelper: PasteboardHelperProtocol, - onSelect: @escaping (SearchDataType) -> () - ) { - self.spaceId = spaceId - self.currentLink = currentLink - self.searchService = searchService - self.pasteboardHelper = pasteboardHelper - self.onSelect = onSelect + init(data: LinkToObjectSearchModuleData, showEditorScreen: @escaping (_ data: EditorScreenData) -> Void) { + self.data = data + self.showEditorScreen = showEditorScreen } func search(text: String) { searchTask?.cancel() searchData.removeAll() - searchTask = Task { @MainActor [weak self, spaceId] in - guard let result = try? await self?.searchService.search(text: text, spaceId: spaceId) else { return } + searchTask = Task { @MainActor [weak self, data] in + guard let result = try? await self?.searchService.search(text: text, spaceId: data.spaceId) else { return } self?.handleSearch(result: result, text: text) } } + func onSelect(searchData: LinkToObjectSearchData) { + switch searchData.searchKind { + case let .object(linkBlockId): + data.setLinkToObject(linkBlockId) + case let .createObject(name): + Task { @MainActor [weak self, data] in + if let linkBlockDetails = try? await self?.defaultObjectService.createDefaultObject(name: name, shouldDeleteEmptyObject: false, spaceId: data.spaceId) { + AnytypeAnalytics.instance().logCreateObject(objectType: linkBlockDetails.analyticsType, route: .mention) + data.setLinkToObject(linkBlockDetails.id) + } + } + case let .web(url): + data.setLinkToUrl(url) + case let .openURL(url): + data.willShowNextScreen?() +// urlOpener.openUrl(url) + case let .openObject(details): + data.willShowNextScreen?() + showEditorScreen(details.editorScreenData()) + case .removeLink: + data.removeLink() + case let .copyLink(url): + UIPasteboard.general.string = url.absoluteString + } + } + func handleSearch(result: [ObjectDetails], text: String) { var objectData = result.compactMap { details in LinkToObjectSearchData(details: details) @@ -94,7 +114,7 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { searchData.append(SearchDataSection(searchData: objectData, sectionName: Loc.objects)) } - func buildExistingLinkSections(currentLink: Either) async throws -> [SearchDataSection] { + private func buildExistingLinkSections(currentLink: Either) async throws -> [SearchDataSection] { let linkedToData: LinkToObjectSearchData? let copyLink: LinkToObjectSearchData? @@ -112,7 +132,7 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { iconImage: .asset(.TextEditor.BlocksOption.copy) ) case let .right(blockId): - let result = try await searchService.search(text: "", spaceId: spaceId) + let result = try await searchService.search(text: "", spaceId: data.spaceId) let object = result.first(where: { $0.id == blockId }) linkedToData = object.map { diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/LinkToObjectSearchData.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/LinkToObjectSearchData.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/LinkToObjectSearchData.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/LinkToObjectSearchData.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/ObjectSearchData.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/ObjectSearchData.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/ObjectSearchData.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/ObjectSearchData.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/SearchViewModelProtocol.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift similarity index 94% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/SearchViewModelProtocol.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift index aa65f99a6c..9fbbf3a97d 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Model/SearchViewModelProtocol.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift @@ -31,7 +31,7 @@ protocol SearchViewModelProtocol: ObservableObject { var searchData: [SearchDataSection] { get } var placeholder: String { get } - var onSelect: (SearchDataType) -> () { get } func search(text: String) + func onSelect(searchData: SearchDataType) } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift similarity index 87% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchViewModel.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift index 19e3c316da..a3d5e23509 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift @@ -7,7 +7,7 @@ final class ObjectSearchViewModel: SearchViewModelProtocol { @Published var searchData: [SearchDataSection] = [] - var onSelect: (ObjectSearchData) -> () + var onSelectClosure: (ObjectSearchData) -> () let placeholder: String = Loc.search @@ -19,7 +19,11 @@ final class ObjectSearchViewModel: SearchViewModelProtocol { init(spaceId: String, searchService: SearchInteractorProtocol, onSelect: @escaping (SearchDataType) -> ()) { self.spaceId = spaceId self.searchService = searchService - self.onSelect = onSelect + self.onSelectClosure = onSelect + } + + func onSelect(searchData: ObjectSearchData) { + onSelectClosure(searchData) } func search(text: String) { diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchInteractors/ObjectLayoutSearch.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchInteractors/ObjectLayoutSearch.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchInteractors/ObjectLayoutSearch.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchInteractors/ObjectLayoutSearch.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchInteractors/WrappedSearchInteractor.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchInteractors/WrappedSearchInteractor.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchInteractors/WrappedSearchInteractor.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchInteractors/WrappedSearchInteractor.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleAssembly.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleAssembly.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleAssembly.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleAssembly.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleAssemblyProtocol.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleAssemblyProtocol.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleAssemblyProtocol.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleAssemblyProtocol.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleModel.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchModuleModel.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchModuleModel.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/Cell/SearchCell.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/Cell/SearchCell.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/Cell/SearchCell.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/Cell/SearchCell.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/SearchBar.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchBar.swift similarity index 100% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/SearchBar.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchBar.swift diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/SearchView.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift similarity index 99% rename from Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/SearchView.swift rename to Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift index eb6f8047a6..0ccf4410be 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/SearchView/SearchView.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift @@ -42,7 +42,7 @@ struct SearchView: View { Button( action: { presentationMode.wrappedValue.dismiss() - viewModel.onSelect(searchData) + viewModel.onSelect(searchData: searchData) } ) { SearchCell(data: searchData) diff --git a/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/BottomSheetsFactory.swift b/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/BottomSheetsFactory.swift index 14f6aee7f4..9074d9bfcd 100644 --- a/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/BottomSheetsFactory.swift +++ b/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/BottomSheetsFactory.swift @@ -101,14 +101,14 @@ final class BottomSheetsFactory { document: BaseDocumentProtocol, blockIds: [String], actionHandler: BlockActionHandlerProtocol, - linkToObjectCoordinator: LinkToObjectCoordinatorProtocol, - viewDidClose: @escaping () -> Void + viewDidClose: @escaping () -> Void, + openLinkToObject: @escaping (LinkToObjectSearchModuleData) -> Void ) { let viewModel = MarkupViewModel( document: document, blockIds: blockIds, actionHandler: actionHandler, - linkToObjectCoordinator: linkToObjectCoordinator + openLinkToObject: openLinkToObject ) let viewController = MarkupsViewController( viewModel: viewModel, diff --git a/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/TextAttributesView/MarkupViewModel.swift b/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/TextAttributesView/MarkupViewModel.swift index 62de0d346c..20fa6bec59 100644 --- a/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/TextAttributesView/MarkupViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/UIKit/BottomSheets/TextAttributesView/MarkupViewModel.swift @@ -12,7 +12,7 @@ final class MarkupViewModel: MarkupViewModelProtocol { private let blockIds: [String] private let actionHandler: BlockActionHandlerProtocol private let document: BaseDocumentProtocol - private let linkToObjectCoordinator: LinkToObjectCoordinatorProtocol + private let openLinkToObject: (LinkToObjectSearchModuleData) -> Void // For read link value private var selectedMarkups: [MarkupType: AttributeState] = [:] @@ -21,12 +21,12 @@ final class MarkupViewModel: MarkupViewModelProtocol { document: BaseDocumentProtocol, blockIds: [String], actionHandler: BlockActionHandlerProtocol, - linkToObjectCoordinator: LinkToObjectCoordinatorProtocol + openLinkToObject: @escaping (LinkToObjectSearchModuleData) -> Void ) { self.document = document self.blockIds = blockIds self.actionHandler = actionHandler - self.linkToObjectCoordinator = linkToObjectCoordinator + self.openLinkToObject = openLinkToObject } // MARK: - MarkupViewModelProtocol @@ -62,9 +62,10 @@ final class MarkupViewModel: MarkupViewModelProtocol { let blokcLink = selectedMarkups.keys.compactMap { $0.blokcLink }.first let currentLink = Either.from(left: urlLink, right: blokcLink) - linkToObjectCoordinator.startFlow( + let data = LinkToObjectSearchModuleData( spaceId: document.spaceId, - currentLink: currentLink, + currentLinkUrl: selectedMarkups.keys.compactMap { $0.urlLink }.first, + currentLinkString: selectedMarkups.keys.compactMap { $0.blokcLink }.first, setLinkToObject: { [weak self, blockIds] blockId in self?.actionHandler.changeMarkup(blockIds: blockIds, markType: .linkToObject(blockId)) }, @@ -85,6 +86,7 @@ final class MarkupViewModel: MarkupViewModelProtocol { self?.view?.dismiss() } ) + openLinkToObject(data) } } diff --git a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift index 8b20b5a216..18fe5df728 100644 --- a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift +++ b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorView.swift @@ -25,6 +25,11 @@ struct EditorPageCoordinatorView: View { .sheet(item: $model.covertPickerData) { ObjectCoverPicker(data: $0) } + .sheet(item: $model.linkToObjectData) { + LinToObjectSearchView(data: $0) { data in + model.showEditorScreen(data: data) + } + } .snackbar(toastBarData: $model.toastBarData) } } diff --git a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift index fee8ff604c..c97c01b1ba 100644 --- a/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Flows/EditorPageFlow/EditorPageCoordinatorViewModel.swift @@ -20,6 +20,7 @@ final class EditorPageCoordinatorViewModel: ObservableObject, EditorPageModuleOu @Published var toastBarData: ToastBarData = .empty @Published var codeLanguageData: CodeLanguageListData? @Published var covertPickerData: ObjectCoverPickerData? + @Published var linkToObjectData: LinkToObjectSearchModuleData? init( data: EditorPageObject, @@ -89,6 +90,12 @@ final class EditorPageCoordinatorViewModel: ObservableObject, EditorPageModuleOu codeLanguageData = CodeLanguageListData(documentId: objectId, blockId: blockId) } + func showLinkToObject(data: LinkToObjectSearchModuleData) { + linkToObjectData = data + } + + // MARK: - Private + private func handleRelationValue(relation: Relation, objectDetails: ObjectDetails) { let analyticsType = AnalyticsEventsRelationType.block if relationValueProcessingService.canOpenRelationInNewModule(relation) { diff --git a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorAssembly.swift b/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorAssembly.swift deleted file mode 100644 index 3c8df861ce..0000000000 --- a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorAssembly.swift +++ /dev/null @@ -1,37 +0,0 @@ -import Foundation -import UIKit - -protocol LinkToObjectCoordinatorAssemblyProtocol: AnyObject { - func make(output: LinkToObjectCoordinatorOutput?) -> LinkToObjectCoordinatorProtocol -} - -final class LinkToObjectCoordinatorAssembly: LinkToObjectCoordinatorAssemblyProtocol { - - private let serviceLocator: ServiceLocator - private let modulesDI: ModulesDIProtocol - private let coordinatorsID: CoordinatorsDIProtocol - private let uiHelopersDI: UIHelpersDIProtocol - - init(serviceLocator: ServiceLocator, modulesDI: ModulesDIProtocol, coordinatorsID: CoordinatorsDIProtocol, uiHelopersDI: UIHelpersDIProtocol) { - self.serviceLocator = serviceLocator - self.modulesDI = modulesDI - self.coordinatorsID = coordinatorsID - self.uiHelopersDI = uiHelopersDI - } - - // MARK: - LinkToObjectCoordinatorAssemblyProtocol - - func make(output: LinkToObjectCoordinatorOutput?) -> LinkToObjectCoordinatorProtocol { - - let coordinator = LinkToObjectCoordinator( - navigationContext: uiHelopersDI.commonNavigationContext(), - defaultObjectService: serviceLocator.defaultObjectCreationService(), - urlOpener: uiHelopersDI.urlOpener(), - searchService: serviceLocator.searchService(), - pasteboardHelper: serviceLocator.pasteboardHelper(), - output: output - ) - - return coordinator - } -} diff --git a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorOutput.swift b/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorOutput.swift deleted file mode 100644 index df8c9a71cd..0000000000 --- a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjectCoordinatorOutput.swift +++ /dev/null @@ -1,5 +0,0 @@ -import Foundation - -protocol LinkToObjectCoordinatorOutput: AnyObject { - func showEditorScreen(data: EditorScreenData) -} diff --git a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjecttCoordinator.swift b/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjecttCoordinator.swift deleted file mode 100644 index e9b2318414..0000000000 --- a/Anytype/Sources/PresentationLayer/LinkToObjectFlow/LinkToObjecttCoordinator.swift +++ /dev/null @@ -1,105 +0,0 @@ -import Foundation -import UIKit -import Services -import AnytypeCore - -@MainActor -protocol LinkToObjectCoordinatorProtocol: AnyObject { - func startFlow( - spaceId: String, - currentLink: Either?, - setLinkToObject: @escaping (_ blockId: String) -> Void, - setLinkToUrl: @escaping (_ url: URL) -> Void, - removeLink: @escaping () -> Void, - willShowNextScreen: (() -> Void)? - ) -} - -@MainActor -final class LinkToObjectCoordinator: LinkToObjectCoordinatorProtocol { - - private let navigationContext: NavigationContextProtocol - private let defaultObjectService: DefaultObjectCreationServiceProtocol - private let urlOpener: URLOpenerProtocol - private let searchService: SearchServiceProtocol - private let pasteboardHelper: PasteboardHelperProtocol - private weak var output: LinkToObjectCoordinatorOutput? - - nonisolated init( - navigationContext: NavigationContextProtocol, - defaultObjectService: DefaultObjectCreationServiceProtocol, - urlOpener: URLOpenerProtocol, - searchService: SearchServiceProtocol, - pasteboardHelper: PasteboardHelperProtocol, - output: LinkToObjectCoordinatorOutput? - ) { - self.navigationContext = navigationContext - self.defaultObjectService = defaultObjectService - self.urlOpener = urlOpener - self.searchService = searchService - self.pasteboardHelper = pasteboardHelper - self.output = output - } - - // MARK: - LinkToObjectCoordinatorProtocol - - func startFlow( - spaceId: String, - currentLink: Either?, - setLinkToObject: @escaping (_ blockId: String) -> Void, - setLinkToUrl: @escaping (_ url: URL) -> Void, - removeLink: @escaping () -> Void, - willShowNextScreen: (() -> Void)? - ) { - - let onLinkSelection: (LinkToObjectSearchViewModel.SearchKind) -> () = { [weak self] searchKind in - switch searchKind { - case let .object(linkBlockId): - setLinkToObject(linkBlockId) - case let .createObject(name): - Task { @MainActor [weak self] in - if let linkBlockDetails = try? await self?.defaultObjectService.createDefaultObject(name: name, shouldDeleteEmptyObject: false, spaceId: spaceId) { - AnytypeAnalytics.instance().logCreateObject(objectType: linkBlockDetails.analyticsType, route: .mention) - setLinkToObject(linkBlockDetails.id) - } - } - case let .web(url): - setLinkToUrl(url) - case let .openURL(url): - willShowNextScreen?() - self?.urlOpener.openUrl(url) - case let .openObject(details): - willShowNextScreen?() - self?.output?.showEditorScreen(data: details.editorScreenData()) - case .removeLink: - removeLink() - case let .copyLink(url): - UIPasteboard.general.string = url.absoluteString - } - } - - showLinkToObject(spaceId: spaceId, currentLink: currentLink, onSelect: onLinkSelection) - } - - - // MARK: - Private - - func showLinkToObject( - spaceId: String, - currentLink: Either?, - onSelect: @escaping (LinkToObjectSearchViewModel.SearchKind) -> () - ) { - let viewModel = LinkToObjectSearchViewModel( - spaceId: spaceId, - currentLink: currentLink, - searchService: searchService, - pasteboardHelper: pasteboardHelper - ) { data in - onSelect(data.searchKind) - } - let linkToView = SearchView(title: Loc.linkTo, viewModel: viewModel) - - navigationContext.presentSwiftUIView(view: linkToView) - } - -} diff --git a/Anytype/Sources/PresentationLayer/Search screen/InternalViewModels/SpaceSearchViewModel/SpaceSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Search screen/InternalViewModels/SpaceSearchViewModel/SpaceSearchViewModel.swift index 429550d611..2456b26695 100644 --- a/Anytype/Sources/PresentationLayer/Search screen/InternalViewModels/SpaceSearchViewModel/SpaceSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Search screen/InternalViewModels/SpaceSearchViewModel/SpaceSearchViewModel.swift @@ -5,7 +5,7 @@ import Combine @MainActor final class SpaceSearchViewModel: SearchViewModelProtocol { @Published var searchData = [SearchDataSection]() - var onSelect: (SpaceView) -> () + var onSelectClosure: (SpaceView) -> () var placeholder: String { Loc.Spaces.Search.title } var lastSearchText: String = "" @@ -18,11 +18,15 @@ final class SpaceSearchViewModel: SearchViewModelProtocol { onSelect: @escaping (SpaceView) -> Void ) { self.participantSpacesStorage = participantSpacesStorage - self.onSelect = onSelect + self.onSelectClosure = onSelect setupSubscription() } + func onSelect(searchData: SpaceView) { + onSelectClosure(searchData) + } + private func setupSubscription() { participantSpacesStorage.activeParticipantSpacesPublisher.sink { [weak self] participantSpaces in self?.spaces = participantSpaces.filter(\.canEdit).map(\.spaceView) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift index f715242524..e7cf7b4e46 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift @@ -82,7 +82,6 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { templatesCoordinator: coordinatorsDI.templates().make(viewController: controller), setObjectCreationSettingsCoordinator: coordinatorsDI.setObjectCreationSettings().make(with: navigationContext), urlOpener: uiHelpersDI.urlOpener(), - linkToObjectCoordinatorAssembly: coordinatorsDI.linkToObject(), objectIconPickerModuleAssembly: modulesDI.objectIconPicker(), objectSettingCoordinator: coordinatorsDI.objectSettings().make(), searchModuleAssembly: modulesDI.search(), @@ -220,7 +219,6 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { mainEditorSelectionManager: blocksStateManager, responderScrollViewHelper: responderScrollViewHelper, defaultObjectService: serviceLocator.defaultObjectCreationService(), - linkToObjectCoordinator: coordinatorsDI.linkToObject().make(output: router), typesService: serviceLocator.typesService(), accessoryStateManager: accessoryState.0, tableService: serviceLocator.blockTableService() @@ -252,7 +250,6 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { accessoryStateManager: accessoryState.0, cursorManager: cursorManager, keyboardActionHandler: keyboardHandler, - linkToObjectCoordinator: coordinatorsDI.linkToObject().make(output: router), markupChanger: BlockMarkupChanger(), slashMenuActionHandler: slashMenuActionHandler, editorPageBlocksStateManager: blocksStateManager, diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift index 009505d3d0..8bdc69203e 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleOutput.swift @@ -7,6 +7,7 @@ protocol EditorPageModuleOutput: AnyObject, ObjectHeaderModuleOutput { func closeEditor() func onSelectCodeLanguage(objectId: String, blockId: String) func showRelationValueEditingView(document: BaseDocumentProtocol, relation: Relation) + func showLinkToObject(data: LinkToObjectSearchModuleData) // TODO: Refactoring templates. Delete it func setModuleInput(input: EditorPageModuleInput, objectId: String) // TODO: Migrate EditorRouter to EditorPageCoordinator and make output as MainActor diff --git a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/SimpleTable/SimpleTableDependenciesBuilder.swift b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/SimpleTable/SimpleTableDependenciesBuilder.swift index 748115984a..3f6fe58a14 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/SimpleTable/SimpleTableDependenciesBuilder.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/SimpleTable/SimpleTableDependenciesBuilder.swift @@ -20,7 +20,6 @@ final class SimpleTableDependenciesBuilder { private let tableService: BlockTableServiceProtocol private let responderScrollViewHelper: ResponderScrollViewHelper private let defaultObjectService: DefaultObjectCreationServiceProtocol - private let linkToObjectCoordinator: LinkToObjectCoordinatorProtocol private let typesService: TypesServiceProtocol private let accessoryStateManager: AccessoryViewStateManager @@ -37,7 +36,6 @@ final class SimpleTableDependenciesBuilder { mainEditorSelectionManager: SimpleTableSelectionHandler?, responderScrollViewHelper: ResponderScrollViewHelper, defaultObjectService: DefaultObjectCreationServiceProtocol, - linkToObjectCoordinator: LinkToObjectCoordinatorProtocol, typesService: TypesServiceProtocol, accessoryStateManager: AccessoryViewStateManager, tableService: BlockTableServiceProtocol @@ -51,7 +49,6 @@ final class SimpleTableDependenciesBuilder { self.mainEditorSelectionManager = mainEditorSelectionManager self.responderScrollViewHelper = responderScrollViewHelper self.defaultObjectService = defaultObjectService - self.linkToObjectCoordinator = linkToObjectCoordinator self.typesService = typesService self.accessoryStateManager = accessoryStateManager self.tableService = tableService diff --git a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Base/TextBlockActionHandler.swift b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Base/TextBlockActionHandler.swift index 9bb8087f88..5dc25a8a1a 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Base/TextBlockActionHandler.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/Text/Base/TextBlockActionHandler.swift @@ -23,9 +23,9 @@ final class TextBlockActionHandler: TextBlockActionHandlerProtocol { private let showWaitingView: (String) -> Void private let hideWaitingView: () -> Void + private let openLinkToObject: @MainActor (LinkToObjectSearchModuleData) -> Void private let showURLBookmarkPopup: (TextBlockURLInputParameters) -> Void private let actionHandler: BlockActionHandlerProtocol - private let linkToObjectCoordinator: LinkToObjectCoordinatorProtocol private let markupChanger: BlockMarkupChangerProtocol // Fix retain cycle for long paste action @@ -65,9 +65,9 @@ final class TextBlockActionHandler: TextBlockActionHandlerProtocol { cursorManager: EditorCursorManager, accessoryViewStateManager: AccessoryViewStateManager, keyboardHandler: KeyboardActionHandlerProtocol, - linkToObjectCoordinator: LinkToObjectCoordinatorProtocol, markupChanger: BlockMarkupChangerProtocol, - slashMenuActionHandler: SlashMenuActionHandler + slashMenuActionHandler: SlashMenuActionHandler, + openLinkToObject: @MainActor @escaping (LinkToObjectSearchModuleData) -> Void ) { self.document = document self.info = info @@ -87,9 +87,9 @@ final class TextBlockActionHandler: TextBlockActionHandlerProtocol { self.cursorManager = cursorManager self.accessoryViewStateManager = accessoryViewStateManager self.keyboardHandler = keyboardHandler - self.linkToObjectCoordinator = linkToObjectCoordinator self.markupChanger = markupChanger self.slashMenuActionHandler = slashMenuActionHandler + self.openLinkToObject = openLinkToObject } func textBlockActions() -> TextBlockContentConfiguration.Actions { @@ -429,9 +429,10 @@ extension TextBlockActionHandler: AccessoryViewOutput { let objectIdLink = text.linkToObjectState(range: range) let eitherLink: Either? = urlLink.map { .left($0) } ?? objectIdLink.map { .right($0) } ?? nil - linkToObjectCoordinator.startFlow( + let data = LinkToObjectSearchModuleData( spaceId: "", - currentLink: eitherLink, + currentLinkUrl: text.linkState(range: range), + currentLinkString: text.linkToObjectState(range: range), setLinkToObject: { [weak self] linkBlockId in guard let self = self else { return } AnytypeAnalytics.instance().logChangeTextStyle(MarkupType.linkToObject(linkBlockId)) @@ -464,6 +465,7 @@ extension TextBlockActionHandler: AccessoryViewOutput { }, willShowNextScreen: nil ) + openLinkToObject(data) } func setNewText(attributedString: NSAttributedString) { diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift index 21cd458e2f..754014682c 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Models/BlockViewModelBuilder.swift @@ -22,7 +22,6 @@ final class BlockViewModelBuilder { private let cursorManager: EditorCursorManager private let keyboardActionHandler: KeyboardActionHandlerProtocol private let editorPageBlocksStateManager: EditorPageBlocksStateManager - private let linkToObjectCoordinator: LinkToObjectCoordinatorProtocol private let markupChanger: BlockMarkupChangerProtocol private let slashMenuActionHandler: SlashMenuActionHandler private weak var output: EditorPageModuleOutput? @@ -45,7 +44,6 @@ final class BlockViewModelBuilder { accessoryStateManager: AccessoryViewStateManager, cursorManager: EditorCursorManager, keyboardActionHandler: KeyboardActionHandlerProtocol, - linkToObjectCoordinator: LinkToObjectCoordinatorProtocol, markupChanger: BlockMarkupChangerProtocol, slashMenuActionHandler: SlashMenuActionHandler, editorPageBlocksStateManager: EditorPageBlocksStateManager, @@ -68,7 +66,6 @@ final class BlockViewModelBuilder { self.accessoryStateManager = accessoryStateManager self.cursorManager = cursorManager self.keyboardActionHandler = keyboardActionHandler - self.linkToObjectCoordinator = linkToObjectCoordinator self.markupChanger = markupChanger self.slashMenuActionHandler = slashMenuActionHandler self.editorPageBlocksStateManager = editorPageBlocksStateManager @@ -175,9 +172,11 @@ final class BlockViewModelBuilder { cursorManager: cursorManager, accessoryViewStateManager: accessoryStateManager, keyboardHandler: keyboardActionHandler, - linkToObjectCoordinator: linkToObjectCoordinator, markupChanger: markupChanger, - slashMenuActionHandler: slashMenuActionHandler + slashMenuActionHandler: slashMenuActionHandler, + openLinkToObject: { [weak self] data in + self?.output?.showLinkToObject(data: data) + } ) let viewModel = TextBlockViewModel( diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift index 2c52838153..27fe221150 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Routing/Editor/EditorRouter.swift @@ -5,7 +5,7 @@ import SwiftUI import FloatingPanel import AnytypeCore -final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordinatorOutput, LinkToObjectCoordinatorOutput { +final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordinatorOutput { private weak var viewController: UIViewController? private let navigationContext: NavigationContextProtocol private let fileCoordinator: FileDownloadingCoordinator @@ -14,7 +14,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina private let templatesCoordinator: TemplatesCoordinatorProtocol private let setObjectCreationSettingsCoordinator: SetObjectCreationSettingsCoordinatorProtocol private let urlOpener: URLOpenerProtocol - private let linkToObjectCoordinatorAssembly: LinkToObjectCoordinatorAssemblyProtocol private let objectIconPickerModuleAssembly: ObjectIconPickerModuleAssemblyProtocol private let objectSettingCoordinator: ObjectSettingsCoordinatorProtocol private let searchModuleAssembly: SearchModuleAssemblyProtocol @@ -33,7 +32,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina templatesCoordinator: TemplatesCoordinatorProtocol, setObjectCreationSettingsCoordinator: SetObjectCreationSettingsCoordinatorProtocol, urlOpener: URLOpenerProtocol, - linkToObjectCoordinatorAssembly: LinkToObjectCoordinatorAssemblyProtocol, objectIconPickerModuleAssembly: ObjectIconPickerModuleAssemblyProtocol, objectSettingCoordinator: ObjectSettingsCoordinatorProtocol, searchModuleAssembly: SearchModuleAssemblyProtocol, @@ -52,7 +50,6 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina self.templatesCoordinator = templatesCoordinator self.setObjectCreationSettingsCoordinator = setObjectCreationSettingsCoordinator self.urlOpener = urlOpener - self.linkToObjectCoordinatorAssembly = linkToObjectCoordinatorAssembly self.objectIconPickerModuleAssembly = objectIconPickerModuleAssembly self.objectSettingCoordinator = objectSettingCoordinator self.searchModuleAssembly = searchModuleAssembly @@ -183,8 +180,10 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina document: self.document, blockIds: infos.map { $0.id }, actionHandler: controller.viewModel.actionHandler, - linkToObjectCoordinator: self.linkToObjectCoordinatorAssembly.make(output: self), - viewDidClose: viewDidClose + viewDidClose: viewDidClose, + openLinkToObject: { [weak self] data in + self?.output?.showLinkToObject(data: data) + } ) }, onDismiss: onDismiss @@ -435,7 +434,9 @@ final class EditorRouter: NSObject, EditorRouterProtocol, ObjectSettingsCoordina document: document, blockIds: selectedBlockIds, actionHandler: controller.viewModel.actionHandler, - linkToObjectCoordinator: linkToObjectCoordinatorAssembly.make(output: self) + openLinkToObject: { [weak self] data in + self?.output?.showLinkToObject(data: data) + } ) let viewController = MarkupsViewController( viewModel: viewModel, From 01992da12a53c55a940ded390997eff9c48356d9 Mon Sep 17 00:00:00 2001 From: Mikhail Golovko Date: Wed, 3 Apr 2024 19:14:34 +0300 Subject: [PATCH 2/3] IOS-2591 Fixes --- .../LinkToObjectSearchViewModel.swift | 46 +++++++++++-------- .../Other/Model/SearchViewModelProtocol.swift | 2 +- .../Search/Other/ObjectSearchViewModel.swift | 31 ++++++------- .../Search/Other/SearchView/SearchView.swift | 9 +--- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift index 5af31646de..9112c41d2d 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift @@ -30,7 +30,6 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { @Published var searchData: [SearchDataSection] = [] - var searchTask: Task<(), Never>? var placeholder: String { Loc.Editor.LinkToObject.searchPlaceholder } init(data: LinkToObjectSearchModuleData, showEditorScreen: @escaping (_ data: EditorScreenData) -> Void) { @@ -38,13 +37,17 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { self.showEditorScreen = showEditorScreen } - func search(text: String) { - searchTask?.cancel() - searchData.removeAll() - - searchTask = Task { @MainActor [weak self, data] in - guard let result = try? await self?.searchService.search(text: text, spaceId: data.spaceId) else { return } - self?.handleSearch(result: result, text: text) + func search(text: String) async throws { + do { + if data.currentLinkUrl.isNotNil || data.currentLinkString.isNotNil, text.isEmpty { + let sections = try await buildExistingLinkSections() + searchData = sections + } else { + let result = try await searchService.search(text: text, spaceId: data.spaceId) + searchData = handleSearch(result: result, text: text) + } + } catch { + searchData.removeAll() } } @@ -74,7 +77,9 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { } } - func handleSearch(result: [ObjectDetails], text: String) { + func handleSearch(result: [ObjectDetails], text: String) -> [SearchDataSection] { + var newSearchData: [SearchDataSection] = [] + var objectData = result.compactMap { details in LinkToObjectSearchData(details: details) } @@ -87,7 +92,7 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { iconImage: .asset(.webPage)) let webSection = SearchDataSection(searchData: [webSearchData], sectionName: Loc.webPages) - searchData.append(webSection) + newSearchData.append(webSection) } let title = Loc.createObject + " " + "\"" + text + "\"" @@ -107,34 +112,35 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { iconImage: .asset(.webPage)) let webSection = SearchDataSection(searchData: [webSearchData], sectionName: Loc.webPages) - searchData.append(webSection) + newSearchData.append(webSection) } } - searchData.append(SearchDataSection(searchData: objectData, sectionName: Loc.objects)) + newSearchData.append(SearchDataSection(searchData: objectData, sectionName: Loc.objects)) + + return newSearchData } - private func buildExistingLinkSections(currentLink: Either) async throws -> [SearchDataSection] { - let linkedToData: LinkToObjectSearchData? - let copyLink: LinkToObjectSearchData? + private func buildExistingLinkSections() async throws -> [SearchDataSection] { + var linkedToData: LinkToObjectSearchData? = nil + var copyLink: LinkToObjectSearchData? = nil - switch currentLink { - case let .left(url): + if let url = data.currentLinkUrl { linkedToData = LinkToObjectSearchData( searchKind: .openURL(url), searchTitle: url.absoluteString, iconImage: .asset(.webPage) ) - + copyLink = LinkToObjectSearchData( searchKind: .copyLink(url), searchTitle: Loc.Editor.LinkToObject.copyLink, iconImage: .asset(.TextEditor.BlocksOption.copy) ) - case let .right(blockId): + } else if let blockId = data.currentLinkString { let result = try await searchService.search(text: "", spaceId: data.spaceId) let object = result.first(where: { $0.id == blockId }) - + linkedToData = object.map { LinkToObjectSearchData(details: $0, searchKind: .openObject($0)) } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift index 9fbbf3a97d..61bce6787a 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift @@ -32,6 +32,6 @@ protocol SearchViewModelProtocol: ObservableObject { var searchData: [SearchDataSection] { get } var placeholder: String { get } - func search(text: String) + func search(text: String) async throws func onSelect(searchData: SearchDataType) } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift index a3d5e23509..87cd4cd38a 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift @@ -14,8 +14,6 @@ final class ObjectSearchViewModel: SearchViewModelProtocol { private let spaceId: String private let searchService: SearchInteractorProtocol - private var searchTask: AnyCancellable? - init(spaceId: String, searchService: SearchInteractorProtocol, onSelect: @escaping (SearchDataType) -> ()) { self.spaceId = spaceId self.searchService = searchService @@ -26,23 +24,20 @@ final class ObjectSearchViewModel: SearchViewModelProtocol { onSelectClosure(searchData) } - func search(text: String) { - searchTask?.cancel() - searchTask = Task { @MainActor in - do { - let result = try await searchService.search(text: text, spaceId: spaceId) - let objectsSearchData = result.compactMap { ObjectSearchData(details: $0) } - - guard objectsSearchData.isNotEmpty else { - searchData = [] - return - } - - searchData = [SearchDataSection(searchData: objectsSearchData, sectionName: "")] - - } catch { + func search(text: String) async throws { + do { + let result = try await searchService.search(text: text, spaceId: spaceId) + let objectsSearchData = result.compactMap { ObjectSearchData(details: $0) } + + guard objectsSearchData.isNotEmpty else { searchData = [] + return } - }.cancellable() + + searchData = [SearchDataSection(searchData: objectsSearchData, sectionName: "")] + + } catch { + searchData = [] + } } } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift index 0ccf4410be..8fd3fb8e0d 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/SearchView/SearchView.swift @@ -17,10 +17,9 @@ struct SearchView: View { content } .background(Color.Background.secondary) - .onChange(of: searchText) { - search(text: $0) + .task(id: searchText) { + try? await viewModel.search(text: searchText) } - .onAppear { search(text: searchText) } } private var content: some View { @@ -84,10 +83,6 @@ struct SearchView: View { Spacer() }.padding(.horizontal) } - - private func search(text: String) { - viewModel.search(text: text) - } } struct HomeSearchView_Previews: PreviewProvider { From 0ce18c0a36cf283011958645768e7aa5d7974eae Mon Sep 17 00:00:00 2001 From: Mikhail Golovko Date: Thu, 4 Apr 2024 10:59:15 +0300 Subject: [PATCH 3/3] IOS-2591 Remove throws --- .../Search/LinkToObject/LinkToObjectSearchViewModel.swift | 2 +- .../SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift | 2 +- .../Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift index 9112c41d2d..cc93903a54 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchViewModel.swift @@ -37,7 +37,7 @@ final class LinkToObjectSearchViewModel: SearchViewModelProtocol { self.showEditorScreen = showEditorScreen } - func search(text: String) async throws { + func search(text: String) async { do { if data.currentLinkUrl.isNotNil || data.currentLinkString.isNotNil, text.isEmpty { let sections = try await buildExistingLinkSections() diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift index 61bce6787a..b50e99e665 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/Model/SearchViewModelProtocol.swift @@ -32,6 +32,6 @@ protocol SearchViewModelProtocol: ObservableObject { var searchData: [SearchDataSection] { get } var placeholder: String { get } - func search(text: String) async throws + func search(text: String) async func onSelect(searchData: SearchDataType) } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift index 87cd4cd38a..896886a33b 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/Other/ObjectSearchViewModel.swift @@ -24,7 +24,7 @@ final class ObjectSearchViewModel: SearchViewModelProtocol { onSelectClosure(searchData) } - func search(text: String) async throws { + func search(text: String) async { do { let result = try await searchService.search(text: text, spaceId: spaceId) let objectsSearchData = result.compactMap { ObjectSearchData(details: $0) }