Skip to content

Commit

Permalink
IOS-2655 Migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
mgolovko committed Apr 11, 2024
1 parent 599a636 commit 5f4707c
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 115 deletions.
8 changes: 4 additions & 4 deletions Anytype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
2A2987362ACBFD2B009E8787 /* EditorSetModuleAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2987352ACBFD2B009E8787 /* EditorSetModuleAssembly.swift */; };
2A2987382ACBFD3C009E8787 /* EditorSetModuleOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2987372ACBFD3C009E8787 /* EditorSetModuleOutput.swift */; };
2A29873C2ACC087B009E8787 /* PageNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A29873B2ACC087B009E8787 /* PageNavigation.swift */; };
2A298E342BC7F1BE00F1194C /* UndoRedoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A298E332BC7F1BE00F1194C /* UndoRedoViewController.swift */; };
2A29FD2F2A701BDD007A8549 /* ActiveWorkspaceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A29FD2E2A701BDD007A8549 /* ActiveWorkspaceStorage.swift */; };
2A2A347529229D2B0004BD8B /* NavigationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2A347429229D2B0004BD8B /* NavigationContext.swift */; };
2A2B331A2A7AA525004BD906 /* WidgetTypeCreateData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2B33192A7AA525004BD906 /* WidgetTypeCreateData.swift */; };
Expand Down Expand Up @@ -863,7 +864,6 @@
2AFF7AC4299CDA6900B7746B /* BinSubscriptionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFF7AC3299CDA6900B7746B /* BinSubscriptionService.swift */; };
2AFF7AC8299CFB9A00B7746B /* AnytypeRelativeDateTimeFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFF7AC7299CFB9A00B7746B /* AnytypeRelativeDateTimeFormatter.swift */; };
2AFF7ACC299D24C300B7746B /* DocumentViewModelSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFF7ACB299D24C300B7746B /* DocumentViewModelSetter.swift */; };
2AFFFB822924DEE700A487E1 /* UndoRedoAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFFFB812924DEE700A487E1 /* UndoRedoAssembly.swift */; };
2AFFFB842924DFC600A487E1 /* UIHelpersDI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFFFB832924DFC600A487E1 /* UIHelpersDI.swift */; };
2AFFFB862924EE1000A487E1 /* ViewControllerProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFFFB852924EE1000A487E1 /* ViewControllerProvider.swift */; };
2AFFFB8A2926670E00A487E1 /* ObjectLayoutPickerModuleAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFFFB892926670E00A487E1 /* ObjectLayoutPickerModuleAssembly.swift */; };
Expand Down Expand Up @@ -2118,6 +2118,7 @@
2A2987352ACBFD2B009E8787 /* EditorSetModuleAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorSetModuleAssembly.swift; sourceTree = "<group>"; };
2A2987372ACBFD3C009E8787 /* EditorSetModuleOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorSetModuleOutput.swift; sourceTree = "<group>"; };
2A29873B2ACC087B009E8787 /* PageNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageNavigation.swift; sourceTree = "<group>"; };
2A298E332BC7F1BE00F1194C /* UndoRedoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoRedoViewController.swift; sourceTree = "<group>"; };
2A29FD2E2A701BDD007A8549 /* ActiveWorkspaceStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveWorkspaceStorage.swift; sourceTree = "<group>"; };
2A2A347429229D2B0004BD8B /* NavigationContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationContext.swift; sourceTree = "<group>"; };
2A2B33192A7AA525004BD906 /* WidgetTypeCreateData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetTypeCreateData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2633,7 +2634,6 @@
2AFF7AC3299CDA6900B7746B /* BinSubscriptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinSubscriptionService.swift; sourceTree = "<group>"; };
2AFF7AC7299CFB9A00B7746B /* AnytypeRelativeDateTimeFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnytypeRelativeDateTimeFormatter.swift; sourceTree = "<group>"; };
2AFF7ACB299D24C300B7746B /* DocumentViewModelSetter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentViewModelSetter.swift; sourceTree = "<group>"; };
2AFFFB812924DEE700A487E1 /* UndoRedoAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoRedoAssembly.swift; sourceTree = "<group>"; };
2AFFFB832924DFC600A487E1 /* UIHelpersDI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIHelpersDI.swift; sourceTree = "<group>"; };
2AFFFB852924EE1000A487E1 /* ViewControllerProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerProvider.swift; sourceTree = "<group>"; };
2AFFFB892926670E00A487E1 /* ObjectLayoutPickerModuleAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectLayoutPickerModuleAssembly.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9817,7 +9817,7 @@
children = (
C91989EC2811673600CC6BEB /* UndoRedoView.swift */,
C91FAF5C2812865B0055BC4A /* UndoRedoViewModel.swift */,
2AFFFB812924DEE700A487E1 /* UndoRedoAssembly.swift */,
2A298E332BC7F1BE00F1194C /* UndoRedoViewController.swift */,
);
path = UndoRedo;
sourceTree = "<group>";
Expand Down Expand Up @@ -11991,7 +11991,6 @@
2A1AEDA028FD318A008C3660 /* MarkupViewTypes.swift in Sources */,
1270CE9526DA85BB00B2D443 /* GradientColor.swift in Sources */,
2A0BAD3329E020D7005BC5D9 /* View+Autofocus.swift in Sources */,
2AFFFB822924DEE700A487E1 /* UndoRedoAssembly.swift in Sources */,
2A1F4CBA29B88DBE004516F6 /* SentryConfiguration.swift in Sources */,
539E019A2758422800067A24 /* SlashMenuRealtionView.swift in Sources */,
EA4AC463261C9AAB002E961E /* FileLoader.swift in Sources */,
Expand Down Expand Up @@ -12135,6 +12134,7 @@
3DE0CFD726F8593D003A606A /* SlashMenuItemType.swift in Sources */,
EAFDEFBF26381E22001B07E4 /* UITextView+Convenience.swift in Sources */,
12887F26274B94A600228330 /* DetailsServiceProtocol.swift in Sources */,
2A298E342BC7F1BE00F1194C /* UndoRedoViewController.swift in Sources */,
C9F44C7F27E351400078E709 /* TextBlockLeadingViewBuilder.swift in Sources */,
2A28D050297FCFE400E55E15 /* WidgetContainerView.swift in Sources */,
2ABF8F5D2B7FB1B5004B8FB8 /* ScreenStateView.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Anytype/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ internal enum Loc {
internal static let red = Loc.tr("Localizable", "Red", fallback: "Red")
/// Red background
internal static let redBackground = Loc.tr("Localizable", "Red background", fallback: "Red background")
/// Redo
internal static let redo = Loc.tr("Localizable", "Redo", fallback: "Redo")
/// Relations
internal static let relations = Loc.tr("Localizable", "Relations", fallback: "Relations")
/// Remove
Expand Down
1 change: 1 addition & 0 deletions Anytype/Resources/Strings/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@

"Undo typing" = "Undo typing";
"Undo" = "Undo";
"Redo" = "Redo";
"Actions.LinkItself" = "Link to";
"Actions.MakeAsTemplate" = "Make template";
"Actions.TemplateMakeDefault" = "Make default";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import Services

extension ObjectActionsServiceError {
var message: String {
extension ObjectActionsServiceError: LocalizedError {
public var errorDescription: String? {
switch self {
case .nothingToUndo:
return Loc.nothingToUndo
Expand Down
4 changes: 0 additions & 4 deletions Anytype/Sources/PresentationLayer/Assemblies/ModulesDI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ final class ModulesDI: ModulesDIProtocol {
TextRelationEditingModuleAssembly(serviceLocator: serviceLocator, uiHelpersDI: uiHelpersDI)
}

func undoRedo() -> UndoRedoModuleAssemblyProtocol {
return UndoRedoModuleAssembly(serviceLocator: serviceLocator, uiHelpersDI: uiHelpersDI)
}

func objectLayoutPicker() -> ObjectLayoutPickerModuleAssemblyProtocol {
return ObjectLayoutPickerModuleAssembly(serviceLocator: serviceLocator)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ protocol ModulesDIProtocol: AnyObject {
func relationValue() -> RelationValueModuleAssemblyProtocol
func relationsList() -> RelationsListModuleAssemblyProtocol
func textRelationEditing() -> TextRelationEditingModuleAssemblyProtocol
func undoRedo() -> UndoRedoModuleAssemblyProtocol
func objectLayoutPicker() -> ObjectLayoutPickerModuleAssemblyProtocol
func objectIconPicker() -> ObjectIconPickerModuleAssemblyProtocol
func objectSetting() -> ObjectSettingModuleAssemblyProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import SwiftUI
import Combine
import AnytypeCore

final class AnytypePopup: FloatingPanelController {
// TODO: Delete it
// Use Native SwiftUI navigation
class AnytypePopup: FloatingPanelController {

struct Configuration {
let isGrabberVisible: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class ObjectSettingsCoordinator: ObjectSettingsCoordinatorProtocol,
RelationValueCoordinatorOutput {
private let navigationContext: NavigationContextProtocol
private let objectSettingsModuleAssembly: ObjectSettingModuleAssemblyProtocol
private let undoRedoModuleAssembly: UndoRedoModuleAssemblyProtocol
private let objectLayoutPickerModuleAssembly: ObjectLayoutPickerModuleAssemblyProtocol
private let objectIconPickerModuleAssembly: ObjectIconPickerModuleAssemblyProtocol
private let relationsListCoordinatorAssembly: RelationsListCoordinatorAssemblyProtocol
Expand All @@ -30,7 +29,6 @@ final class ObjectSettingsCoordinator: ObjectSettingsCoordinatorProtocol,
init(
navigationContext: NavigationContextProtocol,
objectSettingsModuleAssembly: ObjectSettingModuleAssemblyProtocol,
undoRedoModuleAssembly: UndoRedoModuleAssemblyProtocol,
objectLayoutPickerModuleAssembly: ObjectLayoutPickerModuleAssemblyProtocol,
objectIconPickerModuleAssembly: ObjectIconPickerModuleAssemblyProtocol,
relationsListCoordinatorAssembly: RelationsListCoordinatorAssemblyProtocol,
Expand All @@ -39,7 +37,6 @@ final class ObjectSettingsCoordinator: ObjectSettingsCoordinatorProtocol,
) {
self.navigationContext = navigationContext
self.objectSettingsModuleAssembly = objectSettingsModuleAssembly
self.undoRedoModuleAssembly = undoRedoModuleAssembly
self.objectLayoutPickerModuleAssembly = objectLayoutPickerModuleAssembly
self.objectIconPickerModuleAssembly = objectIconPickerModuleAssembly
self.relationsListCoordinatorAssembly = relationsListCoordinatorAssembly
Expand Down Expand Up @@ -75,9 +72,9 @@ final class ObjectSettingsCoordinator: ObjectSettingsCoordinatorProtocol,
// MARK: - ObjectSettingsModelOutput

func undoRedoAction(document: BaseDocumentProtocol) {
let moduleViewController = undoRedoModuleAssembly.make(document: document)
// TODO: Move to editor
navigationContext.dismissTopPresented(animated: false)
navigationContext.present(moduleViewController)
navigationContext.present(UndoRedoViewController(objectId: document.objectId))
}

func layoutPickerAction(document: BaseDocumentProtocol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ final class ObjectSettingsCoordinatorAssembly: ObjectSettingsCoordinatorAssembly
ObjectSettingsCoordinator(
navigationContext: uiHelpersDI.commonNavigationContext(),
objectSettingsModuleAssembly: modulesDI.objectSetting(),
undoRedoModuleAssembly: modulesDI.undoRedo(),
objectLayoutPickerModuleAssembly: modulesDI.objectLayoutPicker(),
objectIconPickerModuleAssembly: modulesDI.objectIconPicker(),
relationsListCoordinatorAssembly: coordinatorsDI.relationsList(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ import SwiftUI
import AnytypeCore

struct UndoRedoView: View {
let viewModel: UndoRedoViewModel
@StateObject private var model: UndoRedoViewModel

init(objectId: String) {
self._model = StateObject(wrappedValue: UndoRedoViewModel(objectId: objectId))
}

var body: some View {
HStack(spacing: 16) {
ForEach(viewModel.buttonModels) { buttonModel in
Button {
buttonModel.action()
} label: {
ItemView(
imageAsset: buttonModel.imageAsset,
title: buttonModel.title
)
}

AsyncButton {
try await model.undo()
} label: {
ItemView(
imageAsset: .X32.Undo.undo,
title: Loc.undo
)
}

AsyncButton {
try await model.redo()
} label: {
ItemView(
imageAsset: .X32.Undo.redo,
title: Loc.redo
)
}
}
.padding(.init(top: 8, leading: 16, bottom: 0, trailing: 16))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

final class UndoRedoViewController: AnytypePopup {

convenience init(objectId: String) {
self.init(
contentView: UndoRedoView(objectId: objectId),
floatingPanelStyle: true,
configuration: .init(isGrabberVisible: false, dismissOnBackdropView: true)
)

backdropView.backgroundColor = .clear
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,27 @@ import UIKit
import AnytypeCore
import Services

@MainActor
final class UndoRedoViewModel: ObservableObject {
struct ButtonModel: Identifiable {
let id: String
let title: String
let imageAsset: ImageAsset
let action: () -> Void
}

var onErrorHandler: RoutingAction<String>?

lazy private(set) var buttonModels = buildButtonModels()

@Injected(\.objectActionsService)
private var objectActionsService: ObjectActionsServiceProtocol

private let objectId: String
private let objectActionsService: ObjectActionsServiceProtocol

init(
objectId: String,
objectActionsService: ObjectActionsServiceProtocol
objectId: String
) {
self.objectId = objectId
self.objectActionsService = objectActionsService
}

func undo() {
func undo() async throws {
AnytypeAnalytics.instance().logUndo()
Task { @MainActor in
do {
try await objectActionsService.undo(objectId: objectId)
} catch let error as ObjectActionsServiceError {
onErrorHandler?(error.message)
}
}
try await objectActionsService.undo(objectId: objectId)
}

func redo() {
func redo() async throws {
AnytypeAnalytics.instance().logRedo()
Task { @MainActor in
do {
try await objectActionsService.redo(objectId: objectId)
} catch let error as ObjectActionsServiceError {
onErrorHandler?(error.message)
}
}
}

private func buildButtonModels() -> [ButtonModel] {
[
.init(
id: "undo",
title: "Undo",
imageAsset: .X32.Undo.undo,
action: { [weak self] in self?.undo() }
),
.init(
id: "redo",
title: "Redo",
imageAsset: .X32.Undo.redo,
action: { [weak self] in self?.redo() }
)
]
try await objectActionsService.redo(objectId: objectId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ final class ObjectActionsService: ObjectActionsServiceProtocol {
do {
try await ClientCommands.objectUndo(.with {
$0.contextID = objectId
}).invoke()
}).invoke(ignoreLogErrors: .canNotMove)
} catch let error as Anytype_Rpc.Object.Undo.Response.Error where error.code == .canNotMove {
throw ObjectActionsServiceError.nothingToUndo
}
Expand All @@ -209,7 +209,7 @@ final class ObjectActionsService: ObjectActionsServiceProtocol {
do {
try await ClientCommands.objectRedo(.with {
$0.contextID = objectId
}).invoke()
}).invoke(ignoreLogErrors: .canNotMove)
} catch let error as Anytype_Rpc.Object.Redo.Response.Error where error.code == .canNotMove {
throw ObjectActionsServiceError.nothingToRedo
}
Expand Down

0 comments on commit 5f4707c

Please sign in to comment.