Skip to content

Commit

Permalink
Merge pull request #87 from Team-Ampersand/feature/82_self_study_ui_l…
Browse files Browse the repository at this point in the history
…ogic

🔀 :: (#82) self study ui logic
  • Loading branch information
ImGaram authored Sep 19, 2023
2 parents 1f68c58 + 39f8e81 commit eb49378
Showing 1 changed file with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -18,27 +19,45 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.dotori.dotori_components.components.bottomsheet.DotoriBottomSheetDialog
import com.dotori.dotori_components.components.card.DotoriStudentCard
import com.dotori.dotori_components.components.utils.Types
import com.dotori.dotori_components.theme.DotoriTheme
import com.msg.domain.model.self_study.SelfStudyListResponseModel
import com.msg.presentation.view.component.DotoriTopBar
import com.msg.presentation.view.self_study.component.BottomSheetContent
import com.msg.presentation.view.self_study.component.EmptySelfStudyScreen
import com.msg.presentation.view.self_study.component.SelfStudyTopBar
import com.msg.presentation.view.util.updateDotoriTheme
import com.msg.presentation.viewmodel.SelfStudyViewModel
import kotlinx.coroutines.launch

@Composable
@OptIn(ExperimentalMaterialApi::class)
fun SelfStudyScreen() {
val list = listOf(1,2,3,4,5)
fun SelfStudyScreen(
selfStudyViewModel: SelfStudyViewModel = hiltViewModel()
) {
val selfStudyList by selfStudyViewModel.selfStudyListState.collectAsState()
val role = "member"

LaunchedEffect(Unit) {
selfStudyViewModel.getSelfStudyList(role)
}

val scope = rememberCoroutineScope()
var sheetCloseState by remember { mutableStateOf(false) }

DotoriBottomSheetDialog(
sheetContent = {
BottomSheetContent { searchText, grade, `class`, gender ->
selfStudyViewModel.searchSelfStudyStudent(
role = role,
name = searchText,
gender = gender,
classNum = `class`,
grade = grade.toInt()
)
sheetCloseState = true
}
}
Expand All @@ -48,15 +67,22 @@ fun SelfStudyScreen() {
sheetCloseState = false
}

if (list.isEmpty()) {
if (selfStudyList.data.isNullOrEmpty()) {
SelfStudyIsEmptyContent {
scope.launch { state.show() }
}
} else {
SelfStudyStudentListContent(
list = list,
list = selfStudyList.data!!,
onFilterIconClick = {
scope.launch { state.show() }
},
checkSelfStudyLogic = { item, checkBoxState ->
selfStudyViewModel.checkSelfStudy(
role = role,
memberId = item.id.toLong(),
selfStudyCheck = checkBoxState
)
}
)
}
Expand All @@ -83,8 +109,9 @@ fun SelfStudyIsEmptyContent(onFilterIconClick: () -> Unit, ) {
@Composable
@OptIn(ExperimentalFoundationApi::class)
fun SelfStudyStudentListContent(
list: List<Int>,
onFilterIconClick: () -> Unit
list: List<SelfStudyListResponseModel>,
onFilterIconClick: () -> Unit,
checkSelfStudyLogic: (SelfStudyListResponseModel, Boolean) -> Unit
) {
var checkBoxState by remember { mutableStateOf(false) }

Expand All @@ -103,16 +130,19 @@ fun SelfStudyStudentListContent(

stickyHeader { SelfStudyTopBar { onFilterIconClick() } }

items(list) { position ->
itemsIndexed(list) { position, item ->
DotoriStudentCard(
name = "임가람",
gender = "MAN",
role = "ROLE_MEMBER",
studentNumber = "3412",
name = item.memberName,
gender = item.gender,
role = "ROLE_MEMBER", // 임시 권한
studentNumber = item.stuNum,
position = position,
mode = Types.CardType.SELF_STUDY,
isLast = list.lastIndex + 1 == position,
onCheckBoxChange = { checkBoxState = it }
onCheckBoxChange = {
checkBoxState = it
checkSelfStudyLogic(item, checkBoxState)
}
)
}
}
Expand Down

0 comments on commit eb49378

Please sign in to comment.