auth to server-V84
This commit is contained in:
parent
17b2e9d272
commit
0b8cc652ee
2 changed files with 80 additions and 112 deletions
|
|
@ -110,6 +110,9 @@ fun Message_contact_list(
|
|||
)
|
||||
}
|
||||
|
||||
//is Searching or not
|
||||
if (uiState.isSearching) {
|
||||
|
||||
// --- 搜尋結果區塊 (僅在有結果時顯示) ---
|
||||
if (uiState.searchResults.isNotEmpty()) {
|
||||
item {
|
||||
|
|
@ -127,9 +130,11 @@ fun Message_contact_list(
|
|||
onAddFriend = { contactListViewModel.sendFriendRequest(user.id) }
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider(modifier = Modifier.padding(vertical = 12.dp)) }
|
||||
}
|
||||
|
||||
|
||||
//if not searching then display friends list
|
||||
}else {
|
||||
// --- 區塊一:待處理好友 (只有在有資料時才顯示) ---
|
||||
if (uiState.pendingRequests.isNotEmpty()) {
|
||||
item {
|
||||
|
|
@ -185,6 +190,11 @@ fun Message_contact_list(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -332,53 +342,6 @@ fun PendingFriendRow(
|
|||
)
|
||||
}
|
||||
|
||||
//add friends
|
||||
@Composable
|
||||
fun AddUserBar(
|
||||
isLoading: Boolean,
|
||||
onSendRequest: (String) -> Unit
|
||||
) {
|
||||
var userIdText by remember { mutableStateOf("") }
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = userIdText,
|
||||
onValueChange = { userIdText = it },
|
||||
label = { Text("輸入好友 ID") },
|
||||
modifier = Modifier.weight(1f),
|
||||
singleLine = true,
|
||||
enabled = !isLoading
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
if (userIdText.isNotBlank()) {
|
||||
onSendRequest(userIdText)
|
||||
userIdText = "" // 發送後清空輸入框
|
||||
}
|
||||
},
|
||||
enabled = !isLoading && userIdText.isNotBlank()
|
||||
) {
|
||||
if (isLoading) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(16.dp),
|
||||
color = MaterialTheme.colorScheme.onPrimary,
|
||||
strokeWidth = 2.dp
|
||||
)
|
||||
} else {
|
||||
Text("新增")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//search user
|
||||
@Composable
|
||||
|
|
|
|||
|
|
@ -22,10 +22,12 @@ data class ContactUiState(
|
|||
val isLoading: Boolean = false,
|
||||
val friends: List<Friend> = emptyList(),
|
||||
val pendingRequests: List<PendingFriendApiModel> = emptyList(),
|
||||
// 新增:搜尋結果與關鍵字
|
||||
val searchResults: List<UserDetail> = emptyList(),
|
||||
val searchQuery: String = "",
|
||||
val error: String? = null
|
||||
val error: String? = null,
|
||||
|
||||
//UI state
|
||||
val isSearching: Boolean = false
|
||||
)
|
||||
@HiltViewModel
|
||||
class ContactListViewModel @Inject constructor(
|
||||
|
|
@ -136,7 +138,10 @@ class ContactListViewModel @Inject constructor(
|
|||
//search user
|
||||
fun onSearchQueryChanged(newQuery: String) {
|
||||
// 1. 即時更新文字輸入,確保 UI TextField 顯示順暢
|
||||
_uiState.update { it.copy(searchQuery = newQuery) }
|
||||
_uiState.update { it.copy(
|
||||
searchQuery = newQuery,
|
||||
isSearching = newQuery.isNotBlank()
|
||||
) }
|
||||
}
|
||||
|
||||
fun performSearch() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue