Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-3264 Version history | Impl readonly mode #1879

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -304,7 +304,8 @@ final class BaseDocument: BaseDocumentProtocol {
let newPermissios = ObjectPermissions(
details: details ?? ObjectDetails(id: ""),
isLocked: isLocked,
participantCanEdit: participantIsEditor,
participantCanEdit: participantIsEditor,
isVersionMode: mode.isVersion,
objectRestrictions: objectRestrictions.objectRestriction
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ enum DocumentMode: Hashable, Codable {
var isHandling: Bool {
self == .handling
}

var isVersion: Bool {
if case .version = self {
return true
} else {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ extension ObjectPermissions {
details: ObjectDetails,
isLocked: Bool,
participantCanEdit: Bool,
isVersionMode: Bool,
objectRestrictions: [ObjectRestriction]
) {
let isArchive = details.isArchived
let isTemplateType = details.isTemplateType

let canEdit = !isLocked && !isArchive && participantCanEdit
let canEdit = !isLocked && !isArchive && participantCanEdit && !isVersionMode
let canApplyUneditableActions = participantCanEdit && !isArchive

let specificTypes = details.layoutValue != .set
Expand Down Expand Up @@ -70,7 +71,7 @@ extension ObjectPermissions {
self.canShare = !isTemplateType
self.canApplyTemplates = canEdit && !isTemplateType

if isLocked {
if isLocked || isVersionMode {
self.editBlocks = .readonly(.locked)
} else if isArchive {
self.editBlocks = .readonly(.archived)
Expand Down Expand Up @@ -99,7 +100,8 @@ extension ObjectDetails {
ObjectPermissions(
details: self,
isLocked: false,
participantCanEdit: participantCanEdit,
participantCanEdit: participantCanEdit,
isVersionMode: false,
objectRestrictions: restrictionsValue
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct FlowRelationsView: View {
TitleWithIconView(
icon: viewModel.icon,
showIcon: viewModel.showIcon,
canEditIcon: viewModel.canEditIcon,
title: viewModel.title,
style: .list
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import SwiftUI
class FlowRelationsViewModel: ObservableObject {
let icon: Icon?
let showIcon: Bool
let canEditIcon: Bool
let title: String?
let description: String?
let relations: [Relation]

init(
icon: Icon? = nil,
showIcon: Bool = true,
canEditIcon: Bool,
title: String?,
description: String?,
relations: [Relation]
) {
self.icon = icon
self.showIcon = showIcon
self.canEditIcon = canEditIcon
self.title = title
self.description = description
self.relations = relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AnytypeCore
struct TitleWithIconView: View {
let icon: Icon?
let showIcon: Bool
let canEditIcon: Bool
let title: String?
let style: TitleWithIconStyle

Expand All @@ -22,6 +23,7 @@ struct TitleWithIconView: View {
height: style.iconSize.height
)
.padding(.top, 1)
.disabled(!canEditIcon)
}
} else {
title(with: title)
Expand All @@ -47,7 +49,8 @@ struct TitleWithIconView_Previews: PreviewProvider {
static var previews: some View {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - header style",
style: .header
)
Expand All @@ -56,6 +59,7 @@ struct TitleWithIconView_Previews: PreviewProvider {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - list style",
style: .list
)
Expand All @@ -64,6 +68,7 @@ struct TitleWithIconView_Previews: PreviewProvider {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - gallery style",
style: .gallery
)
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 @@ -250,7 +250,8 @@ final class SetObjectWidgetInternalViewModel: ObservableObject {
details,
dataView: setDocument.dataView,
activeView: setDocument.activeView,
viewRelationValueIsLocked: false,
viewRelationValueIsLocked: false,
canEditIcon: setDocument.setPermissions.canEditSetObjectIcon,
storage: subscriptionStorage.detailsStorage,
spaceId: setDocument.spaceId,
onItemTap: { [weak self] in
Expand Down
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
Loading
Loading