Reactivating hold to edit draft.

This commit is contained in:
Vitor Pamplona
2024-04-01 14:14:58 -04:00
parent 7fc43c96d6
commit 18b57b8ac8
6 changed files with 118 additions and 59 deletions
@@ -105,6 +105,7 @@ fun ChatroomMessageCompose(
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
) {
WatchNoteEvent(baseNote = baseNote, accountViewModel = accountViewModel) {
WatchBlockAndReport(
@@ -123,6 +124,7 @@ fun ChatroomMessageCompose(
accountViewModel,
nav,
onWantsToReply,
onWantsToEditDraft,
)
}
}
@@ -139,6 +141,7 @@ fun NormalChatNote(
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
) {
val drawAuthorInfo by
remember(note) {
@@ -252,6 +255,7 @@ fun NormalChatNote(
innerQuote,
backgroundBubbleColor,
onWantsToReply,
onWantsToEditDraft,
canPreview,
availableBubbleSize,
showDetails,
@@ -265,7 +269,9 @@ fun NormalChatNote(
note = note,
popupExpanded = popupExpanded,
onDismiss = { popupExpanded = false },
onWantsToEditDraft = { onWantsToEditDraft(note) },
accountViewModel = accountViewModel,
nav = nav,
)
}
}
@@ -279,6 +285,7 @@ private fun RenderBubble(
innerQuote: Boolean,
backgroundBubbleColor: MutableState<Color>,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
canPreview: Boolean,
availableBubbleSize: MutableState<Int>,
showDetails: State<Boolean>,
@@ -309,6 +316,7 @@ private fun RenderBubble(
backgroundBubbleColor,
bubbleSize,
onWantsToReply,
onWantsToEditDraft,
canPreview,
showDetails,
accountViewModel,
@@ -327,6 +335,7 @@ private fun MessageBubbleLines(
backgroundBubbleColor: MutableState<Color>,
bubbleSize: MutableState<Int>,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
canPreview: Boolean,
showDetails: State<Boolean>,
accountViewModel: AccountViewModel,
@@ -349,6 +358,7 @@ private fun MessageBubbleLines(
accountViewModel = accountViewModel,
nav = nav,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
)
}
@@ -357,6 +367,7 @@ private fun MessageBubbleLines(
canPreview = canPreview,
innerQuote = innerQuote,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
backgroundBubbleColor = backgroundBubbleColor,
accountViewModel = accountViewModel,
nav = nav,
@@ -403,9 +414,10 @@ private fun RenderReplyRow(
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
) {
if (!innerQuote && note.replyTo?.lastOrNull() != null) {
RenderReply(note, backgroundBubbleColor, accountViewModel, nav, onWantsToReply)
RenderReply(note, backgroundBubbleColor, accountViewModel, nav, onWantsToReply, onWantsToEditDraft)
}
}
@@ -416,6 +428,7 @@ private fun RenderReply(
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
val replyTo =
@@ -434,6 +447,7 @@ private fun RenderReply(
accountViewModel = accountViewModel,
nav = nav,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
)
}
}
@@ -445,6 +459,7 @@ private fun NoteRow(
canPreview: Boolean,
innerQuote: Boolean,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
backgroundBubbleColor: MutableState<Color>,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
@@ -463,6 +478,7 @@ private fun NoteRow(
canPreview,
innerQuote,
onWantsToReply,
onWantsToEditDraft,
backgroundBubbleColor,
accountViewModel,
nav,
@@ -488,6 +504,7 @@ private fun RenderDraftEvent(
canPreview: Boolean,
innerQuote: Boolean,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
backgroundBubbleColor: MutableState<Color>,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
@@ -501,6 +518,7 @@ private fun RenderDraftEvent(
accountViewModel = accountViewModel,
nav = nav,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
)
NoteRow(
@@ -508,6 +526,7 @@ private fun RenderDraftEvent(
canPreview = canPreview,
innerQuote = innerQuote,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
backgroundBubbleColor = backgroundBubbleColor,
accountViewModel = accountViewModel,
nav = nav,
@@ -40,6 +40,7 @@ import androidx.compose.material.icons.filled.AlternateEmail
import androidx.compose.material.icons.filled.Block
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.FormatQuote
import androidx.compose.material.icons.filled.PersonAdd
import androidx.compose.material.icons.filled.PersonRemove
@@ -137,11 +138,16 @@ fun LongPressToQuickAction(
) {
val popupExpanded = remember { mutableStateOf(false) }
val showPopup = remember { { popupExpanded.value = true } }
val hidePopup = remember { { popupExpanded.value = false } }
content(showPopup)
NoteQuickActionMenu(baseNote, popupExpanded.value, hidePopup, accountViewModel)
NoteQuickActionMenu(
note = baseNote,
popupExpanded = popupExpanded.value,
onDismiss = { popupExpanded.value = false },
accountViewModel = accountViewModel,
nav = {},
)
}
@Composable
@@ -150,12 +156,44 @@ fun NoteQuickActionMenu(
popupExpanded: Boolean,
onDismiss: () -> Unit,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
val editDraftDialog = remember { mutableStateOf(false) }
if (editDraftDialog.value) {
NewPostView(
onClose = {
editDraftDialog.value = false
},
accountViewModel = accountViewModel,
draft = note,
nav = { },
)
}
NoteQuickActionMenu(
note = note,
popupExpanded = popupExpanded,
onDismiss = onDismiss,
onWantsToEditDraft = { editDraftDialog.value = true },
accountViewModel = accountViewModel,
nav = nav,
)
}
@Composable
fun NoteQuickActionMenu(
note: Note,
popupExpanded: Boolean,
onDismiss: () -> Unit,
onWantsToEditDraft: () -> Unit,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
val showSelectTextDialog = remember { mutableStateOf(false) }
val showDeleteAlertDialog = remember { mutableStateOf(false) }
val showBlockAlertDialog = remember { mutableStateOf(false) }
val showReportDialog = remember { mutableStateOf(false) }
val editDraftDialog = remember { mutableStateOf(false) }
if (popupExpanded) {
RenderMainPopup(
@@ -165,7 +203,7 @@ fun NoteQuickActionMenu(
showBlockAlertDialog,
showDeleteAlertDialog,
showReportDialog,
editDraftDialog,
onWantsToEditDraft,
)
}
@@ -202,17 +240,6 @@ fun NoteQuickActionMenu(
onDismiss()
}
}
if (editDraftDialog.value) {
NewPostView(
onClose = {
editDraftDialog.value = false
},
accountViewModel = accountViewModel,
draft = note,
nav = { },
)
}
}
@Composable
@@ -223,7 +250,7 @@ private fun RenderMainPopup(
showBlockAlertDialog: MutableState<Boolean>,
showDeleteAlertDialog: MutableState<Boolean>,
showReportDialog: MutableState<Boolean>,
editDraftDialog: MutableState<Boolean>,
onWantsToEditDraft: () -> Unit,
) {
val context = LocalContext.current
val primaryLight = lightenColor(MaterialTheme.colorScheme.primary, 0.1f)
@@ -294,23 +321,6 @@ private fun RenderMainPopup(
}
}
/*
if (note.isDraft()) {
VerticalDivider(color = primaryLight)
NoteQuickActionItem(
Icons.Default.Edit,
stringResource(R.string.edit_draft),
) {
if (newPostViewModel != null) {
newPostViewModel.load(accountViewModel, null, null, null, null, note)
onDismiss()
} else {
editDraftDialog.value = true
onDismiss()
}
}
}*/
if (!isOwnNote) {
VerticalDivider(color = primaryLight)
@@ -371,6 +381,15 @@ private fun RenderMainPopup(
onDismiss()
}
VerticalDivider(color = primaryLight)
if (isOwnNote && note.isDraft()) {
NoteQuickActionItem(
Icons.Default.Edit,
stringResource(R.string.edit_draft),
) {
onDismiss()
onWantsToEditDraft()
}
} else {
NoteQuickActionItem(
icon = Icons.Default.Share,
label = stringResource(R.string.quick_action_share),
@@ -397,6 +416,7 @@ private fun RenderMainPopup(
ContextCompat.startActivity(context, shareIntent, null)
onDismiss()
}
}
if (!isOwnNote) {
VerticalDivider(color = primaryLight)
@@ -52,6 +52,7 @@ fun RefreshingChatroomFeedView(
nav: (String) -> Unit,
routeForLastRead: String,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
avoidDraft: String? = null,
scrollStateKey: String? = null,
enablePullRefresh: Boolean = true,
@@ -65,6 +66,7 @@ fun RefreshingChatroomFeedView(
nav,
routeForLastRead,
onWantsToReply,
onWantsToEditDraft,
avoidDraft,
)
}
@@ -79,6 +81,7 @@ fun RenderChatroomFeedView(
nav: (String) -> Unit,
routeForLastRead: String,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
avoidDraft: String? = null,
) {
val feedState by viewModel.feedContent.collectAsStateWithLifecycle()
@@ -99,6 +102,7 @@ fun RenderChatroomFeedView(
nav,
routeForLastRead,
onWantsToReply,
onWantsToEditDraft,
avoidDraft,
)
}
@@ -117,6 +121,7 @@ fun ChatroomFeedLoaded(
nav: (String) -> Unit,
routeForLastRead: String,
onWantsToReply: (Note) -> Unit,
onWantsToEditDraft: (Note) -> Unit,
avoidDraft: String? = null,
) {
LaunchedEffect(state.feed.value.firstOrNull()) {
@@ -140,6 +145,7 @@ fun ChatroomFeedLoaded(
accountViewModel = accountViewModel,
nav = nav,
onWantsToReply = onWantsToReply,
onWantsToEditDraft = onWantsToEditDraft,
)
}
NewSubject(item)
@@ -614,7 +614,14 @@ fun NoteMaster(
ReactionsRow(note, true, editState, accountViewModel, nav)
}
NoteQuickActionMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel)
NoteQuickActionMenu(
note = note,
popupExpanded = popupExpanded,
onDismiss = { popupExpanded = false },
onWantsToEditDraft = { },
accountViewModel = accountViewModel,
nav = nav,
)
}
}
@@ -298,6 +298,9 @@ fun ChannelScreen(
routeForLastRead = "Channel/${channel.idHex}",
avoidDraft = newPostModel.draftTag,
onWantsToReply = { replyTo.value = it },
onWantsToEditDraft = {
newPostModel.load(accountViewModel, null, null, null, null, it)
},
)
}
@@ -399,6 +402,7 @@ fun DisplayReplyingToNote(
accountViewModel = accountViewModel,
nav = nav,
onWantsToReply = {},
onWantsToEditDraft = {},
)
}
@@ -326,6 +326,9 @@ fun ChatroomScreen(
onWantsToReply = {
replyTo.value = it
},
onWantsToEditDraft = {
newPostModel.load(accountViewModel, null, null, null, null, it)
},
)
}