Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import SwiftUI
import AnytypeCore

struct ObjectActionsView: View {
@StateObject private var viewModel: ObjectActionsViewModel

@State private var viewModel: ObjectActionsViewModel
@Environment(\.dismiss) private var dismiss

init(objectId: String, spaceId: String, output: (any ObjectActionsOutput)?) {
self._viewModel = StateObject(wrappedValue: ObjectActionsViewModel(objectId: objectId, spaceId: spaceId, output: output))
self._viewModel = State(wrappedValue: ObjectActionsViewModel(objectId: objectId, spaceId: spaceId, output: output))
}

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
import Foundation
import Combine
import Services
import AnytypeCore
import UIKit
import DeepLinks

@MainActor
final class ObjectActionsViewModel: ObservableObject {
@Observable
final class ObjectActionsViewModel {

@ObservationIgnored
private let objectId: String
@ObservationIgnored
private let spaceId: String
@ObservationIgnored
private weak var output: (any ObjectActionsOutput)?


@ObservationIgnored
private lazy var document: any BaseDocumentProtocol = {
openDocumentsProvider.document(objectId: objectId, spaceId: spaceId)
}()


@ObservationIgnored
private lazy var widgetObject: (any BaseDocumentProtocol)? = {
guard let info = workspaceStorage.spaceInfo(spaceId: spaceId) else {
anytypeAssertionFailure("info not found")
return nil
}
return openDocumentsProvider.document(objectId: info.widgetsId, spaceId: spaceId)
}()
@Injected(\.objectActionsService)

@Injected(\.objectActionsService) @ObservationIgnored
private var service: any ObjectActionsServiceProtocol
@Injected(\.blockService)
@Injected(\.blockService) @ObservationIgnored
private var blockService: any BlockServiceProtocol
@Injected(\.templatesService)
@Injected(\.templatesService) @ObservationIgnored
private var templatesService: any TemplatesServiceProtocol
@Injected(\.documentsProvider)
@Injected(\.documentsProvider) @ObservationIgnored
private var documentsProvider: any DocumentsProviderProtocol
@Injected(\.blockWidgetService)
@Injected(\.blockWidgetService) @ObservationIgnored
private var blockWidgetService: any BlockWidgetServiceProtocol
@Injected(\.spaceViewsStorage)
@Injected(\.spaceViewsStorage) @ObservationIgnored
private var workspaceStorage: any SpaceViewsStorageProtocol
@Injected(\.deepLinkParser)
@Injected(\.deepLinkParser) @ObservationIgnored
private var deepLinkParser: any DeepLinkParserProtocol
@Injected(\.universalLinkParser)
@Injected(\.universalLinkParser) @ObservationIgnored
private var universalLinkParser: any UniversalLinkParserProtocol
@Injected(\.openedDocumentProvider)
@Injected(\.openedDocumentProvider) @ObservationIgnored
private var openDocumentsProvider: any OpenedDocumentsProviderProtocol
@Injected(\.workspaceService)
@Injected(\.workspaceService) @ObservationIgnored
private var workspaceService: any WorkspaceServiceProtocol
@Published var objectActions: [ObjectAction] = []
@Published var toastData: ToastBarData?
@Published var dismiss = false

var objectActions: [ObjectAction] = []
var toastData: ToastBarData?
var dismiss = false

init(objectId: String, spaceId: String, output: (any ObjectActionsOutput)?) {
self.objectId = objectId
Expand Down Expand Up @@ -110,6 +115,7 @@ final class ObjectActionsViewModel: ObservableObject {
position: first.map { .above(widgetId: $0.id) } ?? .end
)
}
toastData = ToastBarData(pinned ? Loc.unpinned : Loc.pinned)
dismiss.toggle()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ extension ObjectSetting {
Loc.icon
case .cover:
Loc.cover
case .description:
Loc.description
case .description(let isVisible):
isVisible ? Loc.hideDescription : Loc.showDescription
case .relations:
Loc.fields
case .history:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import Services
import AnytypeCore

struct ObjectSettingsView: View {
@StateObject private var viewModel: ObjectSettingsViewModel

@State private var viewModel: ObjectSettingsViewModel

init(
objectId: String,
spaceId: String,
output: some ObjectSettingsModelOutput
) {
self._viewModel = StateObject(wrappedValue: ObjectSettingsViewModel(objectId: objectId, spaceId: spaceId, output: output))
self._viewModel = State(wrappedValue: ObjectSettingsViewModel(objectId: objectId, spaceId: spaceId, output: output))
}

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Combine
import Services
import UIKit
import FloatingPanel
Expand All @@ -26,27 +25,32 @@ protocol ObjectSettingsModelOutput: AnyObject, ObjectHeaderRouterProtocol, Objec
}

@MainActor
final class ObjectSettingsViewModel: ObservableObject, ObjectActionsOutput {
@Observable
final class ObjectSettingsViewModel: ObjectActionsOutput {

@Injected(\.openedDocumentProvider)
@Injected(\.openedDocumentProvider) @ObservationIgnored
private var openDocumentsProvider: any OpenedDocumentsProviderProtocol
@Injected(\.propertiesService)
@Injected(\.propertiesService) @ObservationIgnored
private var propertiesService: any PropertiesServiceProtocol
@Injected(\.objectSettingsBuilder)
@Injected(\.objectSettingsBuilder) @ObservationIgnored
private var settingsBuilder: any ObjectSettingsBuilderProtocol
@Injected(\.objectSettingsConflictManager)
@Injected(\.objectSettingsConflictManager) @ObservationIgnored
private var conflictManager: any ObjectSettingsPrimitivesConflictManagerProtocol


@ObservationIgnored
private weak var output: (any ObjectSettingsModelOutput)?


@ObservationIgnored
private lazy var document: any BaseDocumentProtocol = {
openDocumentsProvider.document(objectId: objectId, spaceId: spaceId)
}()


@ObservationIgnored
let objectId: String
@ObservationIgnored
let spaceId: String
@Published var settings: [ObjectSetting] = []
@Published var showConflictAlert = false
var settings: [ObjectSetting] = []
var showConflictAlert = false

init(
objectId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AnytypeCore

struct ObjectSettingsMenuView: View {

@StateObject private var viewModel: ObjectSettingsMenuViewModel
@State private var viewModel: ObjectSettingsMenuViewModel

init(
objectId: String,
Expand All @@ -12,7 +12,7 @@ struct ObjectSettingsMenuView: View {
) {
let settingsVM = ObjectSettingsViewModel(objectId: objectId, spaceId: spaceId, output: output)
let actionsVM = ObjectActionsViewModel(objectId: objectId, spaceId: spaceId, output: settingsVM)
self._viewModel = StateObject(wrappedValue: ObjectSettingsMenuViewModel(settingsViewModel: settingsVM, actionsViewModel: actionsVM))
self._viewModel = State(wrappedValue: ObjectSettingsMenuViewModel(settingsViewModel: settingsVM, actionsViewModel: actionsVM))
}

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Foundation
import Combine
import SwiftUI

@MainActor
final class ObjectSettingsMenuViewModel: ObservableObject {
@Observable
final class ObjectSettingsMenuViewModel {

@Published var menuConfig = ObjectMenuConfiguration(sections: [])
var menuConfig = ObjectMenuConfiguration(sections: [])

@ObservationIgnored
let settingsViewModel: ObjectSettingsViewModel
@ObservationIgnored
let actionsViewModel: ObjectActionsViewModel
private var cancellables = Set<AnyCancellable>()

var showConflictAlert: Binding<Bool> {
Binding(
Expand Down Expand Up @@ -42,17 +43,30 @@ final class ObjectSettingsMenuViewModel: ObservableObject {
}

private func setupSubscriptions() {
settingsViewModel.$settings
.sink { [weak self] _ in
observeSettings()
observeActions()
}

private func observeSettings() {
withObservationTracking {
_ = settingsViewModel.settings
} onChange: { [weak self] in
Task { @MainActor [weak self] in
self?.rebuildMenu()
self?.observeSettings()
}
.store(in: &cancellables)
}
}

actionsViewModel.$objectActions
.sink { [weak self] _ in
private func observeActions() {
withObservationTracking {
_ = actionsViewModel.objectActions
} onChange: { [weak self] in
Task { @MainActor [weak self] in
self?.rebuildMenu()
self?.observeActions()
}
.store(in: &cancellables)
}
}

private func rebuildMenu() {
Expand Down
3 changes: 3 additions & 0 deletions Modules/Loc/Sources/Loc/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public enum Loc {
public static let header = Loc.tr("UI", "Header", fallback: "Header")
public static let hidden = Loc.tr("UI", "Hidden", fallback: "Hidden")
public static let hide = Loc.tr("UI", "Hide", fallback: "Hide")
public static let hideDescription = Loc.tr("UI", "Hide Description", fallback: "Hide Description")
public static let hideTypes = Loc.tr("UI", "Hide types", fallback: "Hide types")
public static let highlight = Loc.tr("UI", "Highlight", fallback: "Highlight")
public static let history = Loc.tr("UI", "History", fallback: "History")
Expand Down Expand Up @@ -579,6 +580,7 @@ public enum Loc {
public static let settings = Loc.tr("UI", "Settings", fallback: "Settings")
public static let share = Loc.tr("UI", "Share", fallback: "Share")
public static let show = Loc.tr("UI", "Show", fallback: "Show")
public static let showDescription = Loc.tr("UI", "Show Description", fallback: "Show Description")
public static let showTypes = Loc.tr("UI", "Show types", fallback: "Show types")
public static let skip = Loc.tr("UI", "Skip", fallback: "Skip")
public static let sky = Loc.tr("UI", "Sky", fallback: "Sky")
Expand Down Expand Up @@ -633,6 +635,7 @@ public enum Loc {
public static let unlocked = Loc.tr("UI", "Unlocked", fallback: "Unlocked")
public static let unmute = Loc.tr("UI", "Unmute", fallback: "Unmute")
public static let unpin = Loc.tr("UI", "Unpin", fallback: "Unpin")
public static let unpinned = Loc.tr("UI", "Unpinned", fallback: "Unpinned")
public static let unpublish = Loc.tr("UI", "Unpublish", fallback: "Unpublish")
public static let unread = Loc.tr("UI", "Unread", fallback: "Unread")
public static let unselectAll = Loc.tr("UI", "Unselect all", fallback: "Unselect all")
Expand Down
33 changes: 33 additions & 0 deletions Modules/Loc/Sources/Loc/Resources/UI.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -44547,6 +44547,17 @@
}
}
},
"Hide Description" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hide Description"
}
}
}
},
"Hide types" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -69135,6 +69146,17 @@
}
}
},
"Unpinned" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Unpinned"
}
}
}
},
"Preferences" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -83950,6 +83972,17 @@
}
}
},
"Show Description" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Show Description"
}
}
}
},
"Show types" : {
"extractionState" : "manual",
"localizations" : {
Expand Down