Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature:notifications 생성 #318

Conversation

plgafhd
Copy link
Collaborator

@plgafhd plgafhd commented Jul 14, 2024

No description provided.

@plgafhd plgafhd requested a review from a team as a code owner July 14, 2024 03:04
Comment on lines +28 to +30
pagingSourceFactory = { NotificationPagingSource(api) },
).flow.map { it.map { it.toExternalModel() } }
}
Copy link
Collaborator Author

@plgafhd plgafhd Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 옮겨온 Repository에서는
Flow<PagingData<NotificationDto>>가 아니라 Flow<PagingData<Notification>>을 내려주도록 바꿨다.

Comment on lines +42 to +52

fun getNotifications() {
viewModelScope.launch {
notificationRepository.getNotificationResultStream()
.cachedIn(viewModelScope)
.collect {
_notificationList.emit(it)
}
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 원래 init이었는데
일단 일반함수로 바꾸고 뷰에서 LaunchedEffect로 실행

Comment on lines +31 to +42

val notificationsUiState: StateFlow<NotificationsUiState> =
notificationList
.map<PagingData<Notification>, NotificationsUiState>(NotificationsUiState::Success)
.onStart { emit(NotificationsUiState.Loading) }
.catch { emit(NotificationsUiState.Error) }
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = NotificationsUiState.Loading,
)

Copy link
Collaborator Author

@plgafhd plgafhd Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 함수가 실행되면 notificationList가 바뀌어서 notificationUiState도 바뀌게 되는데...

Comment on lines +5 to +14

sealed interface NotificationsUiState {
data object Loading : NotificationsUiState

data object Error : NotificationsUiState

data class Success(
val notifications: PagingData<Notification>,
) : NotificationsUiState
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotificationsUiState는 이렇게 정의해봤어 NIA도 비슷하게 되어있어서

Comment on lines +33 to +37
notificationList
.map<PagingData<Notification>, NotificationsUiState>(NotificationsUiState::Success)
.onStart { emit(NotificationsUiState.Loading) }
.catch { emit(NotificationsUiState.Error) }
.stateIn(
Copy link
Collaborator Author

@plgafhd plgafhd Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상황에 따라 Loading, Error로 적절하게 들어갈 수 있고,
정상적으로 불러올 경우 NotificationUiState.Success로 감싸서 내려주게 되는데...
문제는 Success의 경우 Notifications가 PagingData<Notification>이라서 (StateFlow가 아니라는게 문제!)

Comment on lines +112 to +114
val notifications = notificationsUiState.notifications
items(notifications) {
it?.let {
Copy link
Collaborator Author

@plgafhd plgafhd Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 갖다 쓸수가 없다... (items에 넣을 수가 없음)
원래는 StateFlow<PagingData<Notification>>를 collectAsLazyPagingItems해서 할수 있었는데
지금은 방법이 없다... NIA에서 이 방식이 가능했던 이유는
NotificationsUiState.Success가 List를 담기 때문이다.
이거 어떻게 해야 할까...

@plgafhd plgafhd closed this Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant