Skip to content

Commit

Permalink
[feat/#10] 서버통신 방식을 변경하고, 검색하기와 회원정보변경 페이지를 구현합니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
SYAAINN committed Dec 2, 2024
1 parent 663c08d commit d1e6549
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AuthViewModel @Inject constructor(
_signInState.value = result.fold(
onSuccess = { token ->
tokenRepository.setToken(token.token)
Log.d("token","토큰 저장 완료! 저장값은 ${token.token} 입니다.")
Log.d("token", "토큰 저장 완료! 저장값은 ${token.token} 입니다.")
SignInState.Success(token)
},
onFailure = {
Expand All @@ -46,11 +46,13 @@ class AuthViewModel @Inject constructor(
fun validateSignUp(username: String, password: String, hobby: String) {
_signUpState.value = SignUpState.Loading
viewModelScope.launch {
val result = authRepository.registerUser(user = User(
username = username,
password = password,
hobby = hobby
))
val result = authRepository.registerUser(
user = User(
username = username,
password = password,
hobby = hobby
)
)
_signUpState.value = result.fold(
onSuccess = {
SignUpState.Success(it)
Expand All @@ -61,4 +63,12 @@ class AuthViewModel @Inject constructor(
)
}
}

fun resetSignInState() {
_signInState.value = SignInState.Idle
}

fun resetSignUpState() {
_signUpState.value = SignUpState.Idle
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import org.sopt.and.R
import org.sopt.and.presentation.ui.auth.component.AuthTextField
import org.sopt.and.presentation.ui.common.WavveTextField
import org.sopt.and.presentation.ui.auth.component.SocialPlatformIconRow
import org.sopt.and.presentation.ui.auth.component.SocialPlatformList
import org.sopt.and.presentation.util.showToast
Expand All @@ -53,6 +53,7 @@ fun SignInRoute(

SignInScreen(
signInState = signInState,
resetSignInState = { authViewModel.resetSignInState() },
onSignUpClick = navigateToSignUp,
onSignInClick = { email, password -> authViewModel.validateSignIn(email, password) },
navigateToMain = navigateToMain
Expand All @@ -62,6 +63,7 @@ fun SignInRoute(
@Composable
fun SignInScreen(
signInState: SignInState,
resetSignInState: () -> Unit,
onSignUpClick: () -> Unit,
onSignInClick: (String, String) -> Unit,
navigateToMain: () -> Unit,
Expand Down Expand Up @@ -102,7 +104,7 @@ fun SignInScreen(

Spacer(Modifier.height(40.dp))

AuthTextField(
WavveTextField(
value = inputEmail,
onValueChange = { newValue -> inputEmail = newValue },
modifier = Modifier
Expand All @@ -112,7 +114,7 @@ fun SignInScreen(
hint = "이메일 주소 또는 아이디"
)
Spacer(Modifier.height(4.dp))
AuthTextField(
WavveTextField(
value = inputPassword,
onValueChange = { newValue -> inputPassword = newValue },
modifier = Modifier
Expand Down Expand Up @@ -215,20 +217,24 @@ fun SignInScreen(

Spacer(modifier = Modifier.weight(1f))

when(signInState) {
when (signInState) {
is SignInState.Success -> {
showToast(
context = context,
message = "로그인에 성공했습니다."
)
resetSignInState()
navigateToMain()
}

is SignInState.Failure -> {
showToast(
context = context,
message = "아이디와 비밃번호를 다시 확인해주세요."
)
resetSignInState()
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import org.sopt.and.R
import org.sopt.and.presentation.ui.auth.component.AuthTextField
import org.sopt.and.presentation.ui.common.WavveTextField
import org.sopt.and.presentation.ui.auth.component.SocialPlatformIconRow
import org.sopt.and.presentation.ui.auth.component.SocialPlatformList
import org.sopt.and.presentation.util.showToast
Expand All @@ -51,6 +51,7 @@ fun SignUpRoute(

SignUpScreen(
signUpState = signUpState,
resetSignUpState = { authViewModel.resetSignUpState() },
onSignUpClick = { username, password, hobby -> authViewModel.validateSignUp(username, password, hobby)},
navigateToSignIn = navigateToSignIn,
onCancelClick = navigateToBack,
Expand All @@ -60,6 +61,7 @@ fun SignUpRoute(
@Composable
fun SignUpScreen(
signUpState: SignUpState,
resetSignUpState: () -> Unit,
onSignUpClick: (String, String, String) -> Unit,
navigateToSignIn: () -> Unit,
onCancelClick: () -> Unit,
Expand Down Expand Up @@ -131,7 +133,7 @@ fun SignUpScreen(

Spacer(modifier = Modifier.height(18.dp))

AuthTextField(
WavveTextField(
value = inputEmail,
onValueChange = { newValue -> inputEmail = newValue },
modifier = Modifier
Expand Down Expand Up @@ -163,7 +165,7 @@ fun SignUpScreen(

Spacer(modifier = Modifier.height(10.dp))

AuthTextField(
WavveTextField(
value = inputPassword,
onValueChange = { newValue -> inputPassword = newValue },
modifier = Modifier
Expand Down Expand Up @@ -194,7 +196,7 @@ fun SignUpScreen(
)
}

AuthTextField(
WavveTextField(
value = inputHobby,
onValueChange = { newValue -> inputHobby = newValue },
modifier = Modifier
Expand Down Expand Up @@ -309,12 +311,14 @@ fun SignUpScreen(
message = "회원가입에 성공했습니다. 유저번호는 ${signUpState.result.no}입니다."
)
navigateToSignIn()
resetSignUpState()
}
is SignUpState.Failure -> {
showToast(
context = context,
message = "회원가입에 실패했습니다. 형식을 다시 확인해주세요."
)
resetSignUpState()
}
else -> {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import org.sopt.and.presentation.ui.main.screen.HomeScreen
import org.sopt.and.presentation.ui.main.screen.HomeRoute
import org.sopt.and.presentation.ui.main.screen.MainRoute
import org.sopt.and.presentation.ui.main.screen.MyPageScreen
import org.sopt.and.presentation.ui.main.screen.SearchScreen
import org.sopt.and.presentation.ui.main.screen.MyPageRoute
import org.sopt.and.presentation.ui.main.screen.SearchRoute
import org.sopt.and.presentation.ui.main.screen.SettingRoute
import org.sopt.and.presentation.ui.navigation.WavveRoute

fun NavGraphBuilder.mainNavGraph(
Expand All @@ -19,19 +20,22 @@ fun NavGraphBuilder.mainNavGraph(
) {
composable(route = WavveRoute.MAIN) {
MainRoute(
navigateToHome = { navController.navigateToHome() },
navigateToSearch = { navController.navigateToSearch() },
navigateToMy = { navController.navigateToMy() }
navigateToSetting = { navController.navigateToSetting() }
)
}
composable(route = WavveRoute.HOME) {
HomeScreen()
HomeRoute()
}
composable(route = WavveRoute.SEARCH) {
SearchScreen()
SearchRoute()
}
composable(route = WavveRoute.MY) {
MyPageScreen(userHobby = "")
MyPageRoute(
navigateToSetting = { navController.navigateToSetting() }
)
}
composable(route = WavveRoute.SETTING) {
SettingRoute()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ fun NavController.navigateToSearch() {

fun NavController.navigateToMy() {
navigate(WavveRoute.MY)
}

fun NavController.navigateToSetting() {
navigate(WavveRoute.SETTING)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.delay
import org.sopt.and.R
import org.sopt.and.presentation.ui.main.component.CategoryItem
Expand All @@ -41,6 +42,13 @@ import org.sopt.and.presentation.ui.main.component.editorRecommendationImages
import org.sopt.and.presentation.ui.main.component.todayTop20Images
import org.sopt.and.ui.theme.ANDANDROIDTheme

@Composable
fun HomeRoute(
mainViewModel: MainViewModel = hiltViewModel()
) {
HomeScreen()
}

@Composable
fun HomeScreen() {
LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,16 @@ import org.sopt.and.ui.theme.ANDANDROIDTheme
@Composable
fun MainRoute(
mainViewModel: MainViewModel = hiltViewModel(),
navigateToHome: () -> Unit,
navigateToSearch: () -> Unit,
navigateToMy: () -> Unit,
navigateToSetting: () -> Unit
) {
val userHobbyState by mainViewModel.userHobbyState.collectAsState()

LaunchedEffect(Unit) {
mainViewModel.getUserHobby()
}

MainScreen(
userHobbyState = userHobbyState,
navigateToSetting = navigateToSetting
)
}

@Composable
fun MainScreen(
userHobbyState: UserHobbyState,
navigateToSetting: ()-> Unit
) {
var selectedTab by remember { mutableStateOf<MainTabList>(MainTabList.HOME) }
val onTabSelected: (MainTabList) -> Unit = { tab ->
Expand Down Expand Up @@ -144,22 +136,11 @@ fun MainScreen(
.padding(innerPadding)
) {
when (selectedTab) {
MainTabList.HOME -> HomeScreen()
MainTabList.SEARCH -> SearchScreen()
MainTabList.MY -> {
when (userHobbyState) {
is UserHobbyState.Success -> {
val userHobby = userHobbyState.hobby
MyPageScreen(userHobby = userHobby)
}

is UserHobbyState.Failure -> {
val errorMessage = userHobbyState.errorMessage
}

else -> {}
}
}
MainTabList.HOME -> HomeRoute()
MainTabList.SEARCH -> SearchRoute()
MainTabList.MY -> MyPageRoute(
navigateToSetting = navigateToSetting
)
}
}

Expand Down
Loading

0 comments on commit d1e6549

Please sign in to comment.