diff --git a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/Home.kt b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/Home.kt index 229d5256..f38d3043 100644 --- a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/Home.kt +++ b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/Home.kt @@ -78,8 +78,7 @@ fun HomeScreen( @OptIn(ExperimentalFoundationApi::class) @Composable fun BoardInMain( - department: Department, - homeBoardViewModel: HomeBoardViewModel = hiltViewModel(key = department.name) + department: Department ) { val context = LocalContext.current @@ -97,16 +96,6 @@ fun BoardInMain( mutableStateOf(department.boards[0].board) } - LaunchedEffect(key1 = tabIndex) { - homeBoardViewModel.getApi(department.name, key) - } - - val uiState = homeBoardViewModel.uiState.collectAsState() - val isSuccess = uiState.value.isSuccess - val isLoaded = uiState.value.isLoaded - val boardList = uiState.value.boardList - val statusCode = uiState.value.statusCode - Card( modifier = Modifier .fillMaxWidth() @@ -145,6 +134,18 @@ fun BoardInMain( ) { page -> key = department.boards[page].board + val homeBoardViewModel: HomeBoardViewModel = hiltViewModel(key = "${department.name}:$key") + + LaunchedEffect(Unit) { + homeBoardViewModel.getApi(department.name, key) + } + + val uiState = homeBoardViewModel.uiState.collectAsState() + val isSuccess = uiState.value.isSuccess + val isLoaded = uiState.value.isLoaded + val boardData = uiState.value.boardData + val statusCode = uiState.value.statusCode + if (!isLoaded) { Column( modifier = Modifier @@ -156,7 +157,7 @@ fun BoardInMain( } } else { if (isSuccess && statusCode == 200) { - if (boardList[key] == null) { + if (boardData.isEmpty()) { Column( modifier = Modifier .fillMaxWidth() @@ -167,7 +168,7 @@ fun BoardInMain( } } else { Column { - boardList[key]!!.forEach { data -> + boardData.forEach { data -> Box( modifier = Modifier .clickable { diff --git a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardState.kt b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardState.kt index b507fa55..ab306ba3 100644 --- a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardState.kt +++ b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardState.kt @@ -6,7 +6,7 @@ import com.kongjak.koreatechboard.ui.base.UiState data class HomeBoardState( val isLoaded: Boolean = false, val isSuccess: Boolean = false, - val boardList: Map?> = emptyMap(), + val boardData: List = emptyList(), val statusCode: Int = 0, val error: String = "" ) : UiState diff --git a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardViewModel.kt b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardViewModel.kt index 622224a5..91d284d6 100644 --- a/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardViewModel.kt +++ b/app/src/main/java/com/kongjak/koreatechboard/ui/main/home/HomeBoardViewModel.kt @@ -33,7 +33,7 @@ class HomeBoardViewModel @Inject constructor(private val getBoardMinimumUseCase: setState( oldState.copy( isSuccess = true, - boardList = (oldState.boardList + (event.board to (it.data.boardData))), + boardData = it.data.boardData ?: emptyList(), statusCode = it.data.statusCode, isLoaded = true )