mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-06 22:53:34 +02:00
Merge branch 'main' of https://github.com/vitorpamplona/amethyst
This commit is contained in:
@@ -630,17 +630,21 @@ private fun BottomRowActions(postViewModel: NewPostViewModel) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PollField(postViewModel: NewPostViewModel) {
|
private fun PollField(postViewModel: NewPostViewModel) {
|
||||||
|
val optionsList = postViewModel.pollOptions
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
postViewModel.pollOptions.values.forEachIndexed { index, _ ->
|
optionsList.forEach { value ->
|
||||||
NewPollOption(postViewModel, index)
|
NewPollOption(postViewModel, value.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
NewPollVoteValueRange(postViewModel)
|
NewPollVoteValueRange(postViewModel)
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = { postViewModel.pollOptions[postViewModel.pollOptions.size] = "" },
|
onClick = {
|
||||||
|
// postViewModel.pollOptions[postViewModel.pollOptions.size] = ""
|
||||||
|
optionsList[optionsList.size] = ""
|
||||||
|
},
|
||||||
border =
|
border =
|
||||||
BorderStroke(
|
BorderStroke(
|
||||||
1.dp,
|
1.dp,
|
||||||
|
@@ -1278,10 +1278,26 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun removePollOption(optionIndex: Int) {
|
fun removePollOption(optionIndex: Int) {
|
||||||
pollOptions.remove(optionIndex)
|
pollOptions.removeOrdered(optionIndex)
|
||||||
saveDraft()
|
saveDraft()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun MutableMap<Int, String>.removeOrdered(index: Int) {
|
||||||
|
val keyList = keys
|
||||||
|
val elementList = values.toMutableList()
|
||||||
|
run stop@{
|
||||||
|
for (i in index until elementList.size) {
|
||||||
|
val nextIndex = i + 1
|
||||||
|
if (nextIndex == elementList.size) return@stop
|
||||||
|
elementList[i] = elementList[nextIndex].also { elementList[nextIndex] = "null" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elementList.removeLast()
|
||||||
|
val newEntries = keyList.zip(elementList) { key, content -> Pair(key, content) }
|
||||||
|
this.clear()
|
||||||
|
this.putAll(newEntries)
|
||||||
|
}
|
||||||
|
|
||||||
fun updatePollOption(
|
fun updatePollOption(
|
||||||
optionIndex: Int,
|
optionIndex: Int,
|
||||||
text: String,
|
text: String,
|
||||||
|
Reference in New Issue
Block a user