auth to server-V83
This commit is contained in:
parent
5c4af08bff
commit
17b2e9d272
3 changed files with 36 additions and 7 deletions
|
|
@ -109,7 +109,9 @@ data class UserDetail(
|
|||
val status: String?,
|
||||
|
||||
@Json(name = "created_at")
|
||||
val createdAt: String
|
||||
val createdAt: String,
|
||||
|
||||
val isRequestSent: Boolean = false
|
||||
)
|
||||
|
||||
val UserDetail.fullSearchedAvatarUrl: Any
|
||||
|
|
|
|||
|
|
@ -432,8 +432,23 @@ fun SearchResultRow(
|
|||
Text("@${user.username}", style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
|
||||
// 判斷是否顯示勾勾
|
||||
if (user.isRequestSent) {
|
||||
// 已發送狀態:綠色勾勾,且按鈕不具備點擊功能
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = "已發送",
|
||||
tint = Color(0xFF4CAF50), // 綠色
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
} else {
|
||||
// 尚未發送:加好友按鈕
|
||||
IconButton(onClick = onAddFriend) {
|
||||
Icon(Icons.Default.PersonAdd, contentDescription = "加好友")
|
||||
Icon(
|
||||
imageVector = Icons.Default.PersonAdd,
|
||||
contentDescription = "加好友"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class ContactListViewModel @Inject constructor(
|
|||
//add friends
|
||||
fun sendFriendRequest(friendId: String) {
|
||||
viewModelScope.launch {
|
||||
// 1. 顯示載入中,並清除舊的錯誤訊息
|
||||
// 1. 顯示載入中
|
||||
_uiState.update { it.copy(isLoading = true, error = null) }
|
||||
|
||||
// 2. 呼叫 Repository
|
||||
|
|
@ -104,9 +104,21 @@ class ContactListViewModel @Inject constructor(
|
|||
|
||||
// 3. 處理結果
|
||||
result.onSuccess {
|
||||
// 發送成功後,通常會重新整理資料
|
||||
// 這樣如果你的「待處理清單」包含「已發送的申請」,畫面就會更新
|
||||
refreshAll()
|
||||
// 關鍵修改:更新搜尋結果清單中的 isRequestSent 狀態
|
||||
_uiState.update { state ->
|
||||
val updatedSearchResults = state.searchResults.map { user ->
|
||||
if (user.id == friendId) {
|
||||
user.copy(isRequestSent = true) // 找到目標,標記為已發送
|
||||
} else {
|
||||
user
|
||||
}
|
||||
}
|
||||
state.copy(
|
||||
isLoading = false,
|
||||
searchResults = updatedSearchResults
|
||||
)
|
||||
}
|
||||
// refreshAll()
|
||||
}.onFailure { error ->
|
||||
Log.e("DEBUG_API", "發送好友申請錯誤: ${error.message}")
|
||||
_uiState.update {
|
||||
|
|
|
|||
Loading…
Reference in a new issue