From 9a56dae3a3a9ff07933b9ce2d30e4ecaf1937b5e Mon Sep 17 00:00:00 2001 From: Flavio Alescio Date: Thu, 20 Apr 2023 17:28:36 +0200 Subject: [PATCH] work on text input for room creation --- .../Screens/CreateRoom/CreateRoomModels.swift | 12 +++ .../CreateRoom/CreateRoomViewModel.swift | 4 + .../CreateRoom/View/CreateRoomScreen.swift | 90 ++++++++++++++++--- 3 files changed, 93 insertions(+), 13 deletions(-) diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift index 6e6f880de..032e417aa 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift @@ -22,9 +22,21 @@ enum CreateRoomViewModelAction { struct CreateRoomViewState: BindableState { var selectedUsers: [UserProfile] + var bindings = CreateRoomViewStateBindings() + + var canCreateRoom: Bool { + !bindings.roomName.isEmpty + } +} + +struct CreateRoomViewStateBindings { + var roomName = "" + var roomTopic = "" } enum CreateRoomViewAction { case createRoom + case selectPrivateRoom + case selectPublicRoom case deselectUser(UserProfile) } diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift index fe55ca956..c30c0176d 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift @@ -38,6 +38,10 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol actionsSubject.send(.createRoom) case .deselectUser(let user): state.selectedUsers.removeAll(where: { $0.userID == user.userID }) + case .selectPrivateRoom: + break + case .selectPublicRoom: + break } } } diff --git a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift index 38ce57dfc..cb9c6e1ea 100644 --- a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift +++ b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift @@ -20,23 +20,60 @@ struct CreateRoomScreen: View { @ObservedObject var context: CreateRoomViewModel.Context var body: some View { - ScrollView { - mainContent - } - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) - .navigationTitle(L10n.actionCreateARoom) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .confirmationAction) { - createButton + mainContent + .scrollContentBackground(.hidden) + .background(Color.element.formBackground.ignoresSafeArea()) + .navigationTitle(L10n.screenCreateRoomTitle) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .confirmationAction) { + createButton + } } - } } /// The main content of the view to be shown in a scroll view. var mainContent: some View { - selectedUsersSection + VStack(alignment: .center, spacing: 24) { + Form { + roomSection + topicSection + } + selectedUsersSection + Spacer() + Form { + securitySection + } + } + } + + private var roomSection: some View { + Section { + TextField(L10n.screenCreateRoomRoomNameLabel, + text: $context.roomName, + prompt: Text(L10n.screenCreateRoomRoomNamePlaceholder).compoundFormTextFieldPlaceholder(), + axis: .horizontal) + .textFieldStyle(.compoundForm) + } header: { + Text(L10n.screenCreateRoomRoomNameLabel) + .compoundFormSectionFooter() + } + .compoundFormSection() + } + + private var topicSection: some View { + Section { + TextField(L10n.screenCreateRoomTopicLabel, + text: $context.roomTopic, + prompt: Text(L10n.screenCreateRoomTopicPlaceholder).compoundFormTextFieldPlaceholder(), + axis: .vertical) + .lineLimit(3, reservesSpace: false) + .textFieldStyle(.compoundForm) + } header: { + Text(L10n.screenCreateRoomTopicLabel) + .compoundFormSectionFooter() + } + .formSectionStyle() } @ScaledMetric private var cellWidth: CGFloat = 64 @@ -54,10 +91,35 @@ struct CreateRoomScreen: View { } } + private var securitySection: some View { + Section { + Button(action: selectPrivate) { + Label(L10n.screenCreateRoomPrivateOptionTitle, systemImage: "lock.shield") + } + .buttonStyle(FormButtonStyle(accessory: .navigationLink)) + Button(action: selectPrivate) { + Label(L10n.screenCreateRoomPublicOptionTitle, systemImage: "exclamationmark.shield") + } + .buttonStyle(FormButtonStyle(accessory: .navigationLink)) + } header: { + Text("SECURITY") + } + .formSectionStyle() + } + private var createButton: some View { Button { context.send(viewAction: .createRoom) } label: { Text(L10n.actionCreate) } + .disabled(!context.viewState.canCreateRoom) + } + + private func selectPrivate() { + context.send(viewAction: .selectPrivateRoom) + } + + private func selectPublic() { + context.send(viewAction: .selectPublicRoom) } private func deselect(_ user: UserProfile) { @@ -71,6 +133,8 @@ struct CreateRoom_Previews: PreviewProvider { static let viewModel = CreateRoomViewModel(selectedUsers: [.mockAlice, .mockBob, .mockCharlie]) static var previews: some View { - CreateRoomScreen(context: viewModel.context) + NavigationView { + CreateRoomScreen(context: viewModel.context) + } } }