Skip to content

Commit

Permalink
feat/#8: SignUpScreen에서 networkState, intent 처리, 회원가입 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
kangyein9892 committed Nov 15, 2024
1 parent b5682fb commit d4b7e5e
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.launch
import org.sopt.and.presentation.R
import org.sopt.and.presentation.component.CloseTopBar
import org.sopt.and.presentation.component.DividerWithText
import org.sopt.and.presentation.component.InfoWithText
import org.sopt.and.presentation.component.OtherServiceIconRow
import org.sopt.and.presentation.component.WavveActionTextField
import org.sopt.and.presentation.component.WavveTextField
import org.sopt.and.presentation.delegate.NetworkState
import org.sopt.and.presentation.extension.noRippleClickable
import org.sopt.and.presentation.sign.signup.intent.SignUpSideEffect
import org.sopt.and.presentation.sign.signup.viewmodel.SignUpViewModel
Expand All @@ -51,7 +55,7 @@ fun SignUpScreen(

val state by viewModel.state.collectAsStateWithLifecycle()

val context = rememberUpdatedState(LocalContext.current).value
val context = LocalContext.current
val snackBarHostState = remember { SnackbarHostState() }

LaunchedEffect(viewModel.intent) {
Expand All @@ -63,10 +67,18 @@ fun SignUpScreen(
is SignUpSideEffect.SnackBar -> {
snackBarHostState.showSnackbar(context.getString(intent.message))
}

is SignUpSideEffect.SnackBarText -> {
snackBarHostState.showSnackbar(intent.message)
}
}
}
}

LaunchedEffect(viewModel.networkState) {
collectNetworkState(viewModel)
}

Column(
modifier = modifier
.fillMaxSize()
Expand Down Expand Up @@ -174,7 +186,7 @@ fun SignUpScreen(
.background(color = ThirdGrey)
.noRippleClickable(
onClick = {
viewModel.onSignUpButtonClick()
viewModel.signUp()
}
)
.padding(vertical = 12.dp)
Expand All @@ -190,6 +202,22 @@ fun SignUpScreen(
}
}

private suspend fun collectNetworkState(viewModel: SignUpViewModel) {
viewModel.networkState.collect { networkState ->
when(networkState){
is NetworkState.Loading -> {
// TODO 로딩 추가
}
is NetworkState.Error -> {
viewModel.handleSignUpIntentError(networkState.title + networkState.msg)
}
is NetworkState.Success -> {
viewModel.handleSignUpIntentSuccess()
}
}
}
}

@Preview
@Composable
fun SignUpScreenPreview() {
Expand Down

0 comments on commit d4b7e5e

Please sign in to comment.