Skip to content
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

๐Ÿ”€ :: (#82) self study ui logic #87

Merged
merged 2 commits into from
Sep 19, 2023
Merged
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 @@ -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
Loading