Skip to content

Commit

Permalink
fix dismissal issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmontz committed Jan 22, 2025
1 parent 32ff1fd commit 1e3350d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions Nos/Views/Lists/AuthorListManageUsersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ struct AuthorListManageUsersView: View {

private var mode: Mode

/// An action that runs after successfully saving an ``AuthorList``.
///
/// Leaving the value nil will cause the Environment's `dismiss()` to be called, which may appear
/// as a modal dismissal or a navigational pop depending on the presentation context.
private let onSave: (() -> Void)?

init(list: AuthorList) {
mode = .update(list: list)
_authors = State(initialValue: list.allAuthors)
onSave = nil
}

init(title: String, description: String?) {
init(title: String, description: String?, onSave: (() -> Void)?) {
mode = .create(title: title, description: description)
_authors = State(initialValue: [])
self.onSave = onSave
}

var body: some View {
Expand Down Expand Up @@ -139,7 +147,12 @@ struct AuthorListManageUsersView: View {
Task {
do {
try await relayService.publishToAll(event: event, signingKey: keyPair, context: viewContext)
dismiss()

if let onSave {
onSave()
} else {
dismiss()
}
} catch {
Log.error("Error when creating list: \(error.localizedDescription)")
}
Expand Down
1 change: 1 addition & 0 deletions Nos/Views/Lists/AuthorListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct AuthorListsView: View {
Text(list.rowDescription)
.foregroundStyle(Color.secondaryTxt)
.font(.footnote)
.lineLimit(1)
}

Spacer()
Expand Down
4 changes: 3 additions & 1 deletion Nos/Views/Lists/EditAuthorListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ struct EditAuthorListView: View {
}
}
.navigationDestination(isPresented: $showingManageUsers) {
AuthorListManageUsersView(title: title, description: description)
AuthorListManageUsersView(title: title, description: description) {
dismiss()
}
}
.onAppear {
title = list?.title ?? ""
Expand Down

0 comments on commit 1e3350d

Please sign in to comment.