Skip to content

Commit

Permalink
fix(EditMedia): empty custom lists on new entry (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiel7 committed Jun 7, 2024
1 parent 38ff83e commit f1d074d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ fun EditMediaSheet(

LaunchedEffect(listEntry) {
viewModel.setListEntry(listEntry)
if (listEntry == null) {
viewModel.fillCustomLists(mediaDetails.type)
}
}

EditMediaSheetContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.axiel7.anihyou.data.repository.MediaListRepository
import com.axiel7.anihyou.fragment.BasicMediaDetails
import com.axiel7.anihyou.fragment.BasicMediaListEntry
import com.axiel7.anihyou.type.MediaListStatus
import com.axiel7.anihyou.type.MediaType
import com.axiel7.anihyou.ui.common.viewmodel.UiStateViewModel
import com.axiel7.anihyou.utils.DateUtils.millisToLocalDate
import com.axiel7.anihyou.utils.DateUtils.toFuzzyDate
Expand All @@ -28,7 +29,7 @@ import javax.inject.Inject
@HiltViewModel
class EditMediaViewModel @Inject constructor(
private val mediaListRepository: MediaListRepository,
defaultPreferencesRepository: DefaultPreferencesRepository,
private val defaultPreferencesRepository: DefaultPreferencesRepository,
) : UiStateViewModel<EditMediaUiState>(), EditMediaEvent {

override val initialState = EditMediaUiState()
Expand All @@ -54,10 +55,22 @@ class EditMediaViewModel @Inject constructor(
isPrivate = value?.private,
isHiddenFromStatusLists = value?.hiddenFromStatusLists,
notes = value?.notes,
customLists = null,
)
}

fun fillCustomLists(mediaType: MediaType?) {
viewModelScope.launch {
val customLists = linkedMapOf<String, Boolean>()
val savedCustomsLists = if (mediaType == MediaType.ANIME) {
defaultPreferencesRepository.animeCustomLists.first()
} else {
defaultPreferencesRepository.mangaCustomLists.first()
}
savedCustomsLists?.forEach { customLists[it] = false }
mutableUiState.update { it.copy(customLists = customLists) }
}
}

override fun onChangeStatus(value: MediaListStatus) {
if (mutableUiState.value.isNewEntry && value == MediaListStatus.CURRENT) {
mutableUiState.update {
Expand Down

0 comments on commit f1d074d

Please sign in to comment.