Skip to content

๐Ÿ”€ :: (#116) - role injection to bottom navigation #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
dependencies {
add("implementation", project(":core:common"))
add("implementation", project(":core:model"))
add("implementation", project(":core:data"))
add("implementation", project(":core:ui"))
add("implementation", project(":core:design-system"))
add("implementation", project(":core:domain"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ interface AuthRepository {

suspend fun saveToken(token: LoginResponseModel)

fun getRole(): Flow<String>

fun logout(): Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class AuthRepositoryImpl @Inject constructor(
}
}

override fun getRole(): Flow<String> {
return localDataSource.getAuthorityInfo()
}

override fun logout(): Flow<Unit> {
return authDataSource.logout()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ interface LocalAuthDataSource {
// Authority
suspend fun setAuthorityInfo(authority: String)

suspend fun getAuthorityInfo(): Flow<String>
fun getAuthorityInfo(): Flow<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LocalAuthDataSourceImpl @Inject constructor(
}
}

override suspend fun getAuthorityInfo(): Flow<String> = dataStore.data.map {
override fun getAuthorityInfo(): Flow<String> = dataStore.data.map {
it[AuthPreferenceKey.AUTHORITY] ?: ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ internal fun MainPageRoute(
onNavigate: (Authority, String, Int?) -> Unit,
viewModel: MainViewModel = hiltViewModel()
) {
var role by remember { mutableStateOf(Authority.ROLE_TEACHER) } //๋กœ๊ทธ์ธ ๋กœ์ง ์ ์šฉํ›„ ๋ณ€๊ฒฝ
val role by viewModel.role.collectAsStateWithLifecycle(initialValue = "")
val getMissionUiState by viewModel.getMissionUiState.collectAsStateWithLifecycle()
val getRankingUiState by viewModel.getRankingUiState.collectAsStateWithLifecycle()

MainPageScreen(
role = role,
role = if (role.isNotBlank()) Authority.valueOf(role) else Authority.ROLE_TEACHER,
getMissionUiState = getMissionUiState,
getRankingUiState = getRankingUiState,
onNavigate = { navType, index -> onNavigate(role, navType, index) },
onNavigate = { navType, index -> onNavigate(Authority.valueOf(role), navType, index) },
initMain = {
with(viewModel) {
getMission()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.example.common.result.Result
import com.example.common.result.asResult
import com.stackknowledge.main.viewModel.uistate.GetMissionUiState
import com.stackknowledge.main.viewModel.uistate.GetRankingUiState
import com.stackknowledge.repository.auth.AuthRepository
import com.stackknowledge.usecase.mission.GetMissionUseCase
import com.stackknowledge.usecase.student.GetStudentPointRankingUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -20,12 +21,15 @@ import javax.inject.Inject
class MainViewModel @Inject constructor(
private val getMissionUseCase: GetMissionUseCase,
private val getStudentPointRankingUseCase: GetStudentPointRankingUseCase,
private val authRepository: AuthRepository
): ViewModel() {
private val _getMissionUiState = MutableStateFlow<GetMissionUiState>(GetMissionUiState.Loading)
internal val getMissionUiState = _getMissionUiState.asStateFlow()

private val _getRankingUiState = MutableStateFlow<GetRankingUiState>(GetRankingUiState.Loading)
internal val getRankingUiState = _getRankingUiState.asStateFlow()

internal val role = authRepository.getRole()
internal fun getMission() = viewModelScope.launch {
getMissionUseCase()
.asResult()
Expand Down
Loading