Skip to content

Commit

Permalink
[Fix] #61 qa add pokit link (#63)
Browse files Browse the repository at this point in the history
* [FIX] #61-미분류 링크 추가 후 메인 화면 포킷에 적용되지 않는 문제 수정

* [FIX] #61-포킷 추가 요청 에러 발생시 뒤로가기 및 다른 화면 이벤트가 반응하지 않는 문제 수정, 닉네임 중복 검사 에러시 toast 메세지가 표시되도록 변경

* [FIX] #61-링크 추가 화면에서 포킷 목록 조회시 미분류가 표시되지 않는 문제 수정

* [FIX] #61-링크 추가 화면에서 리마인드 기능 임시 비활성화, 링크 추가화면에서 포킷 추가시 해당 포킷으로 설정되도록 수정, 타이틀 글자제한 제거

* [FIX] #61-홈 화면 포킷에서 링크 수정 bottomSheet 호출시 pokit수정 bottomSheet가 같이 올라오는 문제 수정

* [FIX] #61-링크 추가 화면에서 타이틀 설정 안되는 문제 수정

* [FIX] #61-링크 추가 화면에서 url로드 성공시 타이틀을 url 타이틀로 수정

* [CHORE] #61-ktlint 적용
  • Loading branch information
l5x5l authored Aug 29, 2024
1 parent 1275367 commit e297184
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LinkRepositoryImpl @Inject constructor(
categoryId = categoryId,
memo = memo,
alertYn = alertYn,
thumbNail = if (thumbNail.isEmpty()) thumbNail else null
thumbNail = thumbNail.ifEmpty { null }
)
val response = dataSource.modifyLink(contentId = linkId, modifyLinkRequest = modifyLinkRequest)
val mappedResponse = LinkMapper.mapperToLink(response)
Expand All @@ -127,7 +127,7 @@ class LinkRepositoryImpl @Inject constructor(
categoryId = categoryId,
memo = memo,
alertYn = alertYn,
thumbNail = if (thumbNail.isEmpty()) thumbNail else null
thumbNail = thumbNail.ifEmpty { null }
)
val response = dataSource.createLink(createLinkRequest = createLinkRequest)
val mappedResponse = LinkMapper.mapperToLink(response)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package pokitmons.pokit.domain.model.pokit

object PokitErrorCode {
const val ALREADY_USED_POKIT_NAME = "C_001"
const val CANNOT_FOUND_POKIT_INFO = "C_002"
const val UNAVAILABLE_POKIT = "C_003"
const val CANNOT_FOUND_POKIT_IMAGE = "C_004"
const val TOO_MUCH_POKIT = "C_005"
const val CANNOT_FOUND_UNCATEGORY_IMAGE = "C_006"
const val ALREADY_USED_POKIT_NAME = "CA_001"
const val CANNOT_FOUND_POKIT_INFO = "CA_002"
const val UNAVAILABLE_POKIT = "CA_003"
const val CANNOT_FOUND_POKIT_IMAGE = "CA_004"
const val TOO_MUCH_POKIT = "CA_005"
const val CANNOT_FOUND_UNCATEGORY_IMAGE = "CA_006"
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fun AddLinkScreen(
Spacer(modifier = Modifier.height(16.dp))

if (state.link != null) {
Link(state.link)
Link(link = state.link, title = title.ifEmpty { null })
Spacer(modifier = Modifier.height(16.dp))
}

Expand All @@ -224,7 +224,6 @@ fun AddLinkScreen(
LabeledInput(
label = stringResource(id = R.string.title),
sub = "",
maxLength = 20,
inputText = title,
hintText = stringResource(id = R.string.placeholder_title),
onChangeText = inputTitle,
Expand Down Expand Up @@ -310,13 +309,13 @@ fun AddLinkScreen(
toggleRemindRadio(it.second)
},
getTitleFromItem = { it.first },
enabled = enable
enabled = false
)

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

Text(
text = stringResource(id = R.string.sub_remind),
text = stringResource(id = R.string.see_you_soon),
style = PokitTheme.typography.detail1.copy(color = PokitTheme.colors.textTertiary)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.orbitmvi.orbit.Container
Expand All @@ -28,6 +29,7 @@ import org.orbitmvi.orbit.syntax.simple.reduce
import org.orbitmvi.orbit.viewmodel.container
import pokitmons.pokit.core.feature.navigation.args.LinkArg
import pokitmons.pokit.core.feature.navigation.args.LinkUpdateEvent
import pokitmons.pokit.core.feature.navigation.args.PokitUpdateEvent
import pokitmons.pokit.domain.commom.PokitResult
import pokitmons.pokit.domain.model.pokit.MAX_POKIT_COUNT
import pokitmons.pokit.domain.usecase.link.CreateLinkUseCase
Expand Down Expand Up @@ -74,13 +76,27 @@ class AddLinkViewModel @Inject constructor(
val currentLinkId: Int? = savedStateHandle.get<String>("link_id")?.toIntOrNull()

init {
initPokitAddEventDetector()

if (currentLinkId != null) {
loadPokitLink(currentLinkId)
} else {
loadUncategorizedPokit()
}
}

private fun initPokitAddEventDetector() {
viewModelScope.launch {
PokitUpdateEvent.addedPokit.collectLatest { addedPokit ->
intent {
reduce {
state.copy(currentPokit = Pokit(addedPokit.title, addedPokit.id.toString(), 0))
}
}
}
}
}

private fun loadUncategorizedPokit() {
viewModelScope.launch {
val response = getUncategorizedPokitUseCase.getUncategoriezdPokit()
Expand Down Expand Up @@ -148,6 +164,9 @@ class AddLinkViewModel @Inject constructor(
val response = getLinkCardUseCase.getLinkCard(linkUrl)
if (response is PokitResult.Success) {
reduce { state.copy(step = ScreenStep.IDLE, link = Link.fromDomainLinkCard(response.result)) }
if (response.result.title.isNotEmpty() && title.value.isEmpty()) {
_title.update { response.result.title }
}
} else {
reduce { state.copy(step = ScreenStep.IDLE) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,29 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.strayalpaca.addlink.R
import com.strayalpaca.addlink.model.Link
import pokitmons.pokit.core.ui.theme.PokitTheme
import pokitmons.pokit.core.ui.utils.noRippleClickable

@Composable
internal fun Link(
link: Link,
title: String?,
modifier: Modifier = Modifier,
openWebBrowserByClick: Boolean = true,
) {
val uriHandler = LocalUriHandler.current
val placeHolder = stringResource(id = R.string.placeholder_title)
val linkTitle = remember(link, title) { title ?: link.title.ifEmpty { placeHolder } }

Row(
modifier = modifier
Expand Down Expand Up @@ -60,7 +66,7 @@ internal fun Link(
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = link.title,
text = linkTitle,
maxLines = 2,
style = PokitTheme.typography.body3Medium.copy(color = PokitTheme.colors.textSecondary)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PokitPaging(
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO),
private val initPage: Int = 0,
private val firstRequestPage: Int = 3,
private val showUncategorizedPokit: Boolean = true,
) : SimplePaging<Pokit> {
private val _pagingState = MutableStateFlow(SimplePagingState.IDLE)
override val pagingState: StateFlow<SimplePagingState> = _pagingState.asStateFlow()
Expand All @@ -36,7 +37,7 @@ class PokitPaging(
requestJob = coroutineScope.launch {
try {
currentPageIndex = initPage
val response = getPokits.getPokits(size = perPage * firstRequestPage, page = currentPageIndex)
val response = getPokits.getPokits(size = perPage * firstRequestPage, page = currentPageIndex, filterUncategorized = !showUncategorizedPokit)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down Expand Up @@ -65,7 +66,7 @@ class PokitPaging(

requestJob = coroutineScope.launch {
try {
val response = getPokits.getPokits(size = perPage, page = currentPageIndex)
val response = getPokits.getPokits(size = perPage, page = currentPageIndex, filterUncategorized = !showUncategorizedPokit)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down
4 changes: 3 additions & 1 deletion feature/addlink/src/main/res/values/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="link">링크</string>
<string name="placeholder_link">내용을 입력해주세요.</string>
<string name="title">제목</string>
<string name="placeholder_title">내용을 입력해주세요.</string>
<string name="placeholder_title">제목을 입력해주세요.</string>
<string name="pokit">포킷</string>
<string name="memo">메모</string>
<string name="placeholder_memo">내용을 입력해주세요.</string>
Expand All @@ -22,4 +22,6 @@

<string name="network_error">네트워크 에러가 발생했습니다. 네트워크 환경을 확인해주세요.</string>
<string name="toast_cannot_create_pokit">최대 30개의 포킷을 생성할 수 있습니다.\n포킷을 삭제한 뒤에 추가해주세요.</string>

<string name="see_you_soon">준비중인 기능이니 조금만 기다려주세요.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import pokitmons.pokit.core.ui.components.atom.button.attributes.PokitButtonSize
import pokitmons.pokit.core.ui.components.block.labeledinput.LabeledInput
import pokitmons.pokit.core.ui.components.block.pokitlist.PokitList
import pokitmons.pokit.core.ui.components.block.pokitlist.attributes.PokitListState
import pokitmons.pokit.core.ui.components.block.pokittoast.PokitToast
import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet
import pokitmons.pokit.core.ui.theme.PokitTheme
import pokitmons.pokit.core.ui.utils.noRippleClickable
Expand All @@ -75,6 +76,7 @@ fun AddPokitScreenContainer(
derivedStateOf {
state.step != AddPokitScreenStep.POKIT_SAVE_LOADING &&
state.pokitInputErrorMessage == null &&
state.errorToastMessage == null &&
state.pokitImage != null
}
}
Expand All @@ -99,6 +101,7 @@ fun AddPokitScreenContainer(
hideProfileSelectBottomSheet = viewModel::hidePokitProfileSelectBottomSheet,
showSelectProfileBottomSheet = viewModel::showPokitProfileSelectBottomSheet,
selectPokitProfileImage = viewModel::selectPokitProfile,
hideToastMessage = viewModel::hideToastMessage,
pokits = pokits,
pokitsState = pokitsState,
loadPokits = viewModel::loadPokitList,
Expand All @@ -117,6 +120,7 @@ fun AddPokitScreen(
hideProfileSelectBottomSheet: () -> Unit = {},
showSelectProfileBottomSheet: () -> Unit = {},
selectPokitProfileImage: (PokitImage) -> Unit = {},
hideToastMessage: () -> Unit = {},
pokits: List<Pokit> = emptyList(),
pokitsState: SimplePagingState = SimplePagingState.IDLE,
loadPokits: () -> Unit = {},
Expand Down Expand Up @@ -251,6 +255,17 @@ fun AddPokitScreen(
trackColor = PokitTheme.colors.backgroundSecondary
)
}

state.errorToastMessage?.let { message ->
PokitToast(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomCenter)
.padding(start = 12.dp, end = 12.dp, bottom = 16.dp),
text = message,
onClickClose = hideToastMessage
)
}
}

Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.orbitmvi.orbit.viewmodel.container
import pokitmons.pokit.core.feature.navigation.args.PokitArg
import pokitmons.pokit.core.feature.navigation.args.PokitUpdateEvent
import pokitmons.pokit.domain.commom.PokitResult
import pokitmons.pokit.domain.model.pokit.PokitErrorCode
import pokitmons.pokit.domain.usecase.pokit.CreatePokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitImagesUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitUseCase
Expand Down Expand Up @@ -65,12 +66,18 @@ class AddPokitViewModel @Inject constructor(
val pokitImages: StateFlow<List<PokitImage>> = _pokitIamges.asStateFlow()

init {
loadPokitList()
initPokitList()
loadPokitImages()

setAddModifyMode(pokitId)
}

private fun initPokitList() {
viewModelScope.launch {
pokitPaging.refresh()
}
}

fun loadPokitList() {
viewModelScope.launch {
pokitPaging.load()
Expand Down Expand Up @@ -117,9 +124,9 @@ class AddPokitViewModel @Inject constructor(
_pokitName.update { pokitName }

intent {
val isInAvailableLength = pokitName.length > POKIT_NAME_MAX_LENGTH
val isOutOfMaxLength = pokitName.length > POKIT_NAME_MAX_LENGTH

if (isInAvailableLength) {
if (isOutOfMaxLength) {
val errorMessage = errorMessageProvider.getTextLengthErrorMessage()
reduce { state.copy(pokitInputErrorMessage = errorMessage) }
} else {
Expand All @@ -129,6 +136,13 @@ class AddPokitViewModel @Inject constructor(
}

fun savePokit() = intent {
// todo 에러 코드 파싱 수정시 제거 필요
if (pokitPaging.pagingData.value.find { it.title == pokitName.value } != null) {
val errorMessage = errorMessageProvider.errorCodeToMessage(PokitErrorCode.ALREADY_USED_POKIT_NAME)
reduce { state.copy(errorToastMessage = errorMessage) }
return@intent
}

reduce {
state.copy(step = AddPokitScreenStep.POKIT_SAVE_LOADING)
}
Expand Down Expand Up @@ -159,7 +173,7 @@ class AddPokitViewModel @Inject constructor(
} else {
response as PokitResult.Error
val errorMessage = errorMessageProvider.errorCodeToMessage(response.error.code)
reduce { state.copy(pokitInputErrorMessage = errorMessage) }
reduce { state.copy(errorToastMessage = errorMessage, step = AddPokitScreenStep.IDLE) }
}
}

Expand Down Expand Up @@ -193,4 +207,10 @@ class AddPokitViewModel @Inject constructor(
state.copy(pokitImage = pokitImage)
}
}

fun hideToastMessage() = intent {
reduce {
state.copy(errorToastMessage = null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class AddPokitScreenState(
val step: AddPokitScreenStep = AddPokitScreenStep.IDLE,
val pokitImage: PokitImage? = null,
val isModify: Boolean = false,
val errorToastMessage: String? = null,
)

sealed class AddPokitScreenStep {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class PokitViewModel @Inject constructor(
private fun initLinkAddEventDetector() {
viewModelScope.launch {
LinkUpdateEvent.addedLink.collectLatest { addedLink ->
linkPaging.refresh()
val linkAddedPokit = pokitPaging.pagingData.value.find { it.id == addedLink.pokitId.toString() } ?: return@collectLatest
val modifiedPokit = linkAddedPokit.copy(count = (linkAddedPokit.count + 1))
pokitPaging.modifyItem(modifiedPokit)
linkPaging.refresh()
}
}
}
Expand Down Expand Up @@ -162,6 +162,9 @@ class PokitViewModel @Inject constructor(
private val _currentDetailShowLink = MutableStateFlow<DetailLink?>(null)
val currentDetailShowLink = _currentDetailShowLink.asStateFlow()

private val _linkOptionBottomSheetType = MutableStateFlow<BottomSheetType?>(null)
val linkOptionBottomSheetType = _linkOptionBottomSheetType.asStateFlow()

init {
initLinkUpdateEventDetector()
initPokitUpdateEventDetector()
Expand Down Expand Up @@ -288,17 +291,17 @@ class PokitViewModel @Inject constructor(
}

fun showLinkOptionBottomSheet(link: DetailLink) {
_pokitOptionBottomSheetType.update { BottomSheetType.MODIFY }
_linkOptionBottomSheetType.update { BottomSheetType.MODIFY }
_currentSelectedLink.update { link }
}

fun hideLinkOptionBottomSheet() {
_pokitOptionBottomSheetType.update { null }
_linkOptionBottomSheetType.update { null }
_currentSelectedLink.update { null }
}

fun showLinkRemoveBottomSheet() {
_pokitOptionBottomSheetType.update { BottomSheetType.REMOVE }
_linkOptionBottomSheetType.update { BottomSheetType.REMOVE }
}

fun removeCurrentSelectedLink() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun UnclassifiedScreen(
) {
val unCategoryLinks = viewModel.unCategoryLinks.collectAsState()

val pokitOptionBottomSheetType by viewModel.pokitOptionBottomSheetType.collectAsState()
val pokitOptionBottomSheetType by viewModel.linkOptionBottomSheetType.collectAsState()
val currentSelectedLink by viewModel.currentSelectedLink.collectAsState()
val currentDetailShowLink by viewModel.currentDetailShowLink.collectAsState()

Expand Down

0 comments on commit e297184

Please sign in to comment.