Skip to content

Commit

Permalink
[#1012] MyPage의 UiState Holder 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
l2hyunwoo committed Jan 2, 2025
1 parent c160ff3 commit 44762a4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import dagger.hilt.components.SingletonComponent
import org.sopt.official.auth.repository.AuthRepository
import org.sopt.official.common.context.appContext
import org.sopt.official.domain.mypage.repository.UserRepository
import org.sopt.official.domain.soptamp.repository.StampRepository

@EntryPoint
@InstallIn(SingletonComponent::class)
internal interface AuthEntryPoint {
fun authRepository(): AuthRepository
fun userRepository(): UserRepository
fun stampRepository(): StampRepository
}

internal val authRepository by lazy {
Expand All @@ -50,3 +52,9 @@ internal val userRepository by lazy {
.fromApplication(appContext, AuthEntryPoint::class.java)
.userRepository()
}

internal val stampRepository by lazy {
EntryPointAccessors
.fromApplication(appContext, AuthEntryPoint::class.java)
.stampRepository()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.sopt.official.feature.mypage.mypage.state

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import com.google.firebase.messaging.FirebaseMessaging
import io.github.takahirom.rin.rememberRetained
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.sopt.official.auth.model.UserActiveState
import org.sopt.official.auth.repository.AuthRepository
import org.sopt.official.domain.soptamp.repository.StampRepository
import timber.log.Timber

@Composable
fun rememberMyPageUiState(
userActiveState: UserActiveState,
authRepository: AuthRepository,
stampRepository: StampRepository,
onRestartApp: () -> Unit
): MyPageUiState {
var userActiveState by rememberRetained { mutableStateOf(userActiveState) }
var dialogState by rememberRetained { mutableStateOf(MyPageDialogState.CLEAR) }

val scope = rememberCoroutineScope()

return MyPageUiState(
user = userActiveState,
dialogState = dialogState,
onEventSink = { action ->
when (action) {
is ResetSoptamp -> {
scope.launch {
stampRepository.deleteAllStamps()
.onSuccess { dialogState = MyPageDialogState.CLEAR }
.onFailure { Timber.e(it) }
}
}

is ClearSoptamp -> {
dialogState = MyPageDialogState.CLEAR_SOPTAMP
}

is Logout -> {
scope.launch {
runCatching {
FirebaseMessaging.getInstance().token.await()
}.onSuccess {
authRepository.logout(it)
.onSuccess {
authRepository.clearLocalData()
onRestartApp()
}.onFailure { error ->
Timber.e(error)
}
}.onFailure {
Timber.e(it)
}
}
}

is CloseDialog -> {
dialogState = MyPageDialogState.CLEAR
}
}
}
)
}

0 comments on commit 44762a4

Please sign in to comment.