Skip to content

Commit

Permalink
IOS-3267 Impl verison restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-pusya committed Aug 5, 2024
1 parent 355247a commit 5decc52
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Anytype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@
2E88257A2C5A61A200FD59D3 /* ObjectVersionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8825792C5A61A200FD59D3 /* ObjectVersionView.swift */; };
2E88257C2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E88257B2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift */; };
2E88257E2C5BDF0D00FD59D3 /* DocumentMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E88257D2C5BDF0D00FD59D3 /* DocumentMode.swift */; };
2E8825802C6140BB00FD59D3 /* ObjectVersionData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E88257F2C6140BB00FD59D3 /* ObjectVersionData.swift */; };
2E92219D294B8B5000968750 /* DataViewBlockViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E92219C294B8B5000968750 /* DataViewBlockViewModel.swift */; };
2E92219F294B8CDE00968750 /* DataViewBlockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E92219E294B8CDE00968750 /* DataViewBlockConfiguration.swift */; };
2E9221A1294B8D4900968750 /* DataViewBlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E9221A0294B8D4900968750 /* DataViewBlockView.swift */; };
Expand Down Expand Up @@ -2918,6 +2919,7 @@
2E8825792C5A61A200FD59D3 /* ObjectVersionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectVersionView.swift; sourceTree = "<group>"; };
2E88257B2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectVersionViewModel.swift; sourceTree = "<group>"; };
2E88257D2C5BDF0D00FD59D3 /* DocumentMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentMode.swift; sourceTree = "<group>"; };
2E88257F2C6140BB00FD59D3 /* ObjectVersionData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectVersionData.swift; sourceTree = "<group>"; };
2E92219C294B8B5000968750 /* DataViewBlockViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockViewModel.swift; sourceTree = "<group>"; };
2E92219E294B8CDE00968750 /* DataViewBlockConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockConfiguration.swift; sourceTree = "<group>"; };
2E9221A0294B8D4900968750 /* DataViewBlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7922,6 +7924,7 @@
children = (
2E8825792C5A61A200FD59D3 /* ObjectVersionView.swift */,
2E88257B2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift */,
2E88257F2C6140BB00FD59D3 /* ObjectVersionData.swift */,
);
path = Object;
sourceTree = "<group>";
Expand Down Expand Up @@ -11732,6 +11735,7 @@
2AB7AAED2AF537AB00ED3E02 /* RemoteStorageSegmentInfo.swift in Sources */,
2AF109562A02639700EDDE26 /* FileIconBuilder.swift in Sources */,
2AF109582A03C56600EDDE26 /* NSItemProvider+Async.swift in Sources */,
2E8825802C6140BB00FD59D3 /* ObjectVersionData.swift in Sources */,
2AD7E2E52BB1768600F2CDA1 /* IdentifiableExtension.swift in Sources */,
123FDAD026C1505700F6F44B /* EditorPageController+UICollectionViewDelegate.swift in Sources */,
3D5A417A2704541900F1F6A1 /* SearchBar.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ObjectSettingsCoordinatorView: View {
RelationsListCoordinatorView(document: $0.document, output: model)
}
.sheet(item: $model.versionHistoryData) {
VersionHistoryCoordinatorView(data: $0)
VersionHistoryCoordinatorView(data: $0, output: model)
}
.onChange(of: model.dismiss) { _ in
dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import AnytypeCore
import SwiftUI

@MainActor
final class ObjectSettingsCoordinatorViewModel: ObservableObject,
ObjectSettingsModelOutput,
RelationValueCoordinatorOutput {
final class ObjectSettingsCoordinatorViewModel:
ObservableObject,
ObjectSettingsModelOutput,
RelationValueCoordinatorOutput,
ObjectVersionModuleOutput
{

let objectId: String
private weak var output: (any ObjectSettingsCoordinatorOutput)?
Expand Down Expand Up @@ -96,4 +99,10 @@ final class ObjectSettingsCoordinatorViewModel: ObservableObject,
output?.showEditorScreen(data: data)
}
}

// MARK: - ObjectVersionModuleOutput

func versionRestored() {
dismiss.toggle()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ struct VersionHistoryCoordinatorView: View {
@StateObject private var model: VersionHistoryCoordinatorViewModel
@Environment(\.dismiss) private var dismiss

init(data: VersionHistoryData) {
_model = StateObject(wrappedValue: VersionHistoryCoordinatorViewModel(data: data))
init(data: VersionHistoryData, output: (any ObjectVersionModuleOutput)?) {
_model = StateObject(wrappedValue: VersionHistoryCoordinatorViewModel(data: data, output: output))
}

var body: some View {
Expand All @@ -16,7 +16,7 @@ struct VersionHistoryCoordinatorView: View {
output: model
)
.sheet(item: $model.objectVersionData) {
ObjectVersionView(data: $0)
ObjectVersionView(data: $0, output: model)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import Services
import SwiftUI

@MainActor
protocol VersionHistoryModuleOutput: AnyObject {
func onVersionTap(title: String, icon: ObjectIcon?, versionId: String)
}

@MainActor
final class VersionHistoryCoordinatorViewModel: ObservableObject, VersionHistoryModuleOutput {
final class VersionHistoryCoordinatorViewModel:
ObservableObject,
VersionHistoryModuleOutput,
ObjectVersionModuleOutput
{

@Published var objectVersionData: ObjectVersionData?

let data: VersionHistoryData

init(data: VersionHistoryData) {
private weak var output: (any ObjectVersionModuleOutput)?

init(data: VersionHistoryData, output: (any ObjectVersionModuleOutput)?) {
self.data = data
self.output = output
}

// MARK: VersionHistoryModuleOutput
Expand All @@ -29,5 +31,11 @@ final class VersionHistoryCoordinatorViewModel: ObservableObject, VersionHistory
isListType: data.isListType
)
}

// MARK: ObjectVersionModuleOutput

func versionRestored() {
output?.versionRestored()
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Services

struct ObjectVersionData: Identifiable, Hashable {
let title: String
let icon: ObjectIcon?
let objectId: String
let spaceId: String
let versionId: String
let isListType: Bool

var id: Int { hashValue }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import SwiftUI
struct ObjectVersionView: View {

@StateObject private var model: ObjectVersionViewModel
@Environment(\.dismiss) private var dismiss

init(data: ObjectVersionData) {
_model = StateObject(wrappedValue: ObjectVersionViewModel(data: data))
init(data: ObjectVersionData, output: (any ObjectVersionModuleOutput)?) {
_model = StateObject(wrappedValue: ObjectVersionViewModel(data: data, output: output))
}

var body: some View {
content
.overlay(alignment: .topLeading) {
header
}
.task {
await model.setupObject()
}
VStack(spacing: 0) {
content
buttons
}
.overlay(alignment: .topLeading) {
header
}
.task {
await model.setupObject()
}
.onChange(of: model.dismiss) { _ in
dismiss()
}
}

private var header: some View {
Expand All @@ -41,4 +48,25 @@ struct ObjectVersionView: View {
EmptyView()
}
}

private var buttons: some View {
HStack {
StandardButton(
Loc.cancel,
style: .secondaryMedium,
action: { model.onCancelTap() }
)
StandardButton(
Loc.restore,
style: .primaryMedium,
action: { model.onRestoreTap() }
)
}
.padding(.top, 16)
.padding(.horizontal, 20)
.overlay(alignment: .top) {
AnytypeDivider()
}
.background(Color.Background.primary)
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import Services
import SwiftUI

struct ObjectVersionData: Identifiable, Hashable {
let title: String
let icon: ObjectIcon?
let objectId: String
let spaceId: String
let versionId: String
let isListType: Bool

var id: Int { hashValue }
@MainActor
protocol ObjectVersionModuleOutput: AnyObject {
func versionRestored()
}

@MainActor
final class ObjectVersionViewModel: ObservableObject {

@Published var screenData: EditorScreenData?
@Published var dismiss = false

let data: ObjectVersionData

init(data: ObjectVersionData) {
@Injected(\.historyVersionsService)
private var historyVersionsService: any HistoryVersionsServiceProtocol

private weak var output: (any ObjectVersionModuleOutput)?

init(data: ObjectVersionData, output: (any ObjectVersionModuleOutput)?) {
self.data = data
self.output = output
}

func setupObject() async {
self.screenData = currentScreenData()
}

func onCancelTap() {
dismiss.toggle()
}

func onRestoreTap() {
Task {
try await historyVersionsService.setVersion(objectId: data.objectId, versionId: data.versionId)
output?.versionRestored()
}
}

private func currentScreenData() -> EditorScreenData? {
let mode: DocumentMode = .version(data.versionId)
if data.isListType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Services
import SwiftUI

@MainActor
protocol VersionHistoryModuleOutput: AnyObject {
func onVersionTap(title: String, icon: ObjectIcon?, versionId: String)
}

@MainActor
final class VersionHistoryViewModel: ObservableObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct EditorSetView: View {
VStack(spacing: 0) {
Spacer.fixedHeight(headerMinimizedSize.height)
contentTypeView
.background(Color.Background.primary)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SetFullHeader: View {
header
}
}
.background(Color.Background.primary)
}

private var header: some View {
Expand Down

0 comments on commit 5decc52

Please sign in to comment.