Профиль, редактирование без аватара

This commit is contained in:
Халимов Рустам
2026-04-16 15:41:22 +03:00
parent 8409c51842
commit cea3f4d669
45 changed files with 1063 additions and 178 deletions

View File

@@ -4,9 +4,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
@@ -68,6 +66,11 @@ fun AppNavigation(
}
}
}
core.utils.NavEvent.Logout -> {
navController.navigate(Screen.Login.route) {
popUpTo(0) { inclusive = true }
}
}
}
}
}
@@ -83,6 +86,15 @@ fun AppNavigation(
Screen.Profile.route
)
val profileViewModel: ProfileViewModel = hiltViewModel()
val profileState by profileViewModel.state.collectAsState()
androidx.compose.runtime.LaunchedEffect(authState.isAuthenticated) {
if (authState.isAuthenticated) {
profileViewModel.loadProfile()
}
}
Scaffold(
bottomBar = {
if (showBottomBar) {
@@ -95,8 +107,8 @@ fun AppNavigation(
restoreState = true
}
},
userAvatarUrl = null,
username = "Me"
userAvatarUrl = profileState.profile?.avatarUrl,
username = profileState.profile?.displayName ?: profileState.profile?.username ?: ""
)
}
}
@@ -166,9 +178,14 @@ fun AppNavigation(
val state by viewModel.state.collectAsState()
ContactListScreen(
contacts = state.contacts,
requests = state.requests,
isLoading = state.isLoading,
onContactClick = { id -> navController.navigate(Screen.Profile.createRoute(id)) },
onSearchChange = { viewModel.onSearchChange(it) }
onSearchChange = { viewModel.onSearchChange(it) },
onAddContact = { id -> viewModel.addContact(id) },
onStartChat = { id -> viewModel.startChat(id) },
onAcceptRequest = { id -> viewModel.acceptRequest(id) },
onDeclineRequest = { id -> viewModel.declineRequest(id) }
)
}
composable(
@@ -192,17 +209,46 @@ fun AppNavigation(
)
}
composable(Screen.EditProfile.route) {
val viewModel: ProfileViewModel = hiltViewModel()
// Используем ViewModel от предыдущего экрана (Profile), чтобы данные не терялись
val profileEntry = remember(it) {
navController.getBackStackEntry(Screen.Profile.route)
}
val viewModel: ProfileViewModel = hiltViewModel(profileEntry)
val state by viewModel.state.collectAsState()
// Получаем profileId из родительского backStackEntry
val profileId = profileEntry.arguments?.getString("profileId")
androidx.compose.runtime.LaunchedEffect(state.profile) {
// Если профиль загружен (или обновился), мы можем инициализировать/обновить поля
}
val isSaving = state.isSaving
val error = state.error
// Автоматически возвращаемся назад после успешного сохранения
var wasSaving by remember { mutableStateOf(false) }
androidx.compose.runtime.LaunchedEffect(isSaving) {
if (isSaving) wasSaving = true
if (wasSaving && !isSaving && error == null) {
// Перезагружаем профиль перед возвратом
viewModel.loadProfile(profileId)
// Небольшая задержка чтобы данные обновились
kotlinx.coroutines.delay(300)
navController.popBackStack()
}
}
EditProfileScreen(
currentDisplayName = state.profile?.displayName,
currentUsername = state.profile?.username ?: "",
currentBio = state.profile?.bio,
currentBirthday = state.profile?.birthday,
currentAvatarUrl = state.profile?.avatarUrl,
onSave = { name, bio, uri ->
viewModel.updateProfile(name, bio, uri)
navController.popBackStack()
isSaving = isSaving,
error = error,
onSave = { name, bio, birthday, uri ->
viewModel.updateProfile(name, bio, birthday, uri)
},
onBack = { navController.popBackStack() }
)