Skip to content

Commit

Permalink
refactor: make consistency on emoji fetch mode as sortByDate
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisWooyeol committed Dec 4, 2023
1 parent cb8243f commit 49a1fc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EmojiViewModel @Inject constructor(
private val _unSaveEmojiState = MutableStateFlow<Result<Unit>?>(null)
val unSaveEmojiState = _unSaveEmojiState.asStateFlow()

var sortingMode by mutableIntStateOf(0)
var sortByDate by mutableIntStateOf(0)

val emojiList = emojiUseCase.emojiList
val myCreatedEmojiList = emojiUseCase.myCreatedEmojiList
Expand All @@ -47,7 +47,7 @@ class EmojiViewModel @Inject constructor(

fun fetchEmojiList() {
viewModelScope.launch {
emojiUseCase.fetchEmojiList(sortingMode)
emojiUseCase.fetchEmojiList(sortByDate)
.cachedIn(viewModelScope)
.collect {
emojiUseCase.updateEmojiList(it)
Expand All @@ -56,7 +56,7 @@ class EmojiViewModel @Inject constructor(
}

fun toggleSortingMode() {
sortingMode = if (sortingMode == 1 ) 0 else 1
sortByDate = sortByDate xor 1
fetchEmojiList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -113,11 +112,11 @@ fun EmojiPage(
Button(
onClick = { viewModel.toggleSortingMode() },
colors = ButtonDefaults.buttonColors(
backgroundColor = if (viewModel.sortingMode == 0) Black else LightGray,
backgroundColor = if (viewModel.sortByDate == 0) Black else LightGray,
contentColor = White
)
) {
Text(text = if (viewModel.sortingMode == 1) "Sort by Date" else "Sort by Save Count", fontSize = 12.sp)
Text(text = if (viewModel.sortByDate == 1) "Sort by Date" else "Sort by Save Count", fontSize = 12.sp)
}
}

Expand Down

0 comments on commit 49a1fc9

Please sign in to comment.