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 @@ -253,10 +253,10 @@ final class EditorSetCoordinatorViewModel:

func templateEditingHandler(
setting: ObjectCreationSetting,
onSetAsDefaultTempalte: @escaping (String) -> Void,
onSetAsDefaultTemplate: @escaping (String) -> Void,
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
) {
legacySetObjectCreationSettingsCoordinator.templateEditingHandler(setting: setting, onSetAsDefaultTempalte: onSetAsDefaultTempalte, onTemplateSelection: onTemplateSelection)
legacySetObjectCreationSettingsCoordinator.templateEditingHandler(setting: setting, onSetAsDefaultTemplate: onSetAsDefaultTemplate, onTemplateSelection: onTemplateSelection)
}

func onObjectTypeLayoutTap(_ data: LayoutPickerData) {
Expand All @@ -282,7 +282,7 @@ final class EditorSetCoordinatorViewModel:

templatesCoordinator.showTemplatesPicker(
data: data,
onSetAsDefaultTempalte: { [weak self] templateId in
onSetAsDefaultTemplate: { [weak self] templateId in
self?.setTemplateAsDefault(objectId: objectId, templateId: templateId)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protocol SetObjectCreationSettingsCoordinatorProtocol: AnyObject, SetObjectCreat
func showTemplateEditing(
setting: ObjectCreationSetting,
onTemplateSelection: (() -> Void)?,
onSetAsDefaultTempalte: @escaping (String) -> Void,
onSetAsDefaultTemplate: @escaping (String) -> Void,
completion: (() -> Void)?
)
}
Expand All @@ -32,7 +32,7 @@ final class SetObjectCreationSettingsCoordinator:
func showTemplateEditing(
setting: ObjectCreationSetting,
onTemplateSelection: (() -> Void)?,
onSetAsDefaultTempalte: @escaping (String) -> Void,
onSetAsDefaultTemplate: @escaping (String) -> Void,
completion: (() -> Void)?
) {
let editorView = EditorPageCoordinatorView(
Expand All @@ -47,10 +47,13 @@ final class SetObjectCreationSettingsCoordinator:
}
)

self.useAsTemplateAction = onSetAsDefaultTempalte
self.useAsTemplateAction = onSetAsDefaultTemplate

let editingTemplateViewController = TemplateEditingViewController(
editorViewController: UIHostingController(rootView: editorView),
objectId: setting.templateId,
spaceId: setting.spaceId,
output: self,
onSettingsTap: { [weak self] in
guard let self = self else { return }
editorModuleInput?.showSettings(output: self)
Expand Down Expand Up @@ -112,20 +115,20 @@ final class SetObjectCreationSettingsCoordinator:

func templateEditingHandler(
setting: ObjectCreationSetting,
onSetAsDefaultTempalte: @escaping (String) -> Void,
onSetAsDefaultTemplate: @escaping (String) -> Void,
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
) {
showTemplateEditing(
setting: setting,
onTemplateSelection: { [weak self] in
self?.navigationContext.dismissAllPresented(animated: true) {
onSetAsDefaultTempalte(setting.templateId)
onSetAsDefaultTemplate(setting.templateId)
onTemplateSelection?(setting)
}
},
onSetAsDefaultTempalte: { [weak self] templateId in
onSetAsDefaultTemplate: { [weak self] templateId in
self?.navigationContext.dismissTopPresented(animated: true, completion: {
onSetAsDefaultTempalte(templateId)
onSetAsDefaultTemplate(templateId)
})
},
completion: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ protocol TemplatesCoordinatorProtocol {
@MainActor
func showTemplatesPicker(
document: some BaseDocumentProtocol,
onSetAsDefaultTempalte: @escaping (String) -> Void
onSetAsDefaultTemplate: @escaping (String) -> Void
)

@MainActor
func showTemplatesPicker(
data: TemplatePickerViewModelData,
onSetAsDefaultTempalte: @escaping (String) -> Void
onSetAsDefaultTemplate: @escaping (String) -> Void
)
}

Expand All @@ -26,30 +26,30 @@ final class TemplatesCoordinator: TemplatesCoordinatorProtocol, ObjectSettingsCo
private var toastPresenter: any ToastPresenterProtocol

private var editorModuleInputs = [String: any EditorPageModuleInput]()
private var onSetAsDefaultTempalte: ((String) -> Void)?
private var onSetAsDefaultTemplate: ((String) -> Void)?

nonisolated init() {}

@MainActor
func showTemplatesPicker(
document: some BaseDocumentProtocol,
onSetAsDefaultTempalte: @escaping (String) -> Void
onSetAsDefaultTemplate: @escaping (String) -> Void
) {
let data = TemplatePickerViewModelData(
mode: .objectTemplate(objectId: document.objectId),
typeId: document.details?.objectType.id,
spaceId: document.spaceId,
defaultTemplateId: nil
)
showTemplatesPicker(data: data, onSetAsDefaultTempalte: onSetAsDefaultTempalte)
showTemplatesPicker(data: data, onSetAsDefaultTemplate: onSetAsDefaultTemplate)
}

@MainActor
func showTemplatesPicker(
data: TemplatePickerViewModelData,
onSetAsDefaultTempalte: @escaping (String) -> Void
onSetAsDefaultTemplate: @escaping (String) -> Void
) {
self.onSetAsDefaultTempalte = onSetAsDefaultTempalte
self.onSetAsDefaultTemplate = onSetAsDefaultTemplate
let picker = TemplatePickerView(viewModel: .init(data: data, output: self))
let hostViewController = UIHostingController(rootView: picker)
hostViewController.modalPresentationStyle = .fullScreen
Expand Down Expand Up @@ -101,7 +101,7 @@ extension TemplatesCoordinator: TemplatePickerViewModuleOutput {
func didCreateTemplate(templateId: String) {}

func didTapUseTemplateAsDefault(templateId: String) {
onSetAsDefaultTempalte?(templateId)
onSetAsDefaultTemplate?(templateId)
}

func didUndoRedo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ final class TemplateEditingViewController: UIViewController {
private let editorViewController: UIViewController
private let onSettingsTap: () -> Void
private let onSelectTemplateTap: (() -> Void)?
private let objectId: String
private let spaceId: String
private weak var output: (any ObjectSettingsCoordinatorOutput)?
private var settingsMenuView: UIView?

private lazy var keyboardHelper = KeyboardEventsListnerHelper(
didShowAction: { [weak selectTemplateButton] _ in
Expand Down Expand Up @@ -35,10 +39,16 @@ final class TemplateEditingViewController: UIViewController {

init(
editorViewController: UIViewController,
objectId: String,
spaceId: String,
output: any ObjectSettingsCoordinatorOutput,
onSettingsTap: @escaping () -> Void,
onSelectTemplateTap: (() -> Void)?
) {
self.editorViewController = editorViewController
self.objectId = objectId
self.spaceId = spaceId
self.output = output
self.onSettingsTap = onSettingsTap
self.onSelectTemplateTap = onSelectTemplateTap

Expand All @@ -54,8 +64,8 @@ final class TemplateEditingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

setupLayout()
setupView()
setupLayout()
}

@objc
Expand All @@ -73,6 +83,13 @@ final class TemplateEditingViewController: UIViewController {
settingsButton.setImage(UIImage(asset: .X24.more), for: .normal)
settingsButton.addTarget(self, action: #selector(didTapSettingButton), for: .touchUpInside)
settingsButton.tintColor = .Control.secondary

if FeatureFlags.newObjectSettings, let output {
let menuContainer = ObjectSettingsMenuContainer(objectId: objectId, spaceId: spaceId, output: output)
let hostingController = UIHostingController(rootView: menuContainer)
hostingController.view.backgroundColor = .clear
self.settingsMenuView = hostingController.view
}
}

private func setupLayout() {
Expand All @@ -89,9 +106,16 @@ final class TemplateEditingViewController: UIViewController {
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
}

fakeNavigationView.addSubview(settingsButton) {
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
if FeatureFlags.newObjectSettings, let settingsMenuView {
fakeNavigationView.addSubview(settingsMenuView) {
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
}
} else {
fakeNavigationView.addSubview(settingsButton) {
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
}
}

embedChild(editorViewController, into: view)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import AnytypeCore

struct TemplatePickerView: View {
@StateObject var viewModel: TemplatePickerViewModel
Expand Down Expand Up @@ -92,12 +93,23 @@ struct TemplatePickerView: View {
}
}

@ViewBuilder
private var settingsButton: some View {
Button {
viewModel.onSettingsButtonTap()
} label: {
Image(asset: .X24.more)
.foregroundColor(.Control.secondary)
if FeatureFlags.newObjectSettings {
if viewModel.items.isNotEmpty {
ObjectSettingsMenuContainer(
objectId: viewModel.selectedItem().object.id,
spaceId: viewModel.spaceId,
output: viewModel.output
)
}
} else {
Button {
viewModel.onSettingsButtonTap()
} label: {
Image(asset: .X24.more)
.foregroundColor(.Control.secondary)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Services
import SwiftUI

@MainActor
protocol TemplatePickerViewModuleOutput: AnyObject {
protocol TemplatePickerViewModuleOutput: AnyObject, ObjectSettingsCoordinatorOutput {
func onTemplatesChanged(_ templates: [ObjectDetails], completion: ([TemplatePickerData]) -> Void)
func onTemplateSettingsTap(_ model: TemplatePickerViewModel.Item)
func selectionOptionsView(_ provider: some OptionsItemProvider) -> AnyView
Expand Down Expand Up @@ -40,7 +40,9 @@ final class TemplatePickerViewModel: ObservableObject, OptionsItemProvider {
if case .objectTemplate = data.mode { return true }
return false
}


var spaceId: String { data.spaceId }

private let data: TemplatePickerViewModelData
private var didSetupDefaultItem = false
private var dismiss: DismissAction?
Expand All @@ -49,8 +51,8 @@ final class TemplatePickerViewModel: ObservableObject, OptionsItemProvider {
private var objectService: any ObjectActionsServiceProtocol
@Injected(\.templatesSubscription)
private var templatesSubscriptionService: any TemplatesSubscriptionServiceProtocol
private weak var output: (any TemplatePickerViewModuleOutput)?

weak var output: (any TemplatePickerViewModuleOutput)?

// MARK: - OptionsItemProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol SetObjectCreationSettingsOutput: AnyObject {
func onObjectTypesSearchAction(setDocument: some SetDocumentProtocol, completion: @escaping (ObjectType) -> Void)
func templateEditingHandler(
setting: ObjectCreationSetting,
onSetAsDefaultTempalte: @escaping (String) -> Void,
onSetAsDefaultTemplate: @escaping (String) -> Void,
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ final class SetObjectCreationSettingsViewModel: ObservableObject {
AnytypeAnalytics.instance().logTemplateCreate(objectType: .object(typeId: objectTypeId), spaceId: spaceId)
output?.templateEditingHandler(
setting: ObjectCreationSetting(objectTypeId: objectTypeId, spaceId: spaceId, templateId: templateId),
onSetAsDefaultTempalte: { [weak self] templateId in
onSetAsDefaultTemplate: { [weak self] templateId in
self?.setTemplateAsDefault(templateId: templateId)
},
onTemplateSelection: data.onTemplateSelection
Expand Down Expand Up @@ -221,7 +221,7 @@ final class SetObjectCreationSettingsViewModel: ObservableObject {
case .editTemplate:
output?.templateEditingHandler(
setting: ObjectCreationSetting(objectTypeId: objectTypeId, spaceId: spaceId, templateId: templateViewModel.id),
onSetAsDefaultTempalte: { [weak self] templateId in
onSetAsDefaultTemplate: { [weak self] templateId in
self?.setTemplateAsDefault(templateId: templateId)
},
onTemplateSelection: data.onTemplateSelection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ final class EditorPageController: UIViewController {

private lazy var navigationBarHelper: EditorNavigationBarHelper = EditorNavigationBarHelper(
navigationBarView: navigationBarView,
navigationBarBackgroundView: navigationBarBackgroundView,
navigationBarBackgroundView: navigationBarBackgroundView,
objectId: viewModel.document.objectId,
spaceId: viewModel.document.spaceId,
output: viewModel.router,
onSettingsBarButtonItemTap: { [weak viewModel] in
UISelectionFeedbackGenerator().selectionChanged()
viewModel?.showSettings()
},
},
onSelectAllBarButtonItemTap: { [weak self] allSelected in
self?.handleSelectState(allSelected: allSelected)
},
Expand All @@ -67,7 +70,7 @@ final class EditorPageController: UIViewController {
},
onTemplatesButtonTap: { [weak viewModel] in
viewModel?.showTemplates()
},
},
onSyncStatusTap: { [weak viewModel] in
UISelectionFeedbackGenerator().selectionChanged()
viewModel?.showSyncStatusInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import UIKit
import Services
import SwiftUI
import AnytypeCore

@MainActor
final class EditorNavigationBarHelper {
Expand All @@ -16,6 +17,7 @@ final class EditorNavigationBarHelper {
private let selectAllButton: UIButton

private let settingsItem: UIEditorBarButtonItem
private let settingsMenuView: UIView?
private let syncStatusItem: EditorSyncStatusItem
private let webBannerItem: EditorWebBannerItem
private let rightContanerForEditing: UIView
Expand All @@ -38,6 +40,9 @@ final class EditorNavigationBarHelper {
init(
navigationBarView: EditorNavigationBarView,
navigationBarBackgroundView: UIView,
objectId: String,
spaceId: String,
output: (any ObjectSettingsCoordinatorOutput)?,
onSettingsBarButtonItemTap: @escaping () -> Void,
onSelectAllBarButtonItemTap: @escaping (Bool) -> Void,
onDoneBarButtonItemTap: @escaping () -> Void,
Expand All @@ -48,6 +53,16 @@ final class EditorNavigationBarHelper {
self.navigationBarView = navigationBarView
self.navigationBarBackgroundView = navigationBarBackgroundView
self.settingsItem = UIEditorBarButtonItem(imageAsset: .X24.more, action: onSettingsBarButtonItemTap)

if FeatureFlags.newObjectSettings {
let menuContainer = ObjectSettingsMenuContainer(objectId: objectId, spaceId: spaceId, output: output)
let hostingController = UIHostingController(rootView: menuContainer)
hostingController.view.backgroundColor = .clear
self.settingsMenuView = hostingController.view
} else {
self.settingsMenuView = nil
}

self.syncStatusItem = EditorSyncStatusItem(onTap: onSyncStatusTap)
self.webBannerItem = EditorWebBannerItem(onTap: onWebBannerTap)

Expand Down Expand Up @@ -94,11 +109,19 @@ final class EditorNavigationBarHelper {
)

self.rightContanerForEditing.layoutUsing.stack {
$0.hStack(
spacing: 12,
syncStatusItem,
settingsItem
)
if FeatureFlags.newObjectSettings, let settingsMenuView {
$0.hStack(
spacing: 12,
syncStatusItem,
settingsMenuView
)
} else {
$0.hStack(
spacing: 12,
syncStatusItem,
settingsItem
)
}
}

navigationBarView.bannerView = webBannerItem
Expand Down
Loading