Skip to content

Commit

Permalink
Fixed an issue in the demo app when switching users (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski authored Mar 7, 2024
1 parent 9fd829f commit 2a02b9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DemoAppSwiftUI/CustomChannelHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier {
message: Text("Are you sure you want to sign out?"),
primaryButton: .destructive(Text("Sign out")) {
withAnimation {
chatClient.disconnect {
chatClient.logout {
UnsecureRepository.shared.removeCurrentUser()
DispatchQueue.main.async {
AppState.shared.userState = .notLoggedIn
Expand Down
18 changes: 14 additions & 4 deletions DemoAppSwiftUI/DemoAppSwiftUIApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ struct DemoAppSwiftUIApp: App {
@ObservedObject var appState = AppState.shared
@ObservedObject var notificationsHandler = NotificationsHandler.shared

@State var channelListController: ChatChannelListController?

var channelListController: ChatChannelListController? {
appState.channelListController
}

var body: some Scene {
WindowGroup {
switch appState.userState {
Expand Down Expand Up @@ -51,7 +53,7 @@ struct DemoAppSwiftUIApp: App {
.init(key: .updatedAt)
]
)
channelListController = chatClient.channelListController(query: channelListQuery)
appState.channelListController = chatClient.channelListController(query: channelListQuery)
}
notificationsHandler.setupRemoteNotifications()
}
Expand All @@ -61,7 +63,15 @@ struct DemoAppSwiftUIApp: App {

class AppState: ObservableObject {

@Published var userState: UserState = .launchAnimation
@Published var userState: UserState = .launchAnimation {
willSet {
if newValue == .notLoggedIn && userState == .loggedIn {
channelListController = nil
}
}
}

var channelListController: ChatChannelListController?

static let shared = AppState()

Expand Down

0 comments on commit 2a02b9b

Please sign in to comment.