Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmaccallum committed Aug 8, 2024
1 parent 30de7fc commit 6a40596
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 131 deletions.
1 change: 0 additions & 1 deletion dev/ParraDev/SampleTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Parra
import SwiftUI

struct SampleTab: View {
@Environment(\.parra) var parra
@Environment(\.parraTheme) private var parraTheme

var body: some View {
Expand Down
3 changes: 1 addition & 2 deletions dev/ParraDev/Settings Tab/Cells/ThemeCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Parra
import SwiftUI

struct ThemeCell: View {
@Environment(\.parraTheme) private var parraTheme
@Environment(\.parraAppearance) private var appearance
@Environment(\.parraPreferredAppearance) private var appearance

var body: some View {
Picker(
Expand Down
93 changes: 48 additions & 45 deletions dev/ParraDev/Settings Tab/Edit Profile Screen/EditProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,20 @@ import SwiftUI

struct EditProfileView: View {
@Environment(\.parra) private var parra
@Environment(\.parraTheme) private var parraTheme
@Environment(\.parraAuthState) private var parraAuthState
@Environment(\.parraTheme) private var parraTheme

@State private var firstName: String = ""
@State private var lastName: String = ""
@State private var displayName: String = ""
@State private var data = ProfileData()
@State private var isLoading = false
@State private var isShowingSuccess = false

var body: some View {
VStack {
Form {
Section {
HStack {
Text("First Name")
Spacer()
.frame(maxWidth: .infinity)
TextField(
"First Name",
text: $firstName,
prompt: Text("First Name")
)
.multilineTextAlignment(.trailing)
}

HStack {
Text("Last Name")
Spacer()
.frame(maxWidth: .infinity)
TextField(
"Last Name",
text: $lastName,
prompt: Text("Last Name")
)
.multilineTextAlignment(.trailing)
}

HStack {
Text("Display Name")
Spacer()
.frame(maxWidth: .infinity)
TextField(
"Display Name",
text: $displayName,
prompt: Text("Display Name")
)
.multilineTextAlignment(.trailing)
}
formField(named: "First Name", fieldData: $data.firstName)
formField(named: "Last Name", fieldData: $data.lastName)
formField(named: "Display Name", fieldData: $data.displayName)
}
}
.onSubmit(of: .text) {
Expand Down Expand Up @@ -96,9 +62,30 @@ struct EditProfileView: View {
.onAppear {
let userInfo = parraAuthState.user?.info

firstName = userInfo?.firstName ?? ""
lastName = userInfo?.lastName ?? ""
displayName = userInfo?.name ?? ""
data = ProfileData(
firstName: userInfo?.firstName,
lastName: userInfo?.lastName,
displayName: userInfo?.displayName
)
}
}

private func formField(
named name: String,
fieldData: Binding<String>
) -> some View {
HStack {
Text(name)

Spacer()
.frame(maxWidth: .infinity)

TextField(
name,
text: fieldData,
prompt: Text(name)
)
.multilineTextAlignment(.trailing)
}
}

Expand All @@ -117,9 +104,9 @@ struct EditProfileView: View {

do {
try await parra.user.updatePersonalInfo(
name: displayName.isEmpty ? nil : displayName,
firstName: firstName.isEmpty ? nil : firstName,
lastName: lastName.isEmpty ? nil : lastName
name: data.displayName,
firstName: data.firstName,
lastName: data.lastName
)
} catch {
success = false
Expand All @@ -139,6 +126,22 @@ struct EditProfileView: View {
}
}
}

private struct ProfileData {
init(
firstName: String? = nil,
lastName: String? = nil,
displayName: String? = nil
) {
self.firstName = firstName ?? ""
self.lastName = lastName ?? ""
self.displayName = displayName ?? ""
}

var firstName: String
var lastName: String
var displayName: String
}
}

#Preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct ParraAppearanceInstanceEnvironmentKey: EnvironmentKey {

@MainActor
public extension EnvironmentValues {
var parraAppearance: Binding<ParraAppearance> {
var parraPreferredAppearance: Binding<ParraAppearance> {
get {
self[ParraAppearanceInstanceEnvironmentKey.self]
}
Expand Down
4 changes: 2 additions & 2 deletions ios/Sources/Parra/Core/Managers/ModalScreenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class ModalScreenManager {
let modalViewController = UIHostingController(
rootView: container
.environment(\.parraTheme, ParraThemeManager.shared.current)
.environment(\.parraAppearance, ParraThemeManager.shared.preferredAppearanceBinding)
.environment(\.parraPreferredAppearance, ParraThemeManager.shared.preferredAppearanceBinding)
)
modalViewController.view.backgroundColor = .clear
modalViewController.modalPresentationStyle = .overCurrentContext
Expand Down Expand Up @@ -124,7 +124,7 @@ final class ModalScreenManager {
.padding(.top, 30)
}
.environment(\.parraTheme, ParraThemeManager.shared.current)
.environment(\.parraAppearance, ParraThemeManager.shared.preferredAppearanceBinding)
.environment(\.parraPreferredAppearance, ParraThemeManager.shared.preferredAppearanceBinding)

let modalViewController = UIHostingController(
rootView: rootView
Expand Down
2 changes: 1 addition & 1 deletion ios/Sources/Parra/Core/Parra App/ParraApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public struct ParraApp<
.environment(\.parra, Parra.default)
.environment(\.parraAuthState, authStateManager.current)
.environment(\.parraTheme, themeManager.current)
.environment(\.parraAppearance, themeManager.preferredAppearanceBinding)
.environment(\.parraPreferredAppearance, themeManager.preferredAppearanceBinding)
.environmentObject(launchScreenState)
.environmentObject(alertManager)
.environmentObject(parra.globalComponentFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public struct ParraAppPreview<Content, DelegateType>: View
.environment(\.parra, parra)
.environment(\.parraAuthState, authStateManager.current)
.environment(\.parraTheme, themeManager.current)
.environment(\.parraAppearance, themeManager.preferredAppearanceBinding)
.environment(\.parraPreferredAppearance, themeManager.preferredAppearanceBinding)
.environmentObject(alertManager)
.environmentObject(
LaunchScreenStateManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ParraViewPreview<Content>: View where Content: View {
.environment(\.parra, parra)
.environment(\.parraAuthState, authStateManager.current)
.environment(\.parraTheme, themeManager.current)
.environment(\.parraAppearance, themeManager.preferredAppearanceBinding)
.environment(\.parraPreferredAppearance, themeManager.preferredAppearanceBinding)
.environmentObject(alertManager)
.environmentObject(
LaunchScreenStateManager(
Expand Down
4 changes: 2 additions & 2 deletions templates/default/App/SampleTab.liquid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Parra
import SwiftUI

struct SampleTab: View {
@EnvironmentObject private var themeManager: ParraThemeManager
@Environment(\.parraTheme) private var parraTheme

var body: some View {
NavigationStack {
Expand All @@ -37,7 +37,7 @@ struct SampleTab: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.navigationTitle("App")
.background(themeManager.theme.palette.secondaryBackground)
.background(parraTheme.palette.secondaryBackground)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Parra
import SwiftUI

struct AccountView: View {
@EnvironmentObject private var parraAuthState: ParraAuthState
@Environment(\.parraAuthState) private var parraAuthState
@State private var isSigningIn = false

var body: some View {
let user = parraAuthState.current.user
let user = parraAuthState.user

List {
Section {
Expand Down Expand Up @@ -80,7 +80,7 @@ struct AccountView: View {
}

#Preview {
ParraAppPreview(authState: .authenticatedPreview) {
ParraAppPreview(authState: .undetermined) {
AccountView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI

struct DeleteAccountCell: View {
@Environment(\.parra) private var parra
@EnvironmentObject private var themeManager: ParraThemeManager
@Environment(\.parraTheme) private var parraTheme

var body: some View {
Button(action: {
Expand All @@ -24,7 +24,7 @@ struct DeleteAccountCell: View {
}
)
}
.foregroundStyle(themeManager.theme.palette.error)
.foregroundStyle(parraTheme.palette.error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import SwiftUI

struct LogoutCell: View {
@Environment(\.parra) private var parra
@Environment(\.parraTheme) private var parraTheme
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>

@EnvironmentObject private var themeManager: ParraThemeManager

@ViewBuilder
var body: some View {
Button(
Expand All @@ -33,7 +32,7 @@ struct LogoutCell: View {
}
)
}
.foregroundStyle(themeManager.theme.palette.error)
.foregroundStyle(parraTheme.palette.error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import SwiftUI
/// presented automatically.
struct ChangelogCell: View {
@Environment(\.parra) private var parra
@EnvironmentObject private var appInfo: ParraAppInfo
@Environment(\.parraAppInfo) private var parraAppInfo

@State private var isLoading = false
@State private var errorMessage: String?
@State private var changelogInfo: ParraChangelogInfo?

var showChangelog: Bool {
guard let newInstalledVersionInfo = appInfo.newInstalledVersionInfo else {
guard let newInstalledVersionInfo = parraAppInfo.newInstalledVersionInfo else {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import SwiftUI
import UIKit

public struct ProfileCell: View {
@EnvironmentObject private var parraAuthState: ParraAuthState
@Environment(\.parraAuthState) private var parraAuthState

public var body: some View {
switch parraAuthState.current {
switch parraAuthState {
case .anonymous, .authenticated:
AuthenticatedProfileInfoView()
default:
Expand All @@ -24,10 +24,10 @@ public struct ProfileCell: View {
}

struct IdentityLabels: View {
@EnvironmentObject private var parraAuthState: ParraAuthState
@Environment(\.parraAuthState) private var parraAuthState

var body: some View {
let user = parraAuthState.current.user
let user = parraAuthState.user
let identityNames = user?.info.identityNames ?? []

if identityNames.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import Parra
import SwiftUI

struct ReviewAppCell: View {
@EnvironmentObject private var parraAppInfo: ParraAppInfo
@Environment(\.parraAppInfo) private var parraAppInfo

var body: some View {
if let writeReviewUrl = parraAppInfo.application
.appStoreWriteReviewUrl
{
if let writeReviewUrl = parraAppInfo.application.appStoreWriteReviewUrl {
HStack {
Link(
destination: writeReviewUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Parra
import SwiftUI

struct ShareCell: View {
@EnvironmentObject private var parraAppInfo: ParraAppInfo
@Environment(\.parraAppInfo) private var parraAppInfo

var body: some View {
if let appStoreUrl = parraAppInfo.application.appStoreUrl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Parra
import SwiftUI

struct ThemeCell: View {
@EnvironmentObject private var themeManager: ParraThemeManager
@Environment(\.parraPreferredAppearance) private var appearance

var body: some View {
Picker(
selection: $themeManager.preferredAppearance,
selection: appearance,
content: {
ForEach(ParraAppearance.allCases) { option in
Text(option.description).tag(option)
Expand Down
Loading

0 comments on commit 6a40596

Please sign in to comment.