Skip to content

Commit

Permalink
add login guest
Browse files Browse the repository at this point in the history
  • Loading branch information
xqsadness committed Sep 16, 2023
1 parent 35c821e commit d9a6333
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 33 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,4 @@
uuid = "40680EE2-D096-4625-B9E1-B90CF7A46FFB"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "EE60291D-9C31-412C-AE2A-E96E3A83A2C6"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DefaultProject/ViewModel/SpeechRecognizer.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "101"
endingLineNumber = "101"
landmarkName = "transcribe()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
4 changes: 1 addition & 3 deletions DefaultProject/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import SwiftUI

struct ContentView: View {
@AppStorage("USERNAME") var USERNAME: String = ""

var body: some View {
if User.shared.userUID != "" {
if User.shared.userUID != ""{
HomeView()
} else {
LoginDefaultView()
Expand Down
9 changes: 8 additions & 1 deletion DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SwiftUI

enum Page: String, Identifiable{
case NONE, mathView, listeningView, historyView, listenAndRepeat, speechToTextView, colorView, chooseLanguageView, writingView, surroundingObjectView
case NONE, mathView, listeningView, historyView, listenAndRepeat, speechToTextView, colorView, chooseLanguageView, writingView, surroundingObjectView, createUsernameView, homeView
var id: String{
return self.rawValue
}
Expand Down Expand Up @@ -94,6 +94,13 @@ class Coordinator: ObservableObject{
case .surroundingObjectView:
SurroundingObjectView()
.environmentObject(Coordinator.shared)
case .createUsernameView:
CreateUsernameView()
.environmentObject(Coordinator.shared)
case .homeView:
HomeView()
.environmentObject(Coordinator.shared)
.navigationBarBackButtonHidden(true)
default:
EmptyView()
}
Expand Down
10 changes: 10 additions & 0 deletions DefaultProject/DEFAULT_SOURCE/DefaultView/LoginDefaultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
struct LoginDefaultView: View {
@StateObject var appController = APPCONTROLLER.shared
@StateObject var authManagerViewModel = AuthManagerViewModel.shared
@EnvironmentObject var coordinator: Coordinator

var body: some View {
VStack{
Expand Down Expand Up @@ -91,6 +92,15 @@ struct LoginDefaultView: View {
}
.padding(.top)
.hAlign(.leading)

styledText(text: "Or continue with guest", foregroundColor: .blue, font: .regular(size: 17))
.onTapGesture {
withAnimation {
coordinator.push(.createUsernameView)
}
}
.padding(.top)
.hAlign(.center)
}
.padding()
.background(Color.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AuthManagerViewModel: ObservableObject {
User.shared.userUID = authResult.user.uid
User.shared.userEmail = authResult.user.email ?? "nil"
LocalNotification.shared.message("Login sucsess", .success)
Coordinator.shared.push(.homeView)
}
} catch {
await setError(error)
Expand Down
4 changes: 3 additions & 1 deletion DefaultProject/View/ChooseLanguageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI
import CrowdinSDK

struct ChooseLanguageView: SwiftUI.View {
@AppStorage("USERNAME") var USERNAME: String = ""
@AppStorage("Language") var language: String = "en"
@EnvironmentObject var coordinator: Coordinator
@State var languagesList: [Language] = [.english(.us), .vietnamese, .french, .russian, .japanese]
Expand Down Expand Up @@ -75,8 +76,9 @@ struct ChooseLanguageView: SwiftUI.View {
.contentShape(Rectangle())
.animation(.easeInOut, value: language)
.onTapGesture {
User.shared.userEmail = ""
AuthManagerViewModel.shared.logoutUser()
coordinator.pop()
coordinator.popToRoot()
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions DefaultProject/View/CreateUsernameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import SwiftUI

struct CreateUsernameView: View {
@AppStorage("Language") var language: String = "en"
@AppStorage("USERNAME") var USERNAME: String = ""
@State var name: String = ""
@EnvironmentObject var coordinator: Coordinator

var body: some View {
VStack{
VStack{
Expand Down Expand Up @@ -49,19 +50,24 @@ struct CreateUsernameView: View {
)
.background(Color.text)

Button {
USERNAME = name
} label: {
VStack {
Text("START".cw_localized)
.font(.bold(size: 18))
.foregroundColor(Color.text)
.padding(.vertical, 10)
.hAlign(.center)
.frame(height: 50)
.cornerRadius(6)
.background(Color.blue)
.contentShape(Rectangle())
.onTapGesture {
User.shared.userEmail = name
if User.shared.userEmail != "" {
coordinator.push(.homeView)
}
}
.disabled(name.isEmpty || name.count < 2)
}
.hAlign(.center)
.frame(height: 50)
.cornerRadius(6)
.background(Color.blue)
.disabled(name.isEmpty || name.count < 2)
}
.padding()
.background(Color.text)
Expand Down
2 changes: 1 addition & 1 deletion DefaultProject/View/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct HomeView: View {
var body: some View {
VStack {
HStack{
Text("\("Hi".cw_localized), " + (User.shared.userEmail.extractName() ?? "nil"))
Text("\("Hi".cw_localized), " + (User.shared.userEmail.extractName() ?? User.shared.userEmail))
.font(.bold(size: 20))
.foregroundColor(Color.background)
.hAlign(.leading)
Expand Down

0 comments on commit d9a6333

Please sign in to comment.