Check for nil context on message views

This commit is contained in:
Garth Vander Houwen 2023-09-25 09:44:57 -07:00
parent 80afbcacd3
commit 0210f0e760
5 changed files with 30 additions and 18 deletions

View file

@ -123,6 +123,11 @@ struct ChannelList: View {
Text("delete")
}
}
.onAppear {
if self.bleManager.context == nil {
self.bleManager.context = context
}
}
}
}
.padding([.top, .bottom])

View file

@ -259,7 +259,9 @@ struct ChannelMessageList: View {
.padding([.top])
.scrollDismissesKeyboard(.immediately)
.onAppear(perform: {
self.bleManager.context = context
if self.bleManager.context == nil {
self.bleManager.context = context
}
if channel.allPrivateMessages.count > 0 {
scrollView.scrollTo(channel.allPrivateMessages.last!.messageId)
}
@ -409,6 +411,7 @@ struct ChannelMessageList: View {
}) {
Image(systemName: "arrow.up.circle.fill").font(.largeTitle).foregroundColor(.accentColor)
}
}
.padding(.all, 15)
}

View file

@ -63,7 +63,9 @@ struct Messages: View {
.navigationBarTitleDisplayMode(.large)
.navigationBarItems(leading: MeshtasticLogo())
.onAppear {
self.bleManager.context = context
if self.bleManager.context == nil {
self.bleManager.context = context
}
if UserDefaults.preferredPeripheralId.count > 0 {
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "NodeInfoEntity")
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(bleManager.connectedPeripheral?.num ?? -1))

View file

@ -143,19 +143,19 @@ struct UserList: View {
}
}
}
.alert(
"Trace Route Sent",
isPresented: $isPresentingTraceRouteSentAlert
) {
Button("OK", role: .cancel) { }
} message: {
Text("This could take a while, response will appear in the mesh log.")
}
.confirmationDialog(
"This conversation will be deleted.",
isPresented: $isPresentingDeleteUserMessagesConfirm,
titleVisibility: .visible
) {
.alert(
"Trace Route Sent",
isPresented: $isPresentingTraceRouteSentAlert
) {
Button("OK", role: .cancel) { }
} message: {
Text("This could take a while, response will appear in the mesh log.")
}
.confirmationDialog(
"This conversation will be deleted.",
isPresented: $isPresentingDeleteUserMessagesConfirm,
titleVisibility: .visible
) {
Button(role: .destructive) {
deleteUserMessages(user: userSelection!, context: context)
context.refresh(node!.user!, mergeChanges: true)

View file

@ -237,12 +237,14 @@ struct UserMessageList: View {
}
.padding([.top])
.scrollDismissesKeyboard(.immediately)
.onAppear(perform: {
self.bleManager.context = context
.onAppear {
if self.bleManager.context == nil {
self.bleManager.context = context
}
if user.messageList.count > 0 {
scrollView.scrollTo(user.messageList.last!.messageId)
}
})
}
.onChange(of: user.messageList, perform: { _ in
if user.messageList.count > 0 {
scrollView.scrollTo(user.messageList.last!.messageId)