Skip to content
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 @@ -56,6 +56,7 @@ import com.sampoom.android.core.ui.theme.backgroundCardColor
import com.sampoom.android.core.ui.theme.textColor
import com.sampoom.android.core.ui.theme.textSecondaryColor
import com.sampoom.android.feature.order.domain.model.Order
import com.sampoom.android.feature.user.domain.model.User

@Composable
fun DashboardScreen(
Expand All @@ -69,6 +70,7 @@ fun DashboardScreen(
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val pullRefreshState = rememberPullToRefreshState()
val isManager = true // TODO: Role 검증
val user by viewModel.user.collectAsStateWithLifecycle()

LaunchedEffect(errorLabel) {
viewModel.bindLabel(errorLabel)
Expand Down Expand Up @@ -144,7 +146,7 @@ fun DashboardScreen(
}
}

item { TitleSection() }
item { TitleSection(user) }

item { ButtonSection(isManager) }

Expand All @@ -166,15 +168,17 @@ fun DashboardScreen(
}

@Composable
fun TitleSection() {
fun TitleSection(
user: User?
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 24.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text(
text = "가산디지털단지점", // TODO: Agency Id 받아오기
text = user?.branch ?: "", // TODO: Agency Id 받아오기
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = textColor()
Expand All @@ -185,7 +189,7 @@ fun TitleSection() {

pushStringAnnotation(tag = "NAME", annotation = "name")
withStyle(style = SpanStyle(color = Main500)) {
append("홍길동") // TODO : 이름 받아오기
append(user?.userName ?: "") // TODO : 이름 받아오기
}
append(stringResource(R.string.dashboard_title_hello_sir))
pop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sampoom.android.core.network.serverMessageOrNull
import com.sampoom.android.feature.order.domain.usecase.GetOrderUseCase
import com.sampoom.android.feature.user.domain.model.User
import com.sampoom.android.feature.user.domain.usecase.GetStoredUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -15,7 +17,8 @@ import javax.inject.Inject

@HiltViewModel
class DashboardViewModel @Inject constructor(
private val getOrderListUseCase: GetOrderUseCase
private val getOrderListUseCase: GetOrderUseCase,
private val getStoredUserUseCase: GetStoredUserUseCase
): ViewModel() {

private companion object {
Expand All @@ -25,6 +28,9 @@ class DashboardViewModel @Inject constructor(
private val _uiState = MutableStateFlow(DashboardUiState())
val uiState : StateFlow<DashboardUiState> = _uiState

private val _user = MutableStateFlow<User?>(null)
val user: StateFlow<User?> = _user

private var errorLabel: String = ""
private var loadJob: Job? = null

Expand All @@ -33,6 +39,9 @@ class DashboardViewModel @Inject constructor(
}

init {
viewModelScope.launch {
_user.value = getStoredUserUseCase()
}
loadOrderList()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sampoom.android.feature.user.domain.usecase

import com.sampoom.android.core.datastore.AuthPreferences
import com.sampoom.android.feature.user.domain.model.User
import javax.inject.Inject

class GetStoredUserUseCase @Inject constructor(
private val preferences: AuthPreferences
) {
suspend operator fun invoke(): User? = preferences.getStoredUser()
}