Skip to content

Commit

Permalink
added confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
John Oberhauser committed May 20, 2024
1 parent 64a7542 commit fe91d3b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package social.firefly.core.ui.common.dialog

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import social.firefly.core.ui.common.R
import social.firefly.core.ui.common.text.FfTextButton

@Composable
fun blockDomainConfirmationDialog(
domain: String,
onConfirmation: () -> Unit
) : DialogOpener {
var isOpen by remember { mutableStateOf(false) }

if (isOpen) {
FfAlertDialog(
onDismissRequest = { isOpen = false },
title = {
Text(
text = stringResource(
id = R.string.block_domain_confirmation,
domain
)
)
},
confirmButton = {
FfTextButton(
onClick = {
onConfirmation()
isOpen = false
}
) {
Text(text = stringResource(id = R.string.block_domain_confirmed))
}
},
dismissButton = {
FfTextButton(onClick = { isOpen = false }) {
Text(text = stringResource(id = R.string.cancel))
}
}
)
}

return object : DialogOpener {
override fun open() {
isOpen = true
}
}
}
3 changes: 3 additions & 0 deletions core/ui/common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<string name="block_user">Block %s</string>
<string name="unblock_user">Unblock %s</string>

<string name="block_domain_confirmation">Are you sure you want to block the entire domain %s?</string>
<string name="block_domain_confirmed">Block</string>

<string name="mute_user_confirmation">Are you sure you want to mute %s?</string>
<string name="mute_user_confirmed">Mute</string>
<string name="mute_user">Mute %s</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import social.firefly.common.utils.StringFactory
import social.firefly.core.designsystem.icon.FfIcons
import social.firefly.core.designsystem.theme.FfTheme
import social.firefly.core.ui.common.dialog.blockAccountConfirmationDialog
import social.firefly.core.ui.common.dialog.blockDomainConfirmationDialog
import social.firefly.core.ui.common.dialog.deleteStatusConfirmationDialog
import social.firefly.core.ui.common.dialog.muteAccountConfirmationDialog
import social.firefly.core.ui.common.dropdown.FfDropDownItem
Expand Down Expand Up @@ -78,6 +79,10 @@ private fun OverflowMenu(
)
}

val blockDomainDialog = blockDomainConfirmationDialog(domain = post.domain) {
postCardInteractions.onOverflowBlockDomainClicked(post.domain)
}

val deleteStatusDialog = deleteStatusConfirmationDialog {
postCardInteractions.onOverflowDeleteClicked(post.statusId)
}
Expand Down Expand Up @@ -136,9 +141,7 @@ private fun OverflowMenu(
post.domain
).build(context),
expanded = overflowMenuExpanded,
onClick = {
postCardInteractions.onOverflowBlockDomainClicked(post.domain)
}
onClick = { blockDomainDialog.open() }
)
}
}
Expand Down

0 comments on commit fe91d3b

Please sign in to comment.