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

Remember saved text for markdown areas. Fixes #104 #106

Merged
merged 1 commit into from
Feb 25, 2022
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 @@ -5,6 +5,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.TextFieldValue
Expand Down Expand Up @@ -35,7 +36,7 @@ fun CommentEditActivity(
val account = getCurrentAccount(accountViewModel = accountViewModel)
val scope = rememberCoroutineScope()

var content by remember { mutableStateOf(TextFieldValue(commentEditViewModel.commentView.value?.comment?.content.orEmpty())) }
var content by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue(commentEditViewModel.commentView.value?.comment?.content.orEmpty())) }

val focusManager = LocalFocusManager.current

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jerboa.ui.components.comment.reply

import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -126,7 +125,6 @@ fun CommentReply(
reply: TextFieldValue,
onReplyChange: (TextFieldValue) -> Unit,
onPersonClick: (personId: Int) -> Unit,
onPickedImage: (image: Uri) -> Unit,
isModerator: Boolean,
account: Account?,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.TextFieldValue
import androidx.navigation.NavController
import com.jerboa.api.uploadPictrsImage
import com.jerboa.appendMarkdownImage
import com.jerboa.db.AccountViewModel
import com.jerboa.imageInputStreamFromUri
import com.jerboa.isModerator
import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.components.inbox.InboxViewModel
import com.jerboa.ui.components.person.PersonProfileViewModel
import com.jerboa.ui.components.person.personClickWrapper
import com.jerboa.ui.components.post.PostViewModel
import kotlinx.coroutines.launch

@Composable
fun CommentReplyActivity(
Expand All @@ -39,7 +36,12 @@ fun CommentReplyActivity(
val ctx = LocalContext.current
val account = getCurrentAccount(accountViewModel = accountViewModel)
val scope = rememberCoroutineScope()
var reply by remember { mutableStateOf(TextFieldValue("")) }
var reply by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(
TextFieldValue
("")
)
}

val focusManager = LocalFocusManager.current

Expand Down Expand Up @@ -85,22 +87,6 @@ fun CommentReplyActivity(
ctx
)
},
onPickedImage = { uri ->
val imageIs = imageInputStreamFromUri(ctx, uri)
scope.launch {
account?.also { acct ->
val url = uploadPictrsImage(acct, imageIs, ctx)
url?.also {
reply = TextFieldValue(
appendMarkdownImage(
reply.text,
it
)
)
}
}
}
},
isModerator = isModerator(
commentView.creator,
postViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
Expand All @@ -32,7 +33,7 @@ fun PrivateMessageReplyActivity(
val ctx = LocalContext.current
val account = getCurrentAccount(accountViewModel = accountViewModel)

var reply by remember { mutableStateOf(TextFieldValue("")) }
var reply by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) }

val focusManager = LocalFocusManager.current

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.TextFieldValue
Expand All @@ -26,7 +27,7 @@ fun CreateCommentReportActivity(

val ctx = LocalContext.current
val account = getCurrentAccount(accountViewModel = accountViewModel)
var reason by remember { mutableStateOf(TextFieldValue("")) }
var reason by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) }

val focusManager = LocalFocusManager.current

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.TextFieldValue
Expand All @@ -26,7 +27,7 @@ fun CreatePostReportActivity(

val ctx = LocalContext.current
val account = getCurrentAccount(accountViewModel = accountViewModel)
var reason by remember { mutableStateOf(TextFieldValue("")) }
var reason by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) }

val focusManager = LocalFocusManager.current

Expand Down