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

Feature/#109 my writing #110

Merged
merged 4 commits into from
Jan 21, 2024
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
@@ -1,12 +1,11 @@
package com.suwiki.feature.timetable.timetablelist.component
package com.suwiki.core.designsystem.component.container

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -26,13 +25,13 @@ import com.suwiki.core.designsystem.theme.Black
import com.suwiki.core.designsystem.theme.GrayF6
import com.suwiki.core.designsystem.theme.SuwikiTheme
import com.suwiki.core.designsystem.theme.White
import com.suwiki.core.model.timetable.Timetable
import com.suwiki.core.ui.extension.suwikiClickable

@Composable
fun TimetableEditContainer(
fun SuwikiEditContainer(
modifier: Modifier = Modifier,
timetable: Timetable = Timetable(),
name: String,
semester: String,
onClickEditButton: () -> Unit = {},
onClickDeleteButton: () -> Unit = {},
onClick: () -> Unit = {},
Expand Down Expand Up @@ -67,12 +66,12 @@ fun TimetableEditContainer(
modifier = Modifier.weight(1f, false),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
text = timetable.name,
text = name,
style = SuwikiTheme.typography.header6,
color = Black,
)

SuwikiBadge(color = BadgeColor.Gray, text = "${timetable.year}-${timetable.semester}")
SuwikiBadge(color = BadgeColor.Gray, text = semester)
}

Row(
Expand All @@ -95,14 +94,9 @@ fun TimetableEditContainer(
fun TimetableEditContainerPreview() {
SuwikiTheme {
Column {
TimetableEditContainer(
timetable = Timetable(
createTime = 0,
year = "2024",
semester = "1",
name = "์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ",
cellList = listOf(),
),
SuwikiEditContainer(
name = "์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ์‹œ๊ฐ„ํ‘œ",
semester = "1",
)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import kotlinx.serialization.Serializable
@Serializable
@Stable
data class MyExamEvaluation(
val id: Long? = null,
val lectureName: String? = null, // ๊ณผ๋ชฉ ์ด๋ฆ„
val professor: String? = null, // ๊ต์ˆ˜์ด๋ฆ„
val majorType: String? = null, // ๊ฐœ์„คํ•™๊ณผ
val selectedSemester: String? = null,
val semesterList: String? = null,
val examInfo: List<String> = listOf(), // ์‹œํ—˜ ์œ ํ˜• ex) "์กฑ๋ณด, ๊ต์žฌ, PPT, ํ•„๊ธฐ, ์‘์šฉ, ์‹ค์Šต, ๊ณผ์ œ",
val examType: String? = null, // ์‹œํ—˜ ์ข…๋ฅ˜(๋ฐ”ํ…€์‹œํŠธ) ex) "์ค‘๊ฐ„๊ณ ์‚ฌ", //๊ธฐ๋ง๊ณ ์‚ฌ, ์ชฝ์ง€, ๊ธฐํƒ€
val id: Long = -1L,
val lectureName: String = "", // ๊ณผ๋ชฉ ์ด๋ฆ„
val professor: String = "", // ๊ต์ˆ˜์ด๋ฆ„
val majorType: String = "", // ๊ฐœ์„คํ•™๊ณผ
val selectedSemester: String = "",
val semesterList: List<String> = emptyList(),
val examInfo: List<String> = emptyList(), // ์‹œํ—˜ ์œ ํ˜• ex) "์กฑ๋ณด, ๊ต์žฌ, PPT, ํ•„๊ธฐ, ์‘์šฉ, ์‹ค์Šต, ๊ณผ์ œ",
val examType: String = "", // ์‹œํ—˜ ์ข…๋ฅ˜(๋ฐ”ํ…€์‹œํŠธ) ex) "์ค‘๊ฐ„๊ณ ์‚ฌ", //๊ธฐ๋ง๊ณ ์‚ฌ, ์ชฝ์ง€, ๊ธฐํƒ€
val examDifficulty: String = "", // ์‹œํ—˜ ๋‚œ์ด๋„
val content: String = "",
) : java.io.Serializable
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ data class MyLectureEvaluation(
val difficulty: Int = 0, // ํ•™์  ์ž˜์ฃผ๋Š”๊ฐ€? (๊นŒ๋‹ค๋กœ์›€ == 0, ๋ณดํ†ต == 1, ํ•™์ ๋Š๋‹˜ ==2)
val homework: Int = 0, // ๊ณผ์ œ์–‘ (์—†์Œ ==0, ๋ณดํ†ต == 1, ๋งŽ์Œ == 2)
val content: String = "",
) : java.io.Serializable
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class AuthenticationInterceptor @Inject constructor(
Timber.tag(RETROFIT_TAG)
.d(
"AuthenticationInterceptor - intercept() called / request header: %s",
request.headers,
accessToken,
)
return@runBlocking chain.proceed(request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import kotlinx.coroutines.flow.collectLatest

// https://manavtamboli.medium.com/infinite-list-paged-list-in-jetpack-compose-b10fc7e74768
@Composable
Expand All @@ -26,9 +27,9 @@ fun LazyListState.OnBottomReached(
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - buffer
}
}
LaunchedEffect(shouldLoadMore.value) {
LaunchedEffect(shouldLoadMore) {
snapshotFlow { shouldLoadMore.value }
.collect {
.collectLatest {
if (it) {
onLoadMore()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UpdateLectureEvaluationUseCase @Inject constructor(
private val lectureEditorRepository: LectureEditorRepository,
) {
suspend operator fun invoke(param: Param): Result<Unit> = runCatchingIgnoreCancelled {
param.run {
with(param) {
lectureEditorRepository.updateLectureEvaluation(
lectureId = lectureId,
selectedSemester = selectedSemester,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import com.suwiki.core.model.enums.ExamInfo
import com.suwiki.core.model.enums.ExamLevel
import com.suwiki.core.model.enums.ExamType
import com.suwiki.core.model.lectureevaluation.exam.MyExamEvaluation
import com.suwiki.core.model.user.User
import com.suwiki.core.ui.extension.decodeFromUri
import com.suwiki.domain.lectureevaluation.editor.usecase.exam.DeleteExamEvaluationUseCase
import com.suwiki.domain.lectureevaluation.editor.usecase.exam.UpdateExamEvaluationUseCase
import com.suwiki.domain.user.usecase.GetUserInfoUseCase
import com.suwiki.feature.lectureevaluation.editor.lectureevaluation.MINIMUM_DELETE_POINT
import com.suwiki.feature.lectureevaluation.editor.navigation.MyEvaluationEditRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
Expand All @@ -29,8 +25,6 @@ import javax.inject.Inject
@HiltViewModel
class MyExamEvaluationEditViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
val getUserInfoUseCase: GetUserInfoUseCase,
val deleteExamEvaluationUseCase: DeleteExamEvaluationUseCase,
val updateExamEvaluationUseCase: UpdateExamEvaluationUseCase,
) : ContainerHost<MyExamEvaluationEditState, MyExamEvaluationEditSideEffect>, ViewModel() {
override val container: Container<MyExamEvaluationEditState, MyExamEvaluationEditSideEffect> =
Expand All @@ -41,14 +35,11 @@ class MyExamEvaluationEditViewModel @Inject constructor(

suspend fun initData() = intent {
showLoadingScreen()

with(myExamEvaluationItem) {
getUserInfoUseCase().collect(::getPoint).runCatching {}
.onFailure {
postSideEffect(MyExamEvaluationEditSideEffect.HandleException(it))
}
reduce {
state.copy(
semesterList = semesterList!!.split(", ").toPersistentList(),
semesterList = semesterList.toPersistentList(),
selectedSemester = selectedSemester,
selectedExamType = examType,
)
Expand All @@ -69,13 +60,10 @@ class MyExamEvaluationEditViewModel @Inject constructor(
}
hideLoadingScreen()
}

private fun getPoint(user: User) = intent { reduce { state.copy(point = user.point) } }

fun updateExamEvaluation() = intent {
updateExamEvaluationUseCase(
UpdateExamEvaluationUseCase.Param(
lectureId = myExamEvaluationItem.id!!,
lectureId = myExamEvaluationItem.id,
selectedSemester = state.selectedSemester,
examInfo = state.examInfo.filter { it.isNotBlank() }.joinToString(", "),
examType = state.selectedExamType,
Expand All @@ -84,18 +72,6 @@ class MyExamEvaluationEditViewModel @Inject constructor(
),
)
.onSuccess {
showReviseToast()
popBackStack()
}
.onFailure {
postSideEffect(MyExamEvaluationEditSideEffect.HandleException(it))
}
}

fun deleteExamEvaluation() = intent {
deleteExamEvaluationUseCase(myExamEvaluationItem.id!!)
.onSuccess {
showDeleteToast()
popBackStack()
}
.onFailure {
Expand All @@ -116,9 +92,11 @@ class MyExamEvaluationEditViewModel @Inject constructor(
}
hideExamTypeBottomSheet()
}

fun updateExamLevel(examLevel: ExamLevel) = intent {
reduce { state.copy(examLevel = examLevel) }
}

fun updateExamInfo(info: ExamInfo) = intent {
val examInfoList = state.examInfo.toMutableList()

Expand All @@ -135,26 +113,12 @@ class MyExamEvaluationEditViewModel @Inject constructor(
reduce { state.copy(examEvaluation = examEvaluationValue) }
}

fun showDeleteOrLackPointDialog() = intent {
if (state.point > MINIMUM_DELETE_POINT) {
showExamEvaluationDeleteDialog()
} else {
showLackPointDialog()
}
}

private fun showLoadingScreen() = intent { reduce { state.copy(isLoading = true) } }
private fun hideLoadingScreen() = intent { reduce { state.copy(isLoading = false) } }
private fun showExamEvaluationDeleteDialog() = intent { reduce { state.copy(showDeleteExamEvaluationDialog = true) } }
fun hideExamEvaluationDeleteDialog() = intent { reduce { state.copy(showDeleteExamEvaluationDialog = false) } }
private fun showLackPointDialog() = intent { reduce { state.copy(showLackPointDialog = true) } }
fun hideLackPointDialog() = intent { reduce { state.copy(showLackPointDialog = false) } }
fun showSemesterBottomSheet() = intent { reduce { state.copy(showSemesterBottomSheet = true) } }
fun hideSemesterBottomSheet() = intent { reduce { state.copy(showSemesterBottomSheet = false) } }
fun showExamTypeBottomSheet() = intent { reduce { state.copy(showExamTypeBottomSheet = true) } }
fun hideExamTypeBottomSheet() = intent { reduce { state.copy(showExamTypeBottomSheet = false) } }

fun popBackStack() = intent { postSideEffect(MyExamEvaluationEditSideEffect.PopBackStack) }
private fun showDeleteToast() = intent { postSideEffect(MyExamEvaluationEditSideEffect.ShowMyExamEvaluationDeleteToast) }
private fun showReviseToast() = intent { postSideEffect(MyExamEvaluationEditSideEffect.ShowMyExamEvaluationReviseToast) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ data class MyExamEvaluationEditState(
val examInfo: PersistentList<String> = persistentListOf(),
val showSemesterBottomSheet: Boolean = false,
val showExamTypeBottomSheet: Boolean = false,
val showDeleteExamEvaluationDialog: Boolean = false,
val showLackPointDialog: Boolean = false,
)

sealed interface MyExamEvaluationEditSideEffect {
data object PopBackStack : MyExamEvaluationEditSideEffect
data object ShowMyExamEvaluationDeleteToast : MyExamEvaluationEditSideEffect
data object ShowMyExamEvaluationReviseToast : MyExamEvaluationEditSideEffect
data class HandleException(val throwable: Throwable) : MyExamEvaluationEditSideEffect
}
Loading