Skip to content

Properly init in-memory usage when restoring the state #610

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

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import kotlinx.coroutines.withContext
fun AvatarUpdateTab(modifier: Modifier = Modifier) {
var userEmail by remember { mutableStateOf(BuildConfig.DEMO_EMAIL) }
var userToken by remember { mutableStateOf(BuildConfig.DEMO_BEARER_TOKEN) }
var useToken by remember { mutableStateOf(false) }
var useToken by rememberSaveable { mutableStateOf(false) }
var tokenVisible by remember { mutableStateOf(false) }
val context = LocalContext.current
var showBottomSheet by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.shrinkVertically
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
Expand All @@ -16,7 +15,6 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.gravatar.quickeditor.QuickEditorContainer
import com.gravatar.quickeditor.ui.alttext.AltTextPage
import com.gravatar.quickeditor.ui.avatarpicker.AvatarPicker
import com.gravatar.quickeditor.ui.navigation.EditorNavDestinations
Expand Down Expand Up @@ -111,14 +109,6 @@ internal fun GravatarQuickEditorPage(
) {
val navController = rememberNavController()

DisposableEffect(authToken) {
QuickEditorContainer.getInstance().useInMemoryTokenStorage()

onDispose {
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}
}

NavHost(
navController,
startDestination = QuickEditorPage.SPLASH.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand All @@ -42,6 +43,7 @@ import com.composables.core.SheetDetent
import com.composables.core.SheetDetent.Companion.FullyExpanded
import com.composables.core.SheetDetent.Companion.Hidden
import com.composables.core.rememberModalBottomSheetState
import com.gravatar.quickeditor.QuickEditorContainer
import com.gravatar.quickeditor.ui.components.QEDragHandle
import com.gravatar.quickeditor.ui.editor.AuthenticationMethod
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
Expand Down Expand Up @@ -100,6 +102,16 @@ internal fun GravatarQuickEditorBottomSheet(
}
}

DisposableEffect(Unit) {
if (authenticationMethod is AuthenticationMethod.Bearer) {
QuickEditorContainer.getInstance().useInMemoryTokenStorage()
}

onDispose {
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}
Comment on lines +111 to +112
Copy link
Preview

Copilot AI Apr 22, 2025

Choose a reason for hiding this comment

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

Consider conditionally calling resetUseInMemoryTokenStorage() within the onDispose block only when authenticationMethod is Bearer. This will ensure that the reset is only performed if the in-memory token storage was actually enabled.

Suggested change
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}
if (authenticationMethod is AuthenticationMethod.Bearer) {
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

}

CompositionLocalProvider(LocalGravatarTheme provides mainGravatarTheme) {
GravatarModalBottomSheet(
onDismiss = onDismiss,
Expand Down