mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
work on text input for room creation
This commit is contained in:
@@ -22,9 +22,21 @@ enum CreateRoomViewModelAction {
|
|||||||
|
|
||||||
struct CreateRoomViewState: BindableState {
|
struct CreateRoomViewState: BindableState {
|
||||||
var selectedUsers: [UserProfile]
|
var selectedUsers: [UserProfile]
|
||||||
|
var bindings = CreateRoomViewStateBindings()
|
||||||
|
|
||||||
|
var canCreateRoom: Bool {
|
||||||
|
!bindings.roomName.isEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CreateRoomViewStateBindings {
|
||||||
|
var roomName = ""
|
||||||
|
var roomTopic = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CreateRoomViewAction {
|
enum CreateRoomViewAction {
|
||||||
case createRoom
|
case createRoom
|
||||||
|
case selectPrivateRoom
|
||||||
|
case selectPublicRoom
|
||||||
case deselectUser(UserProfile)
|
case deselectUser(UserProfile)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
|||||||
actionsSubject.send(.createRoom)
|
actionsSubject.send(.createRoom)
|
||||||
case .deselectUser(let user):
|
case .deselectUser(let user):
|
||||||
state.selectedUsers.removeAll(where: { $0.userID == user.userID })
|
state.selectedUsers.removeAll(where: { $0.userID == user.userID })
|
||||||
|
case .selectPrivateRoom:
|
||||||
|
break
|
||||||
|
case .selectPublicRoom:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,23 +20,60 @@ struct CreateRoomScreen: View {
|
|||||||
@ObservedObject var context: CreateRoomViewModel.Context
|
@ObservedObject var context: CreateRoomViewModel.Context
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
mainContent
|
||||||
mainContent
|
.scrollContentBackground(.hidden)
|
||||||
}
|
.background(Color.element.formBackground.ignoresSafeArea())
|
||||||
.scrollContentBackground(.hidden)
|
.navigationTitle(L10n.screenCreateRoomTitle)
|
||||||
.background(Color.element.formBackground.ignoresSafeArea())
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.navigationTitle(L10n.actionCreateARoom)
|
.toolbar {
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
.toolbar {
|
createButton
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
}
|
||||||
createButton
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The main content of the view to be shown in a scroll view.
|
/// The main content of the view to be shown in a scroll view.
|
||||||
var mainContent: some 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
|
@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 {
|
private var createButton: some View {
|
||||||
Button { context.send(viewAction: .createRoom) } label: {
|
Button { context.send(viewAction: .createRoom) } label: {
|
||||||
Text(L10n.actionCreate)
|
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) {
|
private func deselect(_ user: UserProfile) {
|
||||||
@@ -71,6 +133,8 @@ struct CreateRoom_Previews: PreviewProvider {
|
|||||||
static let viewModel = CreateRoomViewModel(selectedUsers: [.mockAlice, .mockBob, .mockCharlie])
|
static let viewModel = CreateRoomViewModel(selectedUsers: [.mockAlice, .mockBob, .mockCharlie])
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CreateRoomScreen(context: viewModel.context)
|
NavigationView {
|
||||||
|
CreateRoomScreen(context: viewModel.context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user