Browse Source

Made main state scope private (refactoring)

Vadik Sirekanyan 2 năm trước cách đây
mục cha
commit
96e2274688

+ 1 - 1
app/src/main/java/org/sirekanyan/outline/MainState.kt

@@ -41,7 +41,7 @@ fun rememberMainState(router: Router): MainState {
 }
 
 class MainState(
-    val scope: CoroutineScope,
+    scope: CoroutineScope,
     val servers: ServerRepository,
     val keys: KeyRepository,
     val search: SearchState,

+ 4 - 2
app/src/main/java/org/sirekanyan/outline/ui/AddServerContent.kt

@@ -30,10 +30,12 @@ import org.sirekanyan.outline.NotSupportedContent
 import org.sirekanyan.outline.Router
 import org.sirekanyan.outline.SelectedPage
 import org.sirekanyan.outline.api.model.createServerEntity
+import org.sirekanyan.outline.ext.rememberStateScope
 import javax.net.ssl.SSLException
 
 @Composable
 fun AddServerContent(state: MainState, router: Router) {
+    val scope = rememberStateScope()
     var draft by rememberSaveable { mutableStateOf("") }
     var insecure by rememberSaveable { mutableStateOf(false) }
     var error by remember(draft) { mutableStateOf("") }
@@ -64,7 +66,7 @@ fun AddServerContent(state: MainState, router: Router) {
         DialogToolbar(
             title = "Add server",
             onCloseClick = { router.dialog = null },
-            action = "Add" to { state.scope.launch { onAddClick() } },
+            action = "Add" to { scope.launch { onAddClick() } },
             isLoading = isLoading,
         )
         val focusRequester = remember { FocusRequester() }
@@ -81,7 +83,7 @@ fun AddServerContent(state: MainState, router: Router) {
             supportingText = { Text(error) },
             maxLines = 4,
             keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
-            keyboardActions = KeyboardActions(onDone = { state.scope.launch { onAddClick() } })
+            keyboardActions = KeyboardActions(onDone = { scope.launch { onAddClick() } })
         )
         LaunchedEffect(Unit) {
             focusRequester.requestFocus()

+ 3 - 1
app/src/main/java/org/sirekanyan/outline/ui/RenameContent.kt

@@ -20,6 +20,7 @@ import androidx.compose.ui.text.input.TextFieldValue
 import androidx.compose.ui.unit.dp
 import kotlinx.coroutines.launch
 import org.sirekanyan.outline.MainState
+import org.sirekanyan.outline.ext.rememberStateScope
 
 @Composable
 fun RenameContent(
@@ -29,6 +30,7 @@ fun RenameContent(
     defaultName: String,
     onSaveClicked: suspend (String) -> Unit,
 ) {
+    val scope = rememberStateScope()
     var draft by rememberSaveable(stateSaver = TextFieldValue.Saver) {
         mutableStateOf(TextFieldValue(initialName, TextRange(Int.MAX_VALUE)))
     }
@@ -39,7 +41,7 @@ fun RenameContent(
             title = dialogTitle,
             onCloseClick = { state.dialog = null },
             action = "Save" to {
-                state.scope.launch {
+                scope.launch {
                     try {
                         isLoading = true
                         val newName = draft.text.ifBlank { defaultName }