-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out view for a single project in list and add logic to change …
…the selected default payer
- Loading branch information
1 parent
0a22072
commit b2c0783
Showing
4 changed files
with
89 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ProjectListEntry.swift | ||
// PayForMe | ||
// | ||
// Created by Max Tharr on 08.02.23. | ||
// Copyright © 2023 Mayflower GmbH. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ProjectListEntry: View { | ||
let project: Project | ||
let manager = ProjectManager.shared | ||
let currentProject: Project | ||
|
||
@Binding var shareProject: Project? | ||
|
||
@State var edit = false | ||
@State var me = 0 | ||
|
||
var body: some View { | ||
Button(action: { | ||
self.manager.setCurrentProject(project) | ||
}, label: { | ||
VStack { | ||
HStack { | ||
VStack(alignment: .leading) { | ||
Text(project.name) | ||
Text(project.backend == .cospend ? "Cospend" : "iHateMoney").font(.caption).foregroundColor(Color.gray) | ||
} | ||
Spacer() | ||
if project == currentProject { | ||
Button(action: { | ||
self.edit.toggle() | ||
}, label: { | ||
Image(systemName: "pencil") | ||
}) | ||
.padding(.trailing, 5) | ||
} | ||
if project.backend == .cospend { | ||
Button(action: { | ||
self.shareProject = project | ||
}, label: { | ||
HStack(spacing: 5) { | ||
Image(systemName: "square.and.arrow.up") | ||
Image(systemName: "qrcode") | ||
} | ||
}) | ||
} | ||
} | ||
.foregroundColor(self.currentProject == project ? .accentColor : .primary) | ||
} | ||
if edit { | ||
WhoPaidView(members: Array(project.members.values), selectedPayer: self.$me) | ||
.animation(.spring(), value: edit) | ||
} | ||
}) | ||
.onAppear { | ||
me = project.me ?? 0 | ||
} | ||
.onChange(of: me) { newValue in | ||
project.me = newValue | ||
manager.updateProject(project: project) | ||
edit.toggle() | ||
} | ||
} | ||
} | ||
|
||
struct ProjectListEntry_Previews: PreviewProvider { | ||
static var previews: some View { | ||
previewProject.members = previewManyPersons | ||
return List { | ||
ProjectListEntry(project: previewProject, currentProject: previewProject, shareProject: .constant(nil)) | ||
} | ||
} | ||
} |