Skip to content

Commit

Permalink
[fix/#110] let 스코프 함수 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokwanhee committed Aug 24, 2024
1 parent 1ffb6a2 commit d51594b
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun StadiumDetailPictureScreen(
DetailReviewEntryPoint.TOP_REVIEW.name -> {
StadiumDetailPictureTopScreen(
context = context,
reviews = reviews.value,
uiState = reviews.value,
reviewId = reviewId,
reviewIndex = reviewIndex,
bottomPadding = bottomPadding,
Expand All @@ -46,7 +46,7 @@ fun StadiumDetailPictureScreen(
DetailReviewEntryPoint.MAIN_REVIEW.name -> {
StadiumDetailPictureMainScreen(
context = context,
reviews = reviews.value,
uiState = reviews.value,
reviewId = reviewId,
reviewIndex = reviewIndex,
bottomPadding = bottomPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,75 @@ fun StadiumDetailPictureTopScreen(
reviewIndex: Int,
bottomPadding: Float,
isFirstLike: Boolean,
reviews: StadiumDetailUiState,
uiState: StadiumDetailUiState,
modifier: Modifier = Modifier,
stadiumDetailViewModel: StadiumDetailViewModel = viewModel(),
onClickLike: () -> Unit = {},
onClickScrap: (id: Long) -> Unit = {},
onClickShare: () -> Unit = {}
) {
reviews.let { uiState ->
when (uiState) {
is StadiumDetailUiState.ReviewsData -> {
val initPage by remember {
mutableStateOf(uiState.topReviewImages.indexOfFirst { it.id == reviewId })
}
when (uiState) {
is StadiumDetailUiState.ReviewsData -> {
val initPage by remember {
mutableStateOf(uiState.topReviewImages.indexOfFirst { it.id == reviewId })
}

val pagerState = rememberPagerState(
pageCount = { uiState.topReviewImages.size },
initialPage = initPage
)
val pagerState = rememberPagerState(
pageCount = { uiState.topReviewImages.size },
initialPage = initPage
)

var isFirstLikeState by remember {
mutableStateOf(isFirstLike)
}
var isFirstLikeState by remember {
mutableStateOf(isFirstLike)
}

var pageIndex by remember {
mutableStateOf(0)
}
var pageIndex by remember {
mutableStateOf(0)
}

LaunchedEffect(key1 = pagerState) {
snapshotFlow { pagerState.currentPage }.collect {
pageIndex = it
}
LaunchedEffect(key1 = pagerState) {
snapshotFlow { pagerState.currentPage }.collect {
pageIndex = it
}

StadiumDetailReviewViewPager(
context = context,
reviews = uiState.topReviewImages,
position = reviewIndex,
isFirstLike = isFirstLikeState,
pagerState = pagerState,
pageIndex = pageIndex,
bottomPadding = bottomPadding,
modifier = modifier,
onClickLike = { id ->
onClickLike()
isFirstLikeState = false
stadiumDetailViewModel.updateLike(id)
},
onClickScrap = onClickScrap,
onClickShare = { imagePosition ->
onClickShare()
KakaoUtils().share(
context,
seatFeed(
title = uiState.kakaoShareSeatFeedTitle(pageIndex),
description = "출처 : ${uiState.reviews[pageIndex].member.nickname}",
imageUrl = uiState.reviews[pageIndex].images[imagePosition].url,
queryParams = mapOf(
"stadiumId" to stadiumDetailViewModel.stadiumId.toString(),
"blockCode" to stadiumDetailViewModel.blockCode
)
),
onSuccess = { sharingIntent ->
context.startActivity(sharingIntent)
}
)
}
)
}

else -> Unit
StadiumDetailReviewViewPager(
context = context,
reviews = uiState.topReviewImages,
position = reviewIndex,
isFirstLike = isFirstLikeState,
pagerState = pagerState,
pageIndex = pageIndex,
bottomPadding = bottomPadding,
modifier = modifier,
onClickLike = { id ->
onClickLike()
isFirstLikeState = false
stadiumDetailViewModel.updateLike(id)
},
onClickScrap = onClickScrap,
onClickShare = { imagePosition ->
onClickShare()
KakaoUtils().share(
context,
seatFeed(
title = uiState.kakaoShareSeatFeedTitle(pageIndex),
description = "출처 : ${uiState.reviews[pageIndex].member.nickname}",
imageUrl = uiState.reviews[pageIndex].images[imagePosition].url,
queryParams = mapOf(
"stadiumId" to stadiumDetailViewModel.stadiumId.toString(),
"blockCode" to stadiumDetailViewModel.blockCode
)
),
onSuccess = { sharingIntent ->
context.startActivity(sharingIntent)
}
)
}
)
}

else -> Unit
}
}

Expand All @@ -113,6 +111,6 @@ private fun StadiumDetailPictureTopScreenPreview() {
reviewIndex = 0,
bottomPadding = 0f,
isFirstLike = false,
reviews = StadiumDetailUiState.Empty,
uiState = StadiumDetailUiState.Empty,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,100 +30,97 @@ fun StadiumDetailPictureMainScreen(
reviewIndex: Int,
bottomPadding: Float,
isFirstLike: Boolean,
reviews: StadiumDetailUiState,
uiState: StadiumDetailUiState,
modifier: Modifier = Modifier,
stadiumDetailViewModel: StadiumDetailViewModel = viewModel(),
onClickLike: () -> Unit = {},
onClickScrap: (id: Long) -> Unit = {},
onClickShare: () -> Unit = {}
) {
reviews.let { uiState ->
when (uiState) {
is StadiumDetailUiState.ReviewsData -> {
val visited = remember {
mutableStateListOf(
*List(uiState.reviews.size) { false }.toTypedArray()
)
}

if (uiState.reviews.size - visited.size > 0) {
visited.addAll(List(uiState.reviews.size - visited.size) { false })
}
when(uiState) {
is StadiumDetailUiState.ReviewsData -> {
val visited = remember {
mutableStateListOf(
*List(uiState.reviews.size) { false }.toTypedArray()
)
}

val initPage by remember {
mutableStateOf(uiState.reviews.indexOfFirst { it.id == reviewId })
}
if (uiState.reviews.size - visited.size > 0) {
visited.addAll(List(uiState.reviews.size - visited.size) { false })
}

val pagerState = rememberPagerState(
pageCount = { uiState.reviews.size },
initialPage = initPage
)
val initPage by remember {
mutableStateOf(uiState.reviews.indexOfFirst { it.id == reviewId })
}

var pageIndex by remember {
mutableStateOf(0)
}
val pagerState = rememberPagerState(
pageCount = { uiState.reviews.size },
initialPage = initPage
)

var isFirstLikeState by remember {
mutableStateOf(isFirstLike)
}
var pageIndex by remember {
mutableStateOf(0)
}

LaunchedEffect(key1 = pagerState) {
snapshotFlow { pagerState.currentPage }.collect {
pageIndex = it
stadiumDetailViewModel.updateCurrentIndex(it)
if (visited[it]) return@collect
var isFirstLikeState by remember {
mutableStateOf(isFirstLike)
}

if (it == initPage) {
visited[it] = true
}
LaunchedEffect(key1 = pagerState) {
snapshotFlow { pagerState.currentPage }.collect {
pageIndex = it
stadiumDetailViewModel.updateCurrentIndex(it)
if (visited[it]) return@collect

if (!visited[it]) {
visited[it] = true
}
if (it == initPage) {
visited[it] = true
}
}

StadiumDetailReviewViewPager(
context = context,
reviews = uiState.reviews,
visited = visited,
position = reviewIndex,
isFirstLike = isFirstLikeState,
hasNext = uiState.hasNext,
pagerState = pagerState,
pageIndex = pageIndex,
bottomPadding = bottomPadding,
modifier = modifier,
onLoadPaging = stadiumDetailViewModel::getBlockReviews,
onClickLike = { id ->
onClickLike()
isFirstLikeState = false
stadiumDetailViewModel.updateLike(id)
},
onClickScrap = onClickScrap,
onClickShare = { imagePosition ->
onClickShare()
KakaoUtils().share(
context,
seatFeed(
title = uiState.kakaoShareSeatFeedTitle(pageIndex),
description = "출처 : ${uiState.reviews[pageIndex].member.nickname}",
imageUrl = uiState.reviews[pageIndex].images[imagePosition].url,
queryParams = mapOf(
"stadiumId" to stadiumDetailViewModel.stadiumId.toString(),
"blockCode" to stadiumDetailViewModel.blockCode
)
),
onSuccess = { sharingIntent ->
context.startActivity(sharingIntent)
}
)
if (!visited[it]) {
visited[it] = true
}
)
}
}

else -> Unit
StadiumDetailReviewViewPager(
context = context,
reviews = uiState.reviews,
visited = visited,
position = reviewIndex,
isFirstLike = isFirstLikeState,
hasNext = uiState.hasNext,
pagerState = pagerState,
pageIndex = pageIndex,
bottomPadding = bottomPadding,
modifier = modifier,
onLoadPaging = stadiumDetailViewModel::getBlockReviews,
onClickLike = { id ->
onClickLike()
isFirstLikeState = false
stadiumDetailViewModel.updateLike(id)
},
onClickScrap = onClickScrap,
onClickShare = { imagePosition ->
onClickShare()
KakaoUtils().share(
context,
seatFeed(
title = uiState.kakaoShareSeatFeedTitle(pageIndex),
description = "출처 : ${uiState.reviews[pageIndex].member.nickname}",
imageUrl = uiState.reviews[pageIndex].images[imagePosition].url,
queryParams = mapOf(
"stadiumId" to stadiumDetailViewModel.stadiumId.toString(),
"blockCode" to stadiumDetailViewModel.blockCode
)
),
onSuccess = { sharingIntent ->
context.startActivity(sharingIntent)
}
)
}
)
}
else -> Unit
}
}

Expand All @@ -136,6 +133,6 @@ private fun StadiumDetailPictureMainScreenPreview() {
reviewIndex = 0,
bottomPadding = 0f,
isFirstLike = false,
reviews = StadiumDetailUiState.Empty,
uiState = StadiumDetailUiState.Empty,
)
}

0 comments on commit d51594b

Please sign in to comment.