Skip to content

Commit d8d39ef

Browse files
authored
Merge pull request #4325 from anyproto/ios-5337-settings-menu-for-chat
IOS-5337 Settings menu for chat
2 parents bf354d4 + 21ab9af commit d8d39ef

File tree

8 files changed

+64
-15
lines changed

8 files changed

+64
-15
lines changed

Anytype/Sources/PresentationLayer/Flows/ChatCoordinator/ChatCoordinatorViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ final class ChatCoordinatorViewModel: ChatModuleOutput {
102102
func onWidgetsSelected() {
103103
pageNavigation?.pushHome()
104104
}
105-
105+
106+
func onSpaceSettingsSelected() {
107+
pageNavigation?.open(.spaceInfo(.settings(spaceId: spaceId)))
108+
}
109+
106110
func onInviteLinkSelected() {
107111
spaceShareData = SpaceShareData(spaceId: spaceId, route: .chat)
108112
}

Anytype/Sources/PresentationLayer/Modules/Chat/ChatModuleOutput.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protocol ChatModuleOutput: AnyObject {
1313
func onShowCameraSelected(data: SimpleCameraData)
1414
func onUrlSelected(url: URL)
1515
func onWidgetsSelected()
16+
func onSpaceSettingsSelected()
1617
func onInviteLinkSelected()
1718
func onShowQrCodeSelected(url: URL)
1819
func onPushNotificationsAlertSelected()

Anytype/Sources/PresentationLayer/Modules/Chat/ChatView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ struct ChatView: View {
2626
onTapOpenWidgets: {
2727
model.onTapWidgets()
2828
},
29+
onTapOpenSpaceSettings: {
30+
model.onTapSpaceSettings()
31+
},
2932
onTapAddMembers: {
3033
model.onTapInviteLink()
3134
}

Anytype/Sources/PresentationLayer/Modules/Chat/ChatViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ final class ChatViewModel: MessageModuleOutput, ChatActionProviderHandler {
212212
func onTapWidgets() {
213213
output?.onWidgetsSelected()
214214
}
215-
215+
216+
func onTapSpaceSettings() {
217+
output?.onSpaceSettingsSelected()
218+
}
219+
216220
func onTapInviteLink() {
217221
output?.onInviteLinkSelected()
218222
}

Anytype/Sources/PresentationLayer/Modules/Chat/Subviews/ChatHeader/ChatHeaderView.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ struct ChatHeaderView: View {
1010
spaceId: String,
1111
chatId: String,
1212
onTapOpenWidgets: @escaping () -> Void,
13+
onTapOpenSpaceSettings: @escaping () -> Void,
1314
onTapAddMembers: @escaping (() -> Void)
1415
) {
1516
self._model = StateObject(wrappedValue: ChatHeaderViewModel(
1617
spaceId: spaceId,
1718
chatId: chatId,
1819
onTapOpenWidgets: onTapOpenWidgets,
20+
onTapOpenSpaceSettings: onTapOpenSpaceSettings,
1921
onTapAddMembers: onTapAddMembers
2022
))
2123
}
@@ -54,9 +56,18 @@ struct ChatHeaderView: View {
5456
.frame(width: 28, height: 28)
5557
}
5658
}
57-
if model.showWidgetsButton {
59+
if model.isMultiChatSpace {
60+
ObjectSettingsMenuContainer(
61+
objectId: model.chatId,
62+
spaceId: model.spaceId,
63+
output: nil
64+
) {
65+
IconView(icon: model.icon)
66+
.frame(width: 28, height: 28)
67+
}
68+
} else {
5869
ExpandedTapAreaButton {
59-
model.tapOpenWidgets()
70+
model.tapOpenSpaceSettings()
6071
} label: {
6172
IconView(icon: model.icon)
6273
.frame(width: 28, height: 28)

Anytype/Sources/PresentationLayer/Modules/Chat/Subviews/ChatHeader/ChatHeaderViewModel.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ final class ChatHeaderViewModel: ObservableObject {
1717

1818
@Published var title: String?
1919
@Published var icon: Icon?
20-
@Published var showWidgetsButton: Bool = false
2120
@Published var chatLoading = false
2221
@Published var spaceLoading = false
2322
@Published var muted = false
2423
@Published var showAddMembersButton: Bool = false
24+
@Published private(set) var isMultiChatSpace: Bool = false
2525

2626
var showLoading: Bool { chatLoading || spaceLoading }
2727

28-
private let spaceId: String
29-
private let chatId: String
28+
let spaceId: String
29+
let chatId: String
30+
3031
private let onTapOpenWidgets: () -> Void
32+
private let onTapOpenSpaceSettings: () -> Void
3133
private let onTapAddMembers: (() -> Void)
3234
private let chatObject: any BaseDocumentProtocol
3335

@@ -40,11 +42,13 @@ final class ChatHeaderViewModel: ObservableObject {
4042
spaceId: String,
4143
chatId: String,
4244
onTapOpenWidgets: @escaping () -> Void,
45+
onTapOpenSpaceSettings: @escaping () -> Void,
4346
onTapAddMembers: @escaping (() -> Void)
4447
) {
4548
self.spaceId = spaceId
4649
self.chatId = chatId
4750
self.onTapOpenWidgets = onTapOpenWidgets
51+
self.onTapOpenSpaceSettings = onTapOpenSpaceSettings
4852
self.onTapAddMembers = onTapAddMembers
4953
self.chatObject = openDocumentProvider.document(objectId: chatId, spaceId: spaceId)
5054
}
@@ -60,6 +64,8 @@ final class ChatHeaderViewModel: ObservableObject {
6064

6165
func tapOpenWidgets() { onTapOpenWidgets() }
6266

67+
func tapOpenSpaceSettings() { onTapOpenSpaceSettings() }
68+
6369
func tapAddMembers() { onTapAddMembers() }
6470

6571
// MARK: - Private
@@ -68,9 +74,9 @@ final class ChatHeaderViewModel: ObservableObject {
6874
for await participantSpaceView in participantSpacesStorage.participantSpaceViewPublisher(spaceId: spaceId).values {
6975
let spaceView = participantSpaceView.spaceView
7076
spaceSupportsMultiChats = spaceView.uxType.supportsMultiChats
77+
isMultiChatSpace = spaceSupportsMultiChats
7178
spaceTitle = spaceView.title
7279
spaceIcon = spaceView.objectIconImage
73-
showWidgetsButton = spaceView.chatId == chatId && spaceView.initialScreenIsChat
7480
muted = !spaceView.effectiveNotificationMode(for: chatId).isUnmutedAll
7581
showAddMembersButton = participantSpaceView.participant?.permission == .owner
7682
updateHeaderDisplay()

Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectSettingsMenu/ObjectSettingsMenuContainer.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import SwiftUI
22
import AnytypeCore
33

4-
struct ObjectSettingsMenuContainer: View {
4+
struct ObjectSettingsMenuContainer<Label: View>: View {
55

66
@StateObject private var model: ObjectSettingsCoordinatorViewModel
7+
private let label: () -> Label
78

8-
init(objectId: String, spaceId: String, output: (any ObjectSettingsCoordinatorOutput)?) {
9+
init(
10+
objectId: String,
11+
spaceId: String,
12+
output: (any ObjectSettingsCoordinatorOutput)?,
13+
@ViewBuilder label: @escaping () -> Label
14+
) {
915
self._model = StateObject(wrappedValue: ObjectSettingsCoordinatorViewModel(objectId: objectId, spaceId: spaceId, output: output))
16+
self.label = label
1017
}
1118

1219
var body: some View {
13-
ObjectSettingsMenuView(objectId: model.objectId, spaceId: model.spaceId, output: model)
20+
ObjectSettingsMenuView(objectId: model.objectId, spaceId: model.spaceId, output: model, labelView: label)
1421
.sheet(item: $model.coverPickerData) {
1522
ObjectCoverPicker(data: $0)
1623
}
@@ -31,3 +38,14 @@ struct ObjectSettingsMenuContainer: View {
3138
}
3239
}
3340
}
41+
42+
extension ObjectSettingsMenuContainer where Label == AnyView {
43+
init(objectId: String, spaceId: String, output: (any ObjectSettingsCoordinatorOutput)?) {
44+
self.init(objectId: objectId, spaceId: spaceId, output: output) {
45+
AnyView(
46+
Image(asset: .X24.more)
47+
.foregroundColor(.Text.primary)
48+
)
49+
}
50+
}
51+
}

Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectSettingsMenu/ObjectSettingsMenuView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import SwiftUI
22
import AnytypeCore
33

4-
struct ObjectSettingsMenuView: View {
4+
struct ObjectSettingsMenuView<LabelView: View>: View {
55

66
@State private var viewModel: ObjectSettingsMenuViewModel
7+
private let labelView: LabelView
78

89
init(
910
objectId: String,
1011
spaceId: String,
11-
output: some ObjectSettingsModelOutput
12+
output: some ObjectSettingsModelOutput,
13+
@ViewBuilder labelView: () -> LabelView
1214
) {
1315
let settingsVM = ObjectSettingsViewModel(objectId: objectId, spaceId: spaceId, output: output)
1416
let actionsVM = ObjectActionsViewModel(objectId: objectId, spaceId: spaceId, output: settingsVM)
1517
self._viewModel = State(wrappedValue: ObjectSettingsMenuViewModel(settingsViewModel: settingsVM, actionsViewModel: actionsVM))
18+
self.labelView = labelView()
1619
}
1720

1821
var body: some View {
@@ -24,8 +27,7 @@ struct ObjectSettingsMenuView: View {
2427
renderSection(section)
2528
}
2629
} label: {
27-
Image(asset: .X24.more)
28-
.foregroundColor(.Text.primary)
30+
labelView
2931
}
3032
.task {
3133
await viewModel.startTasks()

0 commit comments

Comments
 (0)