auth to server-V36

This commit is contained in:
Eric85710 2026-05-02 17:12:26 +08:00
parent a9475e8c78
commit 95cbb63606
2 changed files with 38 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package com.example.login_v3.home.setting.setting_detail_page.detail_UI
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@ -24,6 +25,9 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
@ -75,6 +79,9 @@ fun Setting_profile_page(
fun Loaded_setting_profile_page(
profile: UserProfile
){
//bia info
var showDialog by remember { mutableStateOf(false) }
var tempBio by remember { mutableStateOf(profile.bio ?: "") }
Column(
modifier = Modifier.fillMaxSize()
@ -241,11 +248,24 @@ fun Loaded_setting_profile_page(
)
//intro
Text(
text = "Founder of JFF studios,Software Dev Guy,3D Artist",
fontSize = 16.sp,
color = MaterialTheme.colorScheme.onBackground
)
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp)
.clickable {
tempBio = profile.bio ?: "" // 開啟時同步目前的 bio
showDialog = true
}
.border(1.dp, Color.White.copy(alpha = 0.3f), RoundedCornerShape(8.dp))
.padding(16.dp)
) {
// 這裡改用 profile.bio
Text(
text = if (profile.bio.isNullOrBlank()) "Add a bio..." else profile.bio,
color = if (profile.bio.isNullOrBlank()) Color.Gray else Color.White
)
}
}
}
}

View file

@ -3,6 +3,7 @@ package com.example.login_v3.home.setting.setting_detail_page.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.login_v3.data.api.api_class.UserProfile
import com.example.login_v3.data.api.api_class.UserProfileUpdateRequest
import com.example.login_v3.data.repository.basic.PersonalProfileRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
@ -31,6 +32,7 @@ class PersonalProfileViewModel @Inject constructor(
fetchProfile()
}
//get profile
fun fetchProfile() {
viewModelScope.launch {
_uiState.value = ProfileUiState.Loading
@ -47,4 +49,15 @@ class PersonalProfileViewModel @Inject constructor(
}
}
}
//update profile
fun updateBio(newBio: String) {
viewModelScope.launch {
val request = UserProfileUpdateRequest(bio = newBio)
repository.patchUserProfile(request).onSuccess {
// 更新成功後,可以重新 loadProfile() 或更新本地狀態
fetchProfile()
}
}
}
}