Skip to content

Commit 952a100

Browse files
committed
fix(web, navigation): stack navigation
1 parent 123b1e1 commit 952a100

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

core/dispatcher/src/webMain/kotlin/com/neoutils/neoregex/core/dispatcher/impl/NavigationManagerWeb.kt

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,65 +62,67 @@ internal class NavigationManagerWeb : NavigationManager {
6262
}
6363

6464
override fun update(screen: Navigation.Screen) {
65-
_canPop.value = when (screen) {
66-
Navigation.Screen.About -> true
67-
Navigation.Screen.Libraries -> true
68-
Navigation.Screen.Matcher -> false
69-
Navigation.Screen.Validator -> false
70-
}
71-
7265
_current.value = screen
7366
}
7467

7568
override suspend fun emit(event: Navigation.Event) {
7669
_event.send(event)
7770

78-
if (event is Navigation.Event.Navigate) {
79-
registerHistory(event.screen)
80-
}
71+
registerHistory(event)
8172
}
8273

83-
private fun registerHistory(screen: Navigation.Screen) {
84-
when (screen) {
85-
Navigation.Screen.Matcher -> {
86-
window.history.go(delta = -stack)
87-
stack = 0
88-
}
74+
private fun registerHistory(event: Navigation.Event) {
8975

90-
Navigation.Screen.About -> {
91-
if (screen is Navigation.Screen.Libraries) {
92-
window.history.back()
93-
return
76+
if (event is Navigation.Event.Navigate) {
77+
when (event.screen) {
78+
Navigation.Screen.Matcher -> {
79+
window.history.pushState(
80+
data = null,
81+
title = "",
82+
url = "?screen=matcher"
83+
)
84+
stack++
9485
}
9586

96-
window.history.pushState(
97-
data = null,
98-
title = "",
99-
url = "?screen=about"
100-
)
101-
stack = 1
102-
}
87+
Navigation.Screen.Validator -> {
88+
window.history.pushState(
89+
data = null,
90+
title = "",
91+
url = "?screen=validator"
92+
)
10393

104-
Navigation.Screen.Validator -> {
105-
window.history.pushState(
106-
data = null,
107-
title = "",
108-
url = "?screen=validator"
109-
)
94+
stack++
95+
}
11096

111-
stack = 1
112-
}
97+
Navigation.Screen.About -> {
98+
window.history.pushState(
99+
data = null,
100+
title = "",
101+
url = "?screen=about"
102+
)
113103

114-
Navigation.Screen.Libraries -> {
115-
window.history.pushState(
116-
data = null,
117-
title = "",
118-
url = "?screen=libraries"
119-
)
120-
stack = 2
104+
stack++
105+
}
106+
107+
Navigation.Screen.Libraries -> {
108+
window.history.pushState(
109+
data = null,
110+
title = "",
111+
url = "?screen=libraries"
112+
)
113+
114+
stack++
115+
}
121116
}
122117

118+
return
123119
}
120+
121+
if (event == Navigation.Event.OnBack) {
122+
window.history.go(delta = --stack)
123+
}
124+
125+
_canPop.value = stack > 0
124126
}
125127

126128
private suspend fun navigate(query: String) {

0 commit comments

Comments
 (0)