Resolve #251
This commit is contained in:
1 parent
1d12a16e3d
commit
c2a2dafb47
2 files changed
+17
-12
No files matched your search
@@ -58,7 +58,6 @@ import androidx.compose.material3.TextButton
|
|||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.currentRecomposeScope
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -110,6 +109,7 @@ import com.ramcosta.composedestinations.annotation.Destination
|
|||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import moe.tarsin.coroutines.replace
|
||||||
import moe.tarsin.coroutines.runSuspendCatching
|
import moe.tarsin.coroutines.runSuspendCatching
|
||||||
import rikka.core.res.resolveColor
|
import rikka.core.res.resolveColor
|
||||||
|
|
||||||
@@ -281,8 +281,6 @@ fun GalleryCommentsScreen(galleryDetail: GalleryDetail, navigator: NavController
|
|||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
items(comments.comments) { item ->
|
items(comments.comments) { item ->
|
||||||
val recomposeScope = currentRecomposeScope
|
|
||||||
|
|
||||||
suspend fun Context.voteComment(comment: GalleryComment, isUp: Boolean) {
|
suspend fun Context.voteComment(comment: GalleryComment, isUp: Boolean) {
|
||||||
galleryDetail.runSuspendCatching {
|
galleryDetail.runSuspendCatching {
|
||||||
EhEngine.voteComment(apiUid, apiKey, gid, token, comment.id, if (isUp) 1 else -1)
|
EhEngine.voteComment(apiUid, apiKey, gid, token, comment.id, if (isUp) 1 else -1)
|
||||||
@@ -291,15 +289,13 @@ fun GalleryCommentsScreen(galleryDetail: GalleryDetail, navigator: NavController
|
|||||||
if (isUp) (if (0 != result.vote) R.string.vote_up_successfully else R.string.cancel_vote_up_successfully) else if (0 != result.vote) R.string.vote_down_successfully else R.string.cancel_vote_down_successfully,
|
if (isUp) (if (0 != result.vote) R.string.vote_up_successfully else R.string.cancel_vote_up_successfully) else if (0 != result.vote) R.string.vote_down_successfully else R.string.cancel_vote_down_successfully,
|
||||||
BaseScene.LENGTH_SHORT,
|
BaseScene.LENGTH_SHORT,
|
||||||
)
|
)
|
||||||
comment.score = result.score
|
val newComment = comment.copy(
|
||||||
if (isUp) {
|
score = result.score,
|
||||||
comment.voteUpEd = 0 != result.vote
|
voteUpEd = 0 != result.vote && isUp,
|
||||||
comment.voteDownEd = false
|
voteDownEd = 0 != result.vote && !isUp,
|
||||||
} else {
|
)
|
||||||
comment.voteDownEd = 0 != result.vote
|
val list = comments.comments.replace(comment, newComment)
|
||||||
comment.voteUpEd = false
|
comments = comments.copy(comments = list)
|
||||||
}
|
|
||||||
recomposeScope.invalidate()
|
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
findActivity<MainActivity>().showTip(R.string.vote_failed, BaseScene.LENGTH_LONG)
|
findActivity<MainActivity>().showTip(R.string.vote_failed, BaseScene.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package moe.tarsin.coroutines
|
||||||
|
|
||||||
|
fun <T> List<T>.replace(toRemove: T, toAdd: T) = map {
|
||||||
|
if (it === toRemove) {
|
||||||
|
toAdd
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user