mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Refactor logout view out of AccountView
This commit is contained in:
parent
0d37f9f3c2
commit
4de5293345
36
Shared/Account/AccountLogoutView.swift
Normal file
36
Shared/Account/AccountLogoutView.swift
Normal file
@ -0,0 +1,36 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AccountLogoutView: View {
|
||||
@Binding var accountModel: AccountModel
|
||||
@Binding var isLoggedIn: Bool
|
||||
@Binding var isLoggingIn: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
VStack {
|
||||
Text("Logged in as \(accountModel.username ?? "UNKNOWN")")
|
||||
Text("on \(accountModel.server ?? "UNKNOWN")")
|
||||
}
|
||||
Spacer()
|
||||
Button(action: logoutHandler, label: {
|
||||
Text("Logout")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func logoutHandler() {
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
}
|
||||
}
|
||||
|
||||
struct AccountLogoutView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AccountLogoutView(
|
||||
accountModel: .constant(AccountModel()),
|
||||
isLoggedIn: .constant(true),
|
||||
isLoggingIn: .constant(false)
|
||||
)
|
||||
}
|
||||
}
|
@ -13,15 +13,7 @@ struct AccountView: View {
|
||||
|
||||
var body: some View {
|
||||
if isLoggedIn {
|
||||
VStack {
|
||||
HStack {
|
||||
Text("Logged in as \(accountModel.username ?? "UNKNOWN") on \(accountModel.server ?? "UNKNOWN")")
|
||||
}
|
||||
Spacer()
|
||||
Button(action: logoutHandler, label: {
|
||||
Text("Logout")
|
||||
})
|
||||
}
|
||||
AccountLogoutView(accountModel: $accountModel, isLoggedIn: $isLoggedIn, isLoggingIn: $isLoggingIn)
|
||||
} else {
|
||||
VStack {
|
||||
HStack {
|
||||
@ -92,10 +84,6 @@ The server could not be found. Please check that you've entered the information
|
||||
}
|
||||
}
|
||||
|
||||
func logoutHandler() {
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
}
|
||||
}
|
||||
struct AccountLogin_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
@ -11,6 +11,8 @@
|
||||
17120DA224E1985C002B9F6C /* AccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388B24DDC83F00DEFF9A /* AccountModel.swift */; };
|
||||
17120DA324E19A42002B9F6C /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5389124DDED0000DEFF9A /* PreferencesView.swift */; };
|
||||
17120DA724E19D11002B9F6C /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DA424E19CBF002B9F6C /* SettingsView.swift */; };
|
||||
17120DA924E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DA824E1B2F5002B9F6C /* AccountLogoutView.swift */; };
|
||||
17120DAA24E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DA824E1B2F5002B9F6C /* AccountLogoutView.swift */; };
|
||||
171BFDF724D49FD400888236 /* PostCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF624D49FD400888236 /* PostCollection.swift */; };
|
||||
171BFDF824D49FD400888236 /* PostCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF624D49FD400888236 /* PostCollection.swift */; };
|
||||
171BFDFA24D4AF8300888236 /* CollectionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF924D4AF8300888236 /* CollectionListView.swift */; };
|
||||
@ -65,6 +67,7 @@
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
17120DA424E19CBF002B9F6C /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
17120DA824E1B2F5002B9F6C /* AccountLogoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLogoutView.swift; sourceTree = "<group>"; };
|
||||
171BFDF624D49FD400888236 /* PostCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostCollection.swift; sourceTree = "<group>"; };
|
||||
171BFDF924D4AF8300888236 /* CollectionListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionListView.swift; sourceTree = "<group>"; };
|
||||
1756AE6A24CB1E4B00FD7257 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
|
||||
@ -268,6 +271,7 @@
|
||||
children = (
|
||||
17A5388B24DDC83F00DEFF9A /* AccountModel.swift */,
|
||||
17A5388D24DDEC7400DEFF9A /* AccountView.swift */,
|
||||
17120DA824E1B2F5002B9F6C /* AccountLogoutView.swift */,
|
||||
);
|
||||
path = Account;
|
||||
sourceTree = "<group>";
|
||||
@ -501,6 +505,7 @@
|
||||
files = (
|
||||
17DF32AC24C87D3500BCE2E3 /* ContentView.swift in Sources */,
|
||||
1756AE8124CB844500FD7257 /* View+Keyboard.swift in Sources */,
|
||||
17120DA924E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */,
|
||||
171BFDFA24D4AF8300888236 /* CollectionListView.swift in Sources */,
|
||||
1756AE7724CB2EDD00FD7257 /* PostEditor.swift in Sources */,
|
||||
17DF32D524C8CA3400BCE2E3 /* PostStatusBadge.swift in Sources */,
|
||||
@ -526,6 +531,7 @@
|
||||
17DF32AD24C87D3500BCE2E3 /* ContentView.swift in Sources */,
|
||||
1765F62B24E18EA200C9EBF0 /* SidebarView.swift in Sources */,
|
||||
1756AE7824CB2EDD00FD7257 /* PostEditor.swift in Sources */,
|
||||
17120DAA24E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */,
|
||||
17DF32D624C8CA3400BCE2E3 /* PostStatusBadge.swift in Sources */,
|
||||
1756AE7B24CB65DF00FD7257 /* PostList.swift in Sources */,
|
||||
171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */,
|
||||
|
Loading…
Reference in New Issue
Block a user