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?,
|
val status: String?,
|
||||||
|
|
||||||
@Json(name = "created_at")
|
@Json(name = "created_at")
|
||||||
val createdAt: String
|
val createdAt: String,
|
||||||
|
|
||||||
|
val isRequestSent: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val UserDetail.fullSearchedAvatarUrl: Any
|
val UserDetail.fullSearchedAvatarUrl: Any
|
||||||
|
|
|
||||||
|
|
@ -432,8 +432,23 @@ fun SearchResultRow(
|
||||||
Text("@${user.username}", style = MaterialTheme.typography.bodySmall)
|
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) {
|
IconButton(onClick = onAddFriend) {
|
||||||
Icon(Icons.Default.PersonAdd, contentDescription = "加好友")
|
Icon(
|
||||||
|
imageVector = Icons.Default.PersonAdd,
|
||||||
|
contentDescription = "加好友"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ class ContactListViewModel @Inject constructor(
|
||||||
//add friends
|
//add friends
|
||||||
fun sendFriendRequest(friendId: String) {
|
fun sendFriendRequest(friendId: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// 1. 顯示載入中,並清除舊的錯誤訊息
|
// 1. 顯示載入中
|
||||||
_uiState.update { it.copy(isLoading = true, error = null) }
|
_uiState.update { it.copy(isLoading = true, error = null) }
|
||||||
|
|
||||||
// 2. 呼叫 Repository
|
// 2. 呼叫 Repository
|
||||||
|
|
@ -104,9 +104,21 @@ class ContactListViewModel @Inject constructor(
|
||||||
|
|
||||||
// 3. 處理結果
|
// 3. 處理結果
|
||||||
result.onSuccess {
|
result.onSuccess {
|
||||||
// 發送成功後,通常會重新整理資料
|
// 關鍵修改:更新搜尋結果清單中的 isRequestSent 狀態
|
||||||
// 這樣如果你的「待處理清單」包含「已發送的申請」,畫面就會更新
|
_uiState.update { state ->
|
||||||
refreshAll()
|
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 ->
|
}.onFailure { error ->
|
||||||
Log.e("DEBUG_API", "發送好友申請錯誤: ${error.message}")
|
Log.e("DEBUG_API", "發送好友申請錯誤: ${error.message}")
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue