Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a042ffa

Browse files
committed
impl: update page title instead of creating a new page
With the new TBX API we can update the title of a UI page without recreating the page and using hacks to force TBX to update the internal state.
1 parent eb93225 commit a042ffa

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class CoderRemoteProvider(
377377

378378
private fun shouldDoAutoSetup(): Boolean = firstRun && context.secrets.rememberMe == true
379379

380-
private suspend fun onConnect(client: CoderRestClient, cli: CoderCLIManager) {
380+
private fun onConnect(client: CoderRestClient, cli: CoderCLIManager) {
381381
// Store the URL and token for use next time.
382382
context.secrets.lastDeploymentURL = client.url.toString()
383383
context.secrets.lastToken = client.token ?: ""
@@ -387,9 +387,8 @@ class CoderRemoteProvider(
387387
this.client = client
388388
pollJob?.cancel()
389389
environments.showLoadingMessage()
390-
coderHeaderPage = NewEnvironmentPage(context.i18n.pnotr(client.url.toString()))
390+
coderHeaderPage.setTitle(context.i18n.pnotr(client.url.toString()))
391391
pollJob = poll(client, cli)
392-
context.refreshMainPage()
393392
}
394393

395394
private fun MutableStateFlow<LoadableState<List<CoderRemoteEnvironment>>>.showLoadingMessage() {

src/main/kotlin/com/coder/toolbox/views/CoderPage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.jetbrains.toolbox.api.localization.LocalizableString
77
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
88
import com.jetbrains.toolbox.api.ui.components.UiPage
99
import kotlinx.coroutines.flow.MutableStateFlow
10+
import kotlinx.coroutines.flow.update
1011

1112
/**
1213
* Base page that handles the icon, displaying error notifications, and
@@ -23,6 +24,12 @@ abstract class CoderPage(
2324
showIcon: Boolean = true,
2425
) : UiPage(titleObservable) {
2526

27+
fun setTitle(title: LocalizableString) {
28+
titleObservable.update {
29+
title
30+
}
31+
}
32+
2633
/**
2734
* Return the icon, if showing one.
2835
*

0 commit comments

Comments
 (0)