Refactor: 优化个人主页和账户主页帖子加载逻辑
- 统一MyProfileViewModel和AccountProfileViewModel中的帖子加载逻辑,使用一致的pageSize。 - 在ProfileWrap和AccountProfileV2中传递正确的postCount。 - 在ProfileV3中改进了加载更多帖子的触发条件,确保在有更多数据时才触发加载。 - 修复了注册页面勾选协议和促销选项后,错误状态未清除的问题。 - 为DataLoader和ProfileV3中的滚动加载逻辑添加了详细日志,方便调试。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.aiosman.ravenow.ui.profile
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
@@ -8,6 +9,7 @@ import com.aiosman.ravenow.exp.viewModelFactory
|
||||
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
|
||||
import com.aiosman.ravenow.ui.index.tabs.profile.ProfileV3
|
||||
import com.aiosman.ravenow.ui.navigateToChat
|
||||
import com.aiosman.ravenow.ui.navigateToPost
|
||||
|
||||
@Composable
|
||||
fun AccountProfileV2(id: String){
|
||||
@@ -27,6 +29,17 @@ fun AccountProfileV2(id: String){
|
||||
moments = model.moments,
|
||||
profile = model.profile,
|
||||
isSelf = isSelf,
|
||||
postCount = model.momentLoader.total,
|
||||
onLoadMore = {
|
||||
Log.d("AccountProfileV2", "onLoadMore被调用")
|
||||
model.loadMoreMoment()
|
||||
},
|
||||
onLike = { moment ->
|
||||
// TODO: 实现点赞逻辑
|
||||
},
|
||||
onComment = { moment ->
|
||||
navController.navigateToPost(moment.id)
|
||||
},
|
||||
onChatClick = {
|
||||
model.profile?.let {
|
||||
navController.navigateToChat(it.id.toString())
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.aiosman.ravenow.ui.profile
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -25,6 +26,7 @@ class AccountProfileViewModel : ViewModel() {
|
||||
var profile by mutableStateOf<AccountProfileEntity?>(null)
|
||||
var refreshing by mutableStateOf(false)
|
||||
var momentLoader = MomentLoader().apply {
|
||||
pageSize = 20 // 设置与后端一致的页面大小
|
||||
onListChanged = {
|
||||
moments = it
|
||||
}
|
||||
@@ -58,6 +60,21 @@ class AccountProfileViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadMoreMoment() {
|
||||
viewModelScope.launch {
|
||||
profile?.let { profileData ->
|
||||
try {
|
||||
Log.d("AccountProfileViewModel", "loadMoreMoment: 开始加载更多, 当前moments数量: ${moments.size}, hasNext: ${momentLoader.hasNext}")
|
||||
momentLoader.loadMore(extra = MomentLoaderExtraArgs(authorId = profileData.id))
|
||||
Log.d("AccountProfileViewModel", "loadMoreMoment: 加载完成, 新的moments数量: ${moments.size}")
|
||||
} catch (e: Exception) {
|
||||
Log.e("AccountProfileViewModel", "loadMoreMoment: ", e)
|
||||
}
|
||||
} ?: Log.w("AccountProfileViewModel", "loadMoreMoment: profile为null,无法加载更多")
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onFollowChangeEvent(event: FollowChangeEvent) {
|
||||
if (event.userId == profile?.id) {
|
||||
|
||||
Reference in New Issue
Block a user