-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Google auth * Implement Google auth on BE side * Login with Google POC * WIP: Fix navigation * Working webpack config * Remove unnecessary code * Fix nav * Fix SPA on GitHub Pages * WIP: Rework navigation * Add fake Google auth * WIP: Fix navigation * Fix missing routing * Refactor * Refactor * Refactor * Fix build
- Loading branch information
1 parent
5ff3610
commit 8768fb6
Showing
42 changed files
with
538 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
composeApp/src/commonMain/kotlin/domain/GoogleAuthenticationUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package domain | ||
|
||
import IvyConstants | ||
import androidx.compose.ui.platform.UriHandler | ||
import ivy.data.ServerUrlProvider | ||
|
||
class GoogleAuthenticationUseCaseImpl( | ||
private val uriHandler: UriHandler, | ||
private val serverUrlProvider: ServerUrlProvider, | ||
) : GoogleAuthenticationUseCase { | ||
override fun loginWithGoogle() { | ||
val clientId = IvyConstants.GoogleClientId | ||
val redirectUri = "${serverUrlProvider.serverUrl}${IvyConstants.GoogleAuthCallbackEndpoint}" | ||
|
||
val authUrl = """ | ||
https://accounts.google.com/o/oauth2/v2/auth? | ||
client_id=$clientId& | ||
redirect_uri=$redirectUri& | ||
response_type=code& | ||
scope=email profile | ||
""".trimIndent() | ||
|
||
uriHandler.openUri(authUrl) | ||
} | ||
} | ||
|
||
interface GoogleAuthenticationUseCase { | ||
fun loginWithGoogle() | ||
} |
16 changes: 16 additions & 0 deletions
16
composeApp/src/commonMain/kotlin/domain/di/DomainModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package domain.di | ||
|
||
import di.bindWithFake | ||
import domain.GoogleAuthenticationUseCase | ||
import domain.GoogleAuthenticationUseCaseImpl | ||
import domain.fake.FakeGoogleAuthenticationUseCase | ||
import ivy.di.Di | ||
import ivy.di.autowire.autoWire | ||
|
||
object DomainModule : Di.Module { | ||
override fun init() = Di.appScope { | ||
autoWire(::GoogleAuthenticationUseCaseImpl) | ||
autoWire(::FakeGoogleAuthenticationUseCase) | ||
bindWithFake<GoogleAuthenticationUseCase, GoogleAuthenticationUseCaseImpl, FakeGoogleAuthenticationUseCase>() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
composeApp/src/commonMain/kotlin/domain/fake/FakeGoogleAuthenticationUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package domain.fake | ||
|
||
import domain.GoogleAuthenticationUseCase | ||
import navigation.Navigation | ||
import ui.screen.home.HomeScreen | ||
|
||
class FakeGoogleAuthenticationUseCase( | ||
private val navigation: Navigation | ||
) : GoogleAuthenticationUseCase { | ||
override fun loginWithGoogle() { | ||
navigation.navigateTo(HomeScreen()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package navigation | ||
|
||
import Platform | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import ui.screen.NotFoundPage | ||
|
||
class Navigation( | ||
private val systemNavigation: SystemNavigation, | ||
private val platform: Platform, | ||
) { | ||
@Composable | ||
fun NavHost() { | ||
val currentRoute by systemNavigation.currentRoute.collectAsState() | ||
val screen = remember(currentRoute) { | ||
Routing.resolve(currentRoute)?.also(Screen::initialize) | ||
} | ||
screen?.Content() ?: NotFoundPage(currentRoute) | ||
} | ||
|
||
fun navigateTo(screen: Screen) { | ||
systemNavigation.navigateTo(screen) | ||
} | ||
|
||
fun replaceWith(screen: Screen) { | ||
systemNavigation.replaceWith(screen) | ||
} | ||
|
||
fun navigateBack() { | ||
systemNavigation.navigateBack() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package navigation | ||
|
||
import arrow.core.Option | ||
import ui.screen.course.CourseRouter | ||
import ui.screen.home.HomeRouter | ||
import ui.screen.intro.IntroRouter | ||
import ui.screen.lesson.LessonRouter | ||
|
||
object Routing { | ||
private val routers = setOf<Router<*>>( | ||
IntroRouter, | ||
HomeRouter, | ||
LessonRouter, | ||
CourseRouter, | ||
) | ||
|
||
fun resolve(route: Route): Screen? { | ||
return routers.firstNotNullOfOrNull { | ||
it.fromRoute(route).getOrNull() | ||
} | ||
} | ||
} | ||
|
||
interface Router<S : Screen> { | ||
fun fromRoute(route: Route): Option<S> | ||
fun toRoute(screen: S): Route | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
composeApp/src/commonMain/kotlin/navigation/SystemNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package navigation | ||
|
||
import androidx.compose.runtime.Immutable | ||
import arrow.core.None | ||
import arrow.core.Option | ||
import arrow.core.some | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
interface SystemNavigation { | ||
val currentRoute: StateFlow<Route> | ||
fun navigateTo(screen: Screen) | ||
fun replaceWith(screen: Screen) | ||
fun navigateBack() | ||
} | ||
|
||
@Immutable | ||
data class Route( | ||
val path: String, | ||
val params: Map<String, String> = emptyMap(), | ||
) { | ||
operator fun get(key: String): Option<String> { | ||
return params[key]?.some() ?: None | ||
} | ||
} | ||
|
||
expect fun systemNavigation(): SystemNavigation |
44 changes: 0 additions & 44 deletions
44
composeApp/src/commonMain/kotlin/ui/navigation/Navigation.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.