mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-02 03:47:09 +01:00
fix: use different error message if autofill title empty (#158)
* update l10n * use different error message in autofill when metadata title empty
This commit is contained in:
parent
ed7aa91a03
commit
8ba43210a8
@ -447,4 +447,5 @@ internal open class DefaultStrings : Strings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val settingsAboutMatrix = "Join Matrix room"
|
override val settingsAboutMatrix = "Join Matrix room"
|
||||||
|
override val messageNoResult = "Oops… no result found!"
|
||||||
}
|
}
|
||||||
|
@ -462,4 +462,5 @@ internal val ItStrings =
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val settingsAboutMatrix = "Entra nella room Matrix"
|
override val settingsAboutMatrix = "Entra nella room Matrix"
|
||||||
|
override val messageNoResult = "Ops… nessun risultato trovato!"
|
||||||
}
|
}
|
||||||
|
@ -441,6 +441,7 @@ interface Strings {
|
|||||||
fun inboxNotificationContent(count: Int): String
|
fun inboxNotificationContent(count: Int): String
|
||||||
|
|
||||||
val settingsAboutMatrix: String
|
val settingsAboutMatrix: String
|
||||||
|
val messageNoResult: String
|
||||||
}
|
}
|
||||||
|
|
||||||
object Locales {
|
object Locales {
|
||||||
|
@ -17,15 +17,25 @@ interface CreatePostMviModel :
|
|||||||
MviModel<CreatePostMviModel.Intent, CreatePostMviModel.UiState, CreatePostMviModel.Effect>,
|
MviModel<CreatePostMviModel.Intent, CreatePostMviModel.UiState, CreatePostMviModel.Effect>,
|
||||||
ScreenModel {
|
ScreenModel {
|
||||||
sealed interface Intent {
|
sealed interface Intent {
|
||||||
data class SetCommunity(val value: CommunityModel) : Intent
|
data class SetCommunity(
|
||||||
|
val value: CommunityModel,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class SetTitle(val value: String) : Intent
|
data class SetTitle(
|
||||||
|
val value: String,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class SetUrl(val value: String) : Intent
|
data class SetUrl(
|
||||||
|
val value: String,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class ChangeNsfw(val value: Boolean) : Intent
|
data class ChangeNsfw(
|
||||||
|
val value: Boolean,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class ImageSelected(val value: ByteArray) : Intent {
|
data class ImageSelected(
|
||||||
|
val value: ByteArray,
|
||||||
|
) : Intent {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other == null || this::class != other::class) return false
|
if (other == null || this::class != other::class) return false
|
||||||
@ -35,12 +45,12 @@ interface CreatePostMviModel :
|
|||||||
return value.contentEquals(other.value)
|
return value.contentEquals(other.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int = value.contentHashCode()
|
||||||
return value.contentHashCode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class InsertImageInBody(val value: ByteArray) : Intent {
|
data class InsertImageInBody(
|
||||||
|
val value: ByteArray,
|
||||||
|
) : Intent {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other == null || this::class != other::class) return false
|
if (other == null || this::class != other::class) return false
|
||||||
@ -50,16 +60,20 @@ interface CreatePostMviModel :
|
|||||||
return value.contentEquals(other.value)
|
return value.contentEquals(other.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int = value.contentHashCode()
|
||||||
return value.contentHashCode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ChangeSection(val value: CreatePostSection) : Intent
|
data class ChangeSection(
|
||||||
|
val value: CreatePostSection,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class ChangeLanguage(val value: Long?) : Intent
|
data class ChangeLanguage(
|
||||||
|
val value: Long?,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data class ChangeBodyValue(val value: TextFieldValue) : Intent
|
data class ChangeBodyValue(
|
||||||
|
val value: TextFieldValue,
|
||||||
|
) : Intent
|
||||||
|
|
||||||
data object Send : Intent
|
data object Send : Intent
|
||||||
|
|
||||||
@ -100,10 +114,14 @@ interface CreatePostMviModel :
|
|||||||
sealed interface Effect {
|
sealed interface Effect {
|
||||||
data object Success : Effect
|
data object Success : Effect
|
||||||
|
|
||||||
data class Failure(val message: String?) : Effect
|
data class Failure(
|
||||||
|
val message: String?,
|
||||||
|
) : Effect
|
||||||
|
|
||||||
data object DraftSaved : Effect
|
data object DraftSaved : Effect
|
||||||
|
|
||||||
data object AutoFillFailed : Effect
|
data object AutoFillError : Effect
|
||||||
|
|
||||||
|
data object AutoFillEmpty : Effect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ class CreatePostScreen(
|
|||||||
val uiState by model.uiState.collectAsState()
|
val uiState by model.uiState.collectAsState()
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
val genericError = LocalStrings.current.messageGenericError
|
val genericError = LocalStrings.current.messageGenericError
|
||||||
|
val autofillEmpty = LocalStrings.current.messageNoResult
|
||||||
val notificationCenter = remember { getNotificationCenter() }
|
val notificationCenter = remember { getNotificationCenter() }
|
||||||
val galleryHelper = remember { getGalleryHelper() }
|
val galleryHelper = remember { getGalleryHelper() }
|
||||||
val crossPostText = LocalStrings.current.createPostCrossPostText
|
val crossPostText = LocalStrings.current.createPostCrossPostText
|
||||||
@ -204,9 +205,8 @@ class CreatePostScreen(
|
|||||||
model.effects
|
model.effects
|
||||||
.onEach { effect ->
|
.onEach { effect ->
|
||||||
when (effect) {
|
when (effect) {
|
||||||
is CreatePostMviModel.Effect.Failure -> {
|
is CreatePostMviModel.Effect.Failure ->
|
||||||
snackbarHostState.showSnackbar(effect.message ?: genericError)
|
snackbarHostState.showSnackbar(effect.message ?: genericError)
|
||||||
}
|
|
||||||
|
|
||||||
CreatePostMviModel.Effect.Success -> {
|
CreatePostMviModel.Effect.Success -> {
|
||||||
notificationCenter.send(
|
notificationCenter.send(
|
||||||
@ -217,9 +217,11 @@ class CreatePostScreen(
|
|||||||
|
|
||||||
CreatePostMviModel.Effect.DraftSaved -> navigationCoordinator.popScreen()
|
CreatePostMviModel.Effect.DraftSaved -> navigationCoordinator.popScreen()
|
||||||
|
|
||||||
CreatePostMviModel.Effect.AutoFillFailed -> {
|
CreatePostMviModel.Effect.AutoFillError ->
|
||||||
snackbarHostState.showSnackbar(genericError)
|
snackbarHostState.showSnackbar(genericError)
|
||||||
}
|
|
||||||
|
CreatePostMviModel.Effect.AutoFillEmpty ->
|
||||||
|
snackbarHostState.showSnackbar(autofillEmpty)
|
||||||
}
|
}
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
}
|
}
|
||||||
|
@ -399,12 +399,12 @@ class CreatePostViewModel(
|
|||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
updateState { it.copy(loading = true) }
|
updateState { it.copy(loading = true) }
|
||||||
val metadata = siteRepository.getMetadata(url)
|
val metadata = siteRepository.getMetadata(url)
|
||||||
val suggestedTitle = metadata?.title.takeUnless { it.isNullOrBlank() }
|
|
||||||
updateState { it.copy(loading = false) }
|
updateState { it.copy(loading = false) }
|
||||||
if (suggestedTitle == null) {
|
|
||||||
emitEffect(CreatePostMviModel.Effect.AutoFillFailed)
|
when {
|
||||||
} else {
|
metadata == null -> emitEffect(CreatePostMviModel.Effect.AutoFillError)
|
||||||
updateState { it.copy(title = suggestedTitle) }
|
metadata.title.isEmpty() -> emitEffect(CreatePostMviModel.Effect.AutoFillEmpty)
|
||||||
|
else -> updateState { it.copy(title = metadata.title) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user