Skip to content

Commit 2a02b9b

Browse files
Fixed an issue in the demo app when switching users (#448)
1 parent 9fd829f commit 2a02b9b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

DemoAppSwiftUI/CustomChannelHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier {
7979
message: Text("Are you sure you want to sign out?"),
8080
primaryButton: .destructive(Text("Sign out")) {
8181
withAnimation {
82-
chatClient.disconnect {
82+
chatClient.logout {
8383
UnsecureRepository.shared.removeCurrentUser()
8484
DispatchQueue.main.async {
8585
AppState.shared.userState = .notLoggedIn

DemoAppSwiftUI/DemoAppSwiftUIApp.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ struct DemoAppSwiftUIApp: App {
1515
@ObservedObject var appState = AppState.shared
1616
@ObservedObject var notificationsHandler = NotificationsHandler.shared
1717

18-
@State var channelListController: ChatChannelListController?
19-
18+
var channelListController: ChatChannelListController? {
19+
appState.channelListController
20+
}
21+
2022
var body: some Scene {
2123
WindowGroup {
2224
switch appState.userState {
@@ -51,7 +53,7 @@ struct DemoAppSwiftUIApp: App {
5153
.init(key: .updatedAt)
5254
]
5355
)
54-
channelListController = chatClient.channelListController(query: channelListQuery)
56+
appState.channelListController = chatClient.channelListController(query: channelListQuery)
5557
}
5658
notificationsHandler.setupRemoteNotifications()
5759
}
@@ -61,7 +63,15 @@ struct DemoAppSwiftUIApp: App {
6163

6264
class AppState: ObservableObject {
6365

64-
@Published var userState: UserState = .launchAnimation
66+
@Published var userState: UserState = .launchAnimation {
67+
willSet {
68+
if newValue == .notLoggedIn && userState == .loggedIn {
69+
channelListController = nil
70+
}
71+
}
72+
}
73+
74+
var channelListController: ChatChannelListController?
6575

6676
static let shared = AppState()
6777

0 commit comments

Comments
 (0)