-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Application Passwords entry to user details #23834
base: trunk
Are you sure you want to change the base?
Changes from 4 commits
133bfc8
af1180d
3b81fd1
5430f25
db61f33
1b0daa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,34 +5,41 @@ import WordPressAPI | |
|
||
struct ApplicationTokenListView: View { | ||
|
||
@ObservedObject | ||
@StateObject | ||
private var viewModel: ApplicationTokenListViewModel | ||
|
||
fileprivate init(tokens: [ApplicationTokenItem]) { | ||
let dataProvider = StaticTokenProvider(tokens: .success(tokens)) | ||
self.init(viewModel: ApplicationTokenListViewModel(dataProvider: dataProvider)) | ||
self.init(dataProvider: dataProvider) | ||
} | ||
|
||
fileprivate init(error: Error) { | ||
let dataProvider = StaticTokenProvider(tokens: .failure(error)) | ||
self.init(viewModel: ApplicationTokenListViewModel(dataProvider: dataProvider)) | ||
self.init(dataProvider: dataProvider) | ||
} | ||
|
||
init(viewModel: ApplicationTokenListViewModel) { | ||
self.viewModel = viewModel | ||
init(dataProvider: ApplicationTokenListDataProvider) { | ||
_viewModel = .init(wrappedValue: ApplicationTokenListViewModel(dataProvider: dataProvider)) | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
if viewModel.isLoadingData { | ||
ProgressView() | ||
} else if let error = viewModel.errorMessage { | ||
EmptyStateView(Self.errorTitle, systemImage: "exclamationmark.triangle", description: error) | ||
} else { | ||
List(viewModel.applicationTokens) { token in | ||
ApplicationTokenListItemView(item: token) | ||
ZStack { | ||
Color(.systemGroupedBackground) | ||
.ignoresSafeArea() | ||
|
||
Group { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in 1b0daa0 |
||
VStack { | ||
if viewModel.isLoadingData { | ||
ProgressView() | ||
} else if let error = viewModel.errorMessage { | ||
EmptyStateView(Self.errorTitle, systemImage: "exclamationmark.triangle", description: error) | ||
} else { | ||
List(viewModel.applicationTokens) { token in | ||
ApplicationTokenListItemView(item: token) | ||
} | ||
.listStyle(.insetGrouped) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit)I'd suggest using a |
||
} | ||
} | ||
.listStyle(.plain) | ||
} | ||
} | ||
.navigationTitle(Self.title) | ||
|
@@ -47,6 +54,7 @@ struct ApplicationTokenListView: View { | |
} | ||
} | ||
|
||
@MainActor | ||
class ApplicationTokenListViewModel: ObservableObject { | ||
|
||
@Published | ||
|
@@ -58,14 +66,13 @@ class ApplicationTokenListViewModel: ObservableObject { | |
@Published | ||
private(set) var applicationTokens: [ApplicationTokenItem] | ||
|
||
private let dataProvider: ApplicationTokenListDataProvider! | ||
let dataProvider: ApplicationTokenListDataProvider! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need a force unwrap? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Addressed in db61f33 |
||
|
||
init(dataProvider: ApplicationTokenListDataProvider) { | ||
self.dataProvider = dataProvider | ||
self.applicationTokens = [] | ||
} | ||
|
||
@MainActor | ||
func fetchTokens() async { | ||
isLoadingData = true | ||
defer { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import XCTest | |
|
||
@testable import WordPress | ||
|
||
@MainActor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actors support in XCTest has been a bit shaky. I'd suggest writing all new tests in swift-testing. It's pretty similar to XCTest https://developer.apple.com/documentation/testing/migratingfromxctest |
||
class ApplicationPasswordsViewModelTests: XCTestCase { | ||
|
||
func testOrder() async throws { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) this should not be needed as long as you are displaying the
List
at the bottom. TheProgressView
could be shown as an.overlay
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get it to work. Do you mind showing me an example?