Skip to content

Commit

Permalink
add users
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Jun 26, 2019
1 parent 48e890f commit e81217a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions SwiftUI-Todo-Redux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
841655B622C1E2CF007DF30E /* KeyboardObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841655B422C1E2CF007DF30E /* KeyboardObserver.swift */; };
841655B722C1E2CF007DF30E /* FormButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841655B522C1E2CF007DF30E /* FormButtons.swift */; };
841655B922C28590007DF30E /* TaskCreate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841655B822C28590007DF30E /* TaskCreate.swift */; };
841655BB22C301AF007DF30E /* UserCreate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841655BA22C301AF007DF30E /* UserCreate.swift */; };
843B2B4B22BE9B1D001E89B6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 843B2B4A22BE9B1D001E89B6 /* AppDelegate.swift */; };
843B2B4D22BE9B1D001E89B6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 843B2B4C22BE9B1D001E89B6 /* SceneDelegate.swift */; };
843B2B5122BE9B1F001E89B6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 843B2B5022BE9B1F001E89B6 /* Assets.xcassets */; };
Expand Down Expand Up @@ -69,6 +70,7 @@
841655B422C1E2CF007DF30E /* KeyboardObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardObserver.swift; sourceTree = "<group>"; };
841655B522C1E2CF007DF30E /* FormButtons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormButtons.swift; sourceTree = "<group>"; };
841655B822C28590007DF30E /* TaskCreate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskCreate.swift; sourceTree = "<group>"; };
841655BA22C301AF007DF30E /* UserCreate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserCreate.swift; sourceTree = "<group>"; };
843B2B4722BE9B1D001E89B6 /* SwiftUI-Todo-Redux.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-Todo-Redux.app"; sourceTree = BUILT_PRODUCTS_DIR; };
843B2B4A22BE9B1D001E89B6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
843B2B4C22BE9B1D001E89B6 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -137,6 +139,7 @@
children = (
8416559422BFF7C6007DF30E /* UsersList.swift */,
8416559322BFF7C5007DF30E /* UserDetail.swift */,
841655BA22C301AF007DF30E /* UserCreate.swift */,
8416559122BFF7C5007DF30E /* UsersRow.swift */,
);
path = users;
Expand Down Expand Up @@ -387,6 +390,7 @@
843B2B8222BF1EB7001E89B6 /* UserActions.swift in Sources */,
8416559B22BFF7C6007DF30E /* TasksList.swift in Sources */,
841655B722C1E2CF007DF30E /* FormButtons.swift in Sources */,
841655BB22C301AF007DF30E /* UserCreate.swift in Sources */,
8416559A22BFF7C6007DF30E /* UsersList.swift in Sources */,
841655B622C1E2CF007DF30E /* KeyboardObserver.swift in Sources */,
843B2B6B22BF1E35001E89B6 /* User.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions SwiftUI-Todo-Redux/models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI

struct User: Equatable, Hashable, Codable, Identifiable {
let id: Int
let name: String
let username: String
var name: String
var username: String
let imageName = "person"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ struct UserStateReducer: Reducer {

if let action = action as? UserActions.UserAddResponse {
let id = action.id
let user = action.response.user
state.users.append(user)
let users = action.response.users
state.users.append(contentsOf: users)
}

if let action = action as? UserActions.UserDeleteResponse {
Expand All @@ -32,8 +32,8 @@ struct UserStateReducer: Reducer {

if let action = action as? UserActions.EditUserResponse {
let id = action.id
let user = action.response.user
state.users[id] = user
let users = action.response.users
state.users[id] = users[0]
}

if let action = action as? UserActions.TestEditResponse {
Expand Down
2 changes: 1 addition & 1 deletion SwiftUI-Todo-Redux/views/tasks/TaskCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct TaskCreate: View {
/// Dismiss Modal presentation, save updated task if valid
func doSave() {
isEditing = false
self.store.dispatch(action: TaskActions.Notification(show: true, message: "New Task Created!"))
store.dispatch(action: TaskActions.Notification(show: true, message: "New Task Created!"))
}

var body: some View {
Expand Down
2 changes: 1 addition & 1 deletion SwiftUI-Todo-Redux/views/tasks/TaskDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct TaskDetail: View {
}

var body: some View {
VStack(alignment: .top, spacing: 20) {
ZStack(alignment: .top) {
HStack {
if self.mode?.value == .active {
Button(action: {
Expand Down
6 changes: 3 additions & 3 deletions SwiftUI-Todo-Redux/views/users/UserCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ struct UserCreate: View {
/// Dismiss Modal presentation, save updated user if valid
func doSave() {
isEditing = false
self.store.dispatch(action: TaskActions.Notification(show: true, message: "New User Created!"))
store.dispatch(action: TaskActions.Notification(show: true, message: "New User Created!"))
}

var body: some View {
NavigationView {
Form {
Section(header: Text("User Information")) {
VStack(alignment: .leading) {
FieldSetText(textItem: $user.name, label: "NAME", placeHolder: "User full name")
FieldSetText(textItem: $user.username, label: "USERNAME", placeHolder: "User nickname")
FieldSetText(textItem: $user.name, label: "NAME", placeHolder: "User full name")
FieldSetText(textItem: $user.username, label: "USERNAME", placeHolder: "User nickname")
}
.padding(.vertical, 20)
.listRowInsets(EdgeInsets())
Expand Down
7 changes: 3 additions & 4 deletions SwiftUI-Todo-Redux/views/users/UserDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import SwiftUI

struct UserDetail: View {
// Based on "in-line" detail editing structure proposed by Apple
/// https://developer.apple.com/tutorials/swiftui/working-with-ui-controls
// Based on "in-line" detail editing structure proposed by Apple
/// https://developer.apple.com/tutorials/swiftui/working-with-ui-controls

@EnvironmentObject var store: AppState

Expand Down Expand Up @@ -47,7 +47,7 @@ struct UserDetail: View {
}

var body: some View {
VStack(alignment: .top, spacing: 20) {
ZStack(alignment: .top) {
HStack {
if self.mode?.value == .active {
Button(action: {
Expand Down Expand Up @@ -76,7 +76,6 @@ struct UserDetail: View {
}
}


#if DEBUG
struct UserDetail_Previews: PreviewProvider {
static var previews: some View {
Expand Down
1 change: 1 addition & 0 deletions SwiftUI-Todo-Redux/views/users/UsersList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

struct UsersList: View {
@EnvironmentObject var store: AppState
@State var showEdit = false

func loadPage() {
print("loadPage")
Expand Down
2 changes: 1 addition & 1 deletion SwiftUI-Todo-ReduxTests/SwiftUI_Todo_ReduxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SwiftUI_Todo_ReduxTests: XCTestCase {
}
}

func testEncodingUser() {
func testEncodingUser() {
let json = #"""
{ "id": 1,
"users":
Expand Down

0 comments on commit e81217a

Please sign in to comment.