Skip to content

Commit

Permalink
Merge pull request #65 from Team-Ampersand/feature/60_write_student_i…
Browse files Browse the repository at this point in the history
…nfo_view_model_for_other_screen

🔀 :: (#60) write student info view model for other screen
  • Loading branch information
Cjsghkd authored Sep 18, 2023
2 parents 34fd2a7 + 5b47d57 commit 31fb84c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,38 @@ 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.dialog.DotoriDialog
import com.dotori.dotori_components.components.drawer.DotoriDrawerView
import com.dotori.dotori_components.components.drawer.DrawerItemData
import com.dotori.dotori_components.components.drawer.Icons
import com.dotori.dotori_components.components.student_info.DotoriStudentInfoListItem
import com.dotori.dotori_components.theme.DotoriTheme
import com.msg.domain.model.student_info.SelfStudyStatusModel
import com.msg.domain.model.student_info.StudentInfoRequestModel
import com.msg.presentation.view.student_info.component.DotoriHamburgerTopBar
import com.msg.presentation.view.student_info.component.StudentInfoBottomSheetContent
import com.msg.presentation.view.student_info.component.StudentInfoBottomSheetType
import com.msg.presentation.view.student_info.component.StudentInfoDialogContent
import com.msg.presentation.view.student_info.component.StudentInfoHeader
import com.msg.presentation.viewmodel.StudentInfoViewModel
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
@Composable
fun StudentInfoScreen(modifier: Modifier = Modifier) {
fun StudentInfoScreen(
modifier: Modifier = Modifier,
studentInfoViewModel: StudentInfoViewModel = hiltViewModel()
) {
var currentBottomSheetType by remember { mutableStateOf(StudentInfoBottomSheetType.StudentInfo) }
var isBaned by remember { mutableStateOf(false) }
var showDialog by remember { mutableStateOf(false) }
var name by remember { mutableStateOf("김준") }
var studentId by remember { mutableStateOf("2105") }
var userId by remember { mutableStateOf(0L) }
var role by remember { mutableStateOf("") }
var gender by remember { mutableStateOf("") }
var sheetCloseState by remember { mutableStateOf(false) }
var dialogState by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
Expand All @@ -60,7 +70,28 @@ fun StudentInfoScreen(modifier: Modifier = Modifier) {
sheetCloseState = true
},
onDismiss = { sheetCloseState = true },
onSaveClick = { sheetCloseState = true }
onSaveClick = {
studentInfoViewModel.modifyStudentInfo(
StudentInfoRequestModel(
userId = userId,
memberName = name,
stuNum = studentId,
gender = gender,
role = role
)
)
sheetCloseState = true
},
onSearchLogic = { searchText, grade, `class`, gender, role, selfStudyCheck ->
studentInfoViewModel.getSearchStudentInfo(
name = searchText,
grade = grade,
classNum = `class`,
gender = gender,
role = role,
selfStudy = selfStudyCheck
)
},
)
}
}
Expand All @@ -77,7 +108,17 @@ fun StudentInfoScreen(modifier: Modifier = Modifier) {
StudentInfoDialogContent(
isBaned = isBaned,
name = "김준",
onSubmit = { showDialog = false },
onSubmit = {
if (isBaned) studentInfoViewModel.banCancelSelfStudy(
role = role,
userId = userId
)
else studentInfoViewModel.banSelfStudy(
role = role,
userId = userId
)
showDialog = false
},
onCancel = { showDialog = false }
)
}
Expand Down Expand Up @@ -122,21 +163,29 @@ fun StudentInfoScreen(modifier: Modifier = Modifier) {
coroutineScope.launch { sheetState.show() }
}
}
items(15) {
studentInfoViewModel.getAllStudentInfo()
val allStudentInfoList = studentInfoViewModel.getAllStudentInfoUiState.value.data!!
items(allStudentInfoList.size) {
Row(modifier = Modifier.padding(horizontal = 20.dp)) {
DotoriStudentInfoListItem(
imageUrl = "",
name = "김준",
studentId = "1101",
gender = "MAN",
role = when (it) { // 테스트용으로 디자인이랑 똑같이 할려고 when문을 사용했습니다
3 -> "ROLE_COUNCILLOR"
4 -> "ROLE_DEVELOPER"
else -> "ROLE_MEMBER"
}
imageUrl = "", // 아직 서버에서 imageUrl를 넘겨주지 않습니다
name = allStudentInfoList[it].memberName,
studentId = allStudentInfoList[it].stuNum,
gender = allStudentInfoList[it].gender,
role = allStudentInfoList[it].role
) {
currentBottomSheetType = StudentInfoBottomSheetType.StudentInfo
isBaned = it == 3 // 테스트 용으로 넣었습니다.
userId = it.toLong()
name = allStudentInfoList[it].memberName
studentId = allStudentInfoList[it].stuNum
role = allStudentInfoList[it].role
gender = allStudentInfoList[it].gender
isBaned = when(allStudentInfoList[it].selfStudyStatus) {
SelfStudyStatusModel.CAN -> false // 자습 가능
SelfStudyStatusModel.APPLIED -> false // 자습 신청됨
SelfStudyStatusModel.CANT -> true // 자습 불가(자습신청 후 취소했을 때)
SelfStudyStatusModel.IMPOSSIBLE -> true // 자습 불가(강제로 자습 막았을 때)
}
coroutineScope.launch { sheetState.show() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ fun StudentInfoBottomSheetContent(
onSelfStudyClick: () -> Unit,
onSaveClick: () -> Unit,
onDismiss: () -> Unit,
onSearchLogic: (
searchText: String?,
grade: String?,
`class`: String?,
gender: String?,
role: String?,
selfStudyCheck: Boolean?
) -> Unit
) {
when (bottomSheetType) {
StudentInfoBottomSheetType.Filter -> {
FilterBottomSheet(
onSearchLogic = { searchText, grade, `class`, gender, role, selfStudyCheck ->

},
onSearchLogic = onSearchLogic,
onDismiss = onDismiss
)
}
Expand Down Expand Up @@ -123,7 +129,7 @@ fun StudentInfoBottomSheet(
fun FilterBottomSheet(
onSearchLogic: (
searchText: String?,
grade: Int?,
grade: String?,
`class`: String?,
gender: String?,
role: String?,
Expand All @@ -132,7 +138,7 @@ fun FilterBottomSheet(
onDismiss: () -> Unit
) {
var textValue: String? by remember { mutableStateOf(null) }
var gradeFilterSelectedState: Int? by remember { mutableStateOf(null) }
var gradeFilterSelectedState: String? by remember { mutableStateOf(null) }
var classFilterSelectedState: String? by remember { mutableStateOf(null) }
var genderFilterSelectedState: Gender? by remember { mutableStateOf(null) }
var roleFilterSelectedState: String? by remember { mutableStateOf(null) }
Expand Down Expand Up @@ -188,10 +194,10 @@ fun FilterBottomSheet(
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
repeat(3) {
val grade = it + 1
val grade = (it + 1).toString()
DotoriButton(
modifier = Modifier.weight(1f),
text = grade.toString(),
text = grade,
colors = if (grade == gradeFilterSelectedState) DotoriTheme.colors.primary10 else Transparent,
paddingValues = PaddingValues(vertical = 8.dp),
textStyle = DotoriTheme.typography.body2
Expand Down

0 comments on commit 31fb84c

Please sign in to comment.