@@ -46,12 +46,21 @@ fun GroupSearchScreen(
4646 var searchText by rememberSaveable { mutableStateOf(" " ) }
4747 var isSearched by rememberSaveable { mutableStateOf(false ) }
4848 var selectedGenreIndex by rememberSaveable { mutableIntStateOf(- 1 ) }
49- var selectedSortOption by rememberSaveable { mutableStateOf( " 마감임박순 " ) }
49+ var selectedSortOptionIndex by rememberSaveable { mutableIntStateOf( 0 ) }
5050 val focusRequester = remember { FocusRequester () }
5151 val focusManager = LocalFocusManager .current
5252
53- val genres = listOf (" 문학" , " 과학·IT" , " 사회과학" , " 인문학" , " 예술" )
54- val sortOptions = listOf (" 마감임박순" , " 최신순" , " 참여많은순" )
53+ val genres = listOf (
54+ stringResource(R .string.literature),
55+ stringResource(R .string.science_it),
56+ stringResource(R .string.social_science),
57+ stringResource(R .string.humanities),
58+ stringResource(R .string.art)
59+ )
60+ val sortOptions = listOf (
61+ stringResource(R .string.group_filter_deadline),
62+ stringResource(R .string.group_filter_popular)
63+ )
5564
5665 val liveFilteredRoomList by remember(searchText) {
5766 derivedStateOf {
@@ -62,18 +71,22 @@ fun GroupSearchScreen(
6271 }
6372 }
6473
65- val filteredRoomList by remember(searchText, selectedGenreIndex, selectedSortOption, isSearched) {
74+ val filteredRoomList by remember(
75+ searchText,
76+ selectedGenreIndex,
77+ selectedSortOptionIndex,
78+ isSearched
79+ ) {
6680 derivedStateOf {
6781 if (! isSearched) emptyList()
6882 else {
6983 val filtered = roomList.filter { room ->
7084 (searchText.isBlank() || room.title.contains(searchText, ignoreCase = true )) &&
7185 (selectedGenreIndex == - 1 || room.genreIndex == selectedGenreIndex)
7286 }
73- when (selectedSortOption) {
74- " 마감임박순" -> filtered.sortedBy { it.endDate }
75- " 최신순" -> filtered // TODO: 생성일 기준 정렬 필요
76- " 참여많은순" -> filtered.sortedByDescending { it.participants }
87+ when (selectedSortOptionIndex) {
88+ 0 -> filtered.sortedBy { it.endDate } // 마감임박순
89+ 1 -> filtered.sortedByDescending { it.participants } // 인기순
7790 else -> filtered
7891 }
7992 }
@@ -131,6 +144,7 @@ fun GroupSearchScreen(
131144 onRemove = {}
132145 )
133146 }
147+
134148 searchText.isBlank() && ! isSearched && recentSearches.isNotEmpty() -> {
135149 GroupRecentSearch (
136150 recentSearches = recentSearches,
@@ -143,6 +157,7 @@ fun GroupSearchScreen(
143157 }
144158 )
145159 }
160+
146161 searchText.isNotBlank() && ! isSearched -> {
147162 if (liveFilteredRoomList.isEmpty()) {
148163 GroupEmptyResult (
@@ -155,6 +170,7 @@ fun GroupSearchScreen(
155170 )
156171 }
157172 }
173+
158174 isSearched -> {
159175 GroupFilteredSearchResult (
160176 genres = genres,
@@ -173,9 +189,11 @@ fun GroupSearchScreen(
173189 modifier = Modifier
174190 .align(Alignment .TopEnd )
175191 .padding(top = 176 .dp, end = 20 .dp),
176- selectedOption = selectedSortOption ,
192+ selectedOption = sortOptions[selectedSortOptionIndex] ,
177193 options = sortOptions,
178- onOptionSelected = { selectedSortOption = it }
194+ onOptionSelected = { selected ->
195+ selectedSortOptionIndex = sortOptions.indexOf(selected)
196+ }
179197 )
180198 }
181199 }
@@ -190,8 +208,26 @@ fun PreviewGroupSearchScreen() {
190208 roomList = listOf (
191209 GroupCardItemRoomData (" aaa" , 22 , 30 , true , 3 , R .drawable.bookcover_sample, 0 ),
192210 GroupCardItemRoomData (" abc" , 15 , 20 , true , 7 , R .drawable.bookcover_sample, 1 , true ),
193- GroupCardItemRoomData (" abcd" , 10 , 15 , true , 5 , R .drawable.bookcover_sample, 2 , true ),
194- GroupCardItemRoomData (" abcde" , 8 , 12 , false , 2 , R .drawable.bookcover_sample, 3 , true ),
211+ GroupCardItemRoomData (
212+ " abcd" ,
213+ 10 ,
214+ 15 ,
215+ true ,
216+ 5 ,
217+ R .drawable.bookcover_sample,
218+ 2 ,
219+ true
220+ ),
221+ GroupCardItemRoomData (
222+ " abcde" ,
223+ 8 ,
224+ 12 ,
225+ false ,
226+ 2 ,
227+ R .drawable.bookcover_sample,
228+ 3 ,
229+ true
230+ ),
195231 GroupCardItemRoomData (" abcdef" , 18 , 25 , true , 4 , R .drawable.bookcover_sample, 4 ),
196232 GroupCardItemRoomData (" abcdefg" , 12 , 20 , true , 1 , R .drawable.bookcover_sample, 0 ),
197233 GroupCardItemRoomData (" abcdefgh" , 10 , 14 , true , 6 , R .drawable.bookcover_sample, 1 )
0 commit comments