11package com.paw.key.presentation.ui.home
22
3+ import android.util.Log
34import androidx.compose.foundation.layout.Box
45import androidx.compose.foundation.layout.Column
56import androidx.compose.foundation.layout.PaddingValues
@@ -31,6 +32,8 @@ import com.paw.key.core.util.noRippleClickable
3132import com.paw.key.presentation.ui.home.viewmodel.HomeViewModel
3233import com.paw.key.presentation.ui.signup.component.FormField
3334import com.paw.key.presentation.ui.signup.component.LocationButton
35+ import com.paw.key.presentation.ui.signup.component.LocationItem
36+ import com.paw.key.presentation.ui.signup.component.LocationItemList
3437import com.paw.key.presentation.ui.signup.component.LocationList
3538import com.paw.key.presentation.ui.signup.component.SignUpHeader
3639import com.paw.key.presentation.ui.signup.viewmodel.SignUpViewModel
@@ -52,7 +55,7 @@ private fun PreviewHomeLocationSettingScreen() {
5255fun HomeLocationSettingRoute (
5356 paddingValues : PaddingValues ,
5457 navigateUp : () -> Unit ,
55- navigateNext : () -> Unit ,
58+ navigateNext : (Int ) -> Unit ,
5659 navigateHomeLocationSetting : () -> Unit ,
5760 modifier : Modifier = Modifier ,
5861) {
@@ -70,31 +73,47 @@ fun HomeLocationSettingRoute(
7073fun HomeLocationSettingScreen (
7174 paddingValues : PaddingValues ,
7275 navigateUp : () -> Unit ,
73- navigateNext : () -> Unit ,
76+ navigateNext : (Int ) -> Unit ,
7477 navigateHomeLocationSetting : () -> Unit ,
7578 modifier : Modifier = Modifier ,
7679 viewModel : HomeViewModel = hiltViewModel(),
7780) {
7881 val state by viewModel.state.collectAsStateWithLifecycle()
82+ val regionList by viewModel.regionList.collectAsStateWithLifecycle()
83+
84+ val selectedGu = state.selectedGu
85+ val selectedDong = state.selectedDong
86+
87+ // 구 옵션들 (서버에서 받아온 구 리스트)
88+ val guOptions = regionList.map { it.gu.name }
89+
90+ // 선택된 구에 해당하는 동 옵션들
91+ val dongOptions = if (selectedGu.isNotEmpty()) {
92+ regionList.find { it.gu.name == selectedGu }?.dongs?.map {
93+ LocationItem (id = it.id, name = it.name)
94+ } ? : emptyList()
95+ } else {
96+ emptyList()
97+ }
7998
8099 Column (
81100 modifier = modifier
82101 .fillMaxSize()
102+ .padding(paddingValues)
83103 .padding(horizontal = 16 .dp)
84104 ) {
105+ // 헤더
85106 Row (
86107 modifier = Modifier
87108 .fillMaxWidth()
88109 .height(60 .dp)
89110 .padding(vertical = 16 .dp),
90111 verticalAlignment = Alignment .CenterVertically
91- )
92- {
112+ ) {
93113 Icon (
94114 imageVector = ImageVector .vectorResource(R .drawable.ic_arrow_left_black),
95115 contentDescription = " 뒤로가기" ,
96- modifier = Modifier
97- .noRippleClickable { navigateUp() }
116+ modifier = Modifier .noRippleClickable { navigateUp() }
98117 )
99118 Box (
100119 modifier = Modifier .weight(1f ),
@@ -110,49 +129,65 @@ fun HomeLocationSettingScreen(
110129
111130 Spacer (modifier = Modifier .height(27 .dp))
112131
132+ // 지역구 섹션 - 처음부터 모든 구 칩들을 보여줌
113133 FormField (
114134 label = stringResource(id = R .string.ic_onboarding_signup_main_location),
115135 content = {
116- LocationButton (
117- isEnable = state.isLocationMenuVisible,
118- location = " 강남구" ,
119- onClick = { viewModel.toggleLocationMenu() }
136+ LocationList (
137+ selected = selectedGu,
138+ locations = guOptions,
139+ onLocationSelected = { guName ->
140+ val selectedGuItem = regionList.find { it.gu.name == guName }
141+ selectedGuItem?.let {
142+ viewModel.onGuSelected(it.gu.name, it.gu.id)
143+ }
144+ }
120145 )
121146 }
122147 )
123148
124149 Spacer (modifier = Modifier .height(46 .dp))
125150
126- FormField (
127- label = stringResource(id = R .string.ic_onboarding_signup_sub_location),
128- content = {
129- if (state.isLocationMenuVisible) {
130- LocationList (
131- selected = state.selectedLocation,
132- locations = listOf (" 개포동" , " 논현동" , " 뭔동" , " 동동동" , " 스꾸삐" , " 4글자유" ),
133- onLocationSelected = { location ->
134- viewModel.selectLocation(location)
151+ // 동 선택 섹션 (구가 선택되었을 때만 표시)
152+ if (selectedGu.isNotEmpty()) {
153+ FormField (
154+ label = stringResource(id = R .string.ic_onboarding_signup_sub_location),
155+ content = {
156+ LocationItemList (
157+ selected = selectedDong,
158+ locations = dongOptions,
159+ onLocationSelected = { locationItem ->
160+ viewModel.onDongSelected(locationItem.name, locationItem.id)
135161 }
136162 )
137163 }
138- }
139- )
164+ )
165+ }
140166
141167 Spacer (modifier = Modifier .weight(1f ))
142168
143- val isFormValid = state.selectedLocation.isNotEmpty()
169+ // 완료 버튼
170+ val isFormValid = selectedGu.isNotEmpty() && selectedDong.isNotEmpty()
144171
145172 PawkeyButton (
146173 text = stringResource(id = R .string.ic_onboarding_signup_button),
147174 enabled = isFormValid,
148175 onClick = {
149176 if (isFormValid) {
150- navigateNext()
177+ viewModel.patchRegion(
178+ userId = 2 ,
179+ onSuccess = {
180+ val selectedDongId = state.selectedDongId
181+ navigateNext(selectedDongId)
182+ },
183+ onFailure = { message ->
184+ Log .e(" HomeScreen" , " 지역 설정 실패: $message " )
185+ }
186+ )
151187 }
152188 }
153189 )
154190
155191 Spacer (modifier = Modifier .height(46 .dp))
156192 }
157- }
158-
193+ }
0 commit comments