mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-11 03:00:49 +02:00
Displaying correct edits on the new edit proposal
This commit is contained in:
parent
f42ec3c149
commit
e9fd62dc26
@ -1136,6 +1136,11 @@ class EditState() {
|
|||||||
|
|
||||||
fun latest() = modificationsList.lastOrNull()
|
fun latest() = modificationsList.lastOrNull()
|
||||||
|
|
||||||
|
fun latestBefore(createdAt: Long?): Note? {
|
||||||
|
if (createdAt == null) return latest()
|
||||||
|
return modificationsList.lastOrNull { (it.createdAt() ?: Long.MAX_VALUE) < createdAt }
|
||||||
|
}
|
||||||
|
|
||||||
fun nextModification() {
|
fun nextModification() {
|
||||||
if (modificationToShowIndex < 0) {
|
if (modificationToShowIndex < 0) {
|
||||||
modificationToShowIndex = 0
|
modificationToShowIndex = 0
|
||||||
@ -1370,7 +1375,6 @@ private fun RenderNoteRow(
|
|||||||
makeItShort,
|
makeItShort,
|
||||||
canPreview,
|
canPreview,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
editState,
|
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
@ -1509,35 +1513,12 @@ fun RenderTextModificationEvent(
|
|||||||
makeItShort: Boolean,
|
makeItShort: Boolean,
|
||||||
canPreview: Boolean,
|
canPreview: Boolean,
|
||||||
backgroundColor: MutableState<Color>,
|
backgroundColor: MutableState<Color>,
|
||||||
editStateByAuthor: State<GenericLoadable<EditState>>,
|
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val noteEvent = note.event as? TextNoteModificationEvent ?: return
|
val noteEvent = note.event as? TextNoteModificationEvent ?: return
|
||||||
val noteAuthor = note.author ?: return
|
val noteAuthor = note.author ?: return
|
||||||
|
|
||||||
// val isAuthorTheLoggedUser = remember(note.event) { accountViewModel.isLoggedUser(note.author) }
|
|
||||||
|
|
||||||
val editState =
|
|
||||||
remember {
|
|
||||||
derivedStateOf {
|
|
||||||
val loadable = editStateByAuthor.value as? GenericLoadable.Loaded<EditState>
|
|
||||||
|
|
||||||
val state = EditState()
|
|
||||||
|
|
||||||
val latestChangeByAuthor =
|
|
||||||
if (loadable != null && loadable.loaded.hasModificationsToShow()) {
|
|
||||||
loadable.loaded.latest()
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
state.updateModifications(listOfNotNull(latestChangeByAuthor, note))
|
|
||||||
|
|
||||||
GenericLoadable.Loaded(state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val wantsToEditPost =
|
val wantsToEditPost =
|
||||||
remember {
|
remember {
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
@ -1550,6 +1531,13 @@ fun RenderTextModificationEvent(
|
|||||||
mutableStateOf(accountViewModel.isLoggedUser(authorOfTheOriginalNote))
|
mutableStateOf(accountViewModel.isLoggedUser(authorOfTheOriginalNote))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noteEvent.editedNote()?.let {
|
||||||
|
LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { baseOriginalNote ->
|
||||||
|
baseOriginalNote?.let {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = MaterialTheme.colorScheme.imageModifier,
|
modifier = MaterialTheme.colorScheme.imageModifier,
|
||||||
) {
|
) {
|
||||||
@ -1583,6 +1571,28 @@ fun RenderTextModificationEvent(
|
|||||||
baseNote?.let {
|
baseNote?.let {
|
||||||
val noteState by baseNote.live().metadata.observeAsState()
|
val noteState by baseNote.live().metadata.observeAsState()
|
||||||
|
|
||||||
|
val editStateOriginalNote = observeEdits(baseNote = baseNote, accountViewModel = accountViewModel)
|
||||||
|
|
||||||
|
val editState =
|
||||||
|
remember(note) {
|
||||||
|
derivedStateOf {
|
||||||
|
val loadable = editStateOriginalNote.value as? GenericLoadable.Loaded<EditState>
|
||||||
|
|
||||||
|
val state = EditState()
|
||||||
|
|
||||||
|
val latestChangeByAuthor =
|
||||||
|
if (loadable != null && loadable.loaded.hasModificationsToShow()) {
|
||||||
|
loadable.loaded.latestBefore(note.createdAt())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
state.updateModifications(listOfNotNull(latestChangeByAuthor, note))
|
||||||
|
|
||||||
|
GenericLoadable.Loaded(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(key1 = noteState) {
|
LaunchedEffect(key1 = noteState) {
|
||||||
val newAuthor = accountViewModel.isLoggedUser(noteState?.note?.author)
|
val newAuthor = accountViewModel.isLoggedUser(noteState?.note?.author)
|
||||||
|
|
||||||
|
@ -576,7 +576,6 @@ fun NoteMaster(
|
|||||||
makeItShort = false,
|
makeItShort = false,
|
||||||
canPreview = true,
|
canPreview = true,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
editState,
|
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user