mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-29 05:31:59 +02:00
Update
This commit is contained in:
66
Other Projects/SwiftUI + Redux/SwiftUIDemo/views/users/UsersListView.swift
Executable file
66
Other Projects/SwiftUI + Redux/SwiftUIDemo/views/users/UsersListView.swift
Executable file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// SwiftUIDemo
|
||||
//
|
||||
// Created by Thomas Ricouard on 04/06/2019.
|
||||
// Copyright © 2019 Thomas Ricouarf. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UsersListView : View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List {
|
||||
Section {
|
||||
Button(action: addUser) {
|
||||
Text("Add user")
|
||||
}
|
||||
Button(action: targetUpdate) {
|
||||
Text("Update first")
|
||||
}
|
||||
}
|
||||
Section {
|
||||
ForEach(state.usersState.users) {user in
|
||||
NavigationButton(destination: UserDetailView(userId: user.id)) {
|
||||
UserRow(user: user)
|
||||
}
|
||||
}
|
||||
.onDelete(perform: delete)
|
||||
.onMove(perform: move)
|
||||
}
|
||||
}
|
||||
.listStyle(.grouped)
|
||||
.navigationBarTitle(Text("Users (\(state.usersState.users.count))"))
|
||||
.navigationBarItems(trailing: EditButton())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func addUser() {
|
||||
state.dispatch(action: UserActions.addUser)
|
||||
|
||||
}
|
||||
|
||||
func targetUpdate() {
|
||||
state.dispatch(action: UserActions.testEditFirstUser)
|
||||
}
|
||||
|
||||
func delete(at offset: IndexSet) {
|
||||
state.dispatch(action: UserActions.deleteUser(index: offset.first!))
|
||||
}
|
||||
|
||||
func move(from: IndexSet, to: Int) {
|
||||
state.dispatch(action: UserActions.move(from: from.first!, to: to))
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct ContentView_Previews : PreviewProvider {
|
||||
static var previews: some View {
|
||||
UsersListView().environmentObject(sampleStore)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user