Skip to content

Commit

Permalink
Fix chat states
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekby committed Nov 22, 2023
1 parent 32dec4e commit 6bc3937
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ data class ChatState private constructor(

@JvmStatic
fun disabled(reason: ChatDisabledReason) = ChatState(
enabled = false, loading =
false, reason
enabled = false,
loading =
false,
reason
)
}
}
Expand Down
12 changes: 8 additions & 4 deletions Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ class ChatEnabledState private constructor() : ChatFrame.UseChatEnabledState,
}

override fun useState(
parent: Disposable, onStateChanged: (state: ChatState) -> Unit
parent: Disposable,
onStateChanged: (state: ChatState) -> Unit
) {
useState(parent, ChatEnabledChanged {
onStateChanged(it)
})
useState(
parent,
ChatEnabledChanged {
onStateChanged(it)
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class TabnineChatWebViewFactory : ToolWindowFactory, Disposable {
private val binaryRequestFacade = instanceOfBinaryRequestFacade()

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) {
BinaryStateSingleton.instance.get()?.isLoggedIn == true
}
val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance)
Disposer.register(toolWindow.disposable, chatFrame)
toolWindow.component.add(chatFrame)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ class ChatEnabledState private constructor() : ChatFrame.UseChatEnabledState,
}

override fun useState(
parent: Disposable, onStateChanged: (state: ChatState) -> Unit
parent: Disposable,
onStateChanged: (state: ChatState) -> Unit
) {
useState(parent, ChatEnabledChanged {
onStateChanged(it)
})
useState(
parent,
ChatEnabledChanged {
onStateChanged(it)
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class TabnineChatWebViewFactory : ToolWindowFactory, Disposable {
private val binaryRequestFacade = instanceOfBinaryRequestFacade()

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) {
UserInfoStateSingleton.instance.get()?.isLoggedIn == true
}
val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance)
Disposer.register(toolWindow.disposable, chatFrame)
toolWindow.component.add(chatFrame)
}
Expand Down

0 comments on commit 6bc3937

Please sign in to comment.