Skip to content

Commit

Permalink
fix: show unblock user confirmation dialog (WPB-2427)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Aug 18, 2023
1 parent f1996bb commit 018d35e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.core.os.bundleOf
import com.sebaslogen.resaca.hilt.hiltViewModelScoped
import com.wire.android.R
import com.wire.android.model.ClickBlockParams
import com.wire.android.model.ActionableState
import com.wire.android.model.ClickBlockParams
import com.wire.android.navigation.EXTRA_CONNECTION_STATE
import com.wire.android.navigation.EXTRA_USER_ID
import com.wire.android.navigation.EXTRA_USER_NAME
import com.wire.android.ui.common.button.WireButtonState
import com.wire.android.ui.common.button.WirePrimaryButton
import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.dialogs.UnblockUserDialogContent
import com.wire.android.ui.common.dialogs.UnblockUserDialogState
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.visbility.rememberVisibilityState
import com.wire.android.ui.snackbar.LocalSnackbarHostState
import com.wire.android.ui.snackbar.collectAndShowSnackbar
import com.wire.kalium.logic.data.user.ConnectionState
Expand All @@ -66,6 +69,17 @@ fun ConnectionActionButton(
LocalSnackbarHostState.current.collectAndShowSnackbar(snackbarFlow = it.infoMessage)
}
}
val unblockUserDialogState = rememberVisibilityState<UnblockUserDialogState>()

UnblockUserDialogContent(
dialogState = unblockUserDialogState,
onUnblock = { viewModel.onUnblockUser() },
isLoading = viewModel.actionableState().isPerformingAction,
)

if (!viewModel.actionableState().isPerformingAction) {
unblockUserDialogState.dismiss()
}

when (viewModel.actionableState().state) {
ConnectionState.SENT -> WireSecondaryButton(
Expand All @@ -74,11 +88,13 @@ fun ConnectionActionButton(
onClick = viewModel::onCancelConnectionRequest,
clickBlockParams = ClickBlockParams(blockWhenSyncing = true, blockWhenConnecting = true),
)

ConnectionState.ACCEPTED -> WirePrimaryButton(
text = stringResource(R.string.label_open_conversation),
loading = viewModel.actionableState().isPerformingAction,
onClick = viewModel::onOpenConversation,
)

ConnectionState.IGNORED -> WirePrimaryButton(
text = stringResource(R.string.connection_label_accept),
loading = viewModel.actionableState().isPerformingAction,
Expand All @@ -92,6 +108,7 @@ fun ConnectionActionButton(
)
}
)

ConnectionState.PENDING -> Column {
WirePrimaryButton(
text = stringResource(R.string.connection_label_accept),
Expand Down Expand Up @@ -122,14 +139,23 @@ fun ConnectionActionButton(
}
)
}

ConnectionState.BLOCKED -> {
WireSecondaryButton(
text = stringResource(R.string.user_profile_unblock_user),
loading = viewModel.actionableState().isPerformingAction,
onClick = viewModel::onUnblockUser,
onClick = {
unblockUserDialogState.show(
UnblockUserDialogState(
userId = userId,
userName = userName
)
)
},
clickBlockParams = ClickBlockParams(blockWhenSyncing = true, blockWhenConnecting = true),
)
}

ConnectionState.NOT_CONNECTED,
ConnectionState.CANCELLED,
ConnectionState.MISSING_LEGALHOLD_CONSENT -> WirePrimaryButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.PagerState
import com.google.accompanist.pager.rememberPagerState
Expand Down Expand Up @@ -136,10 +135,6 @@ fun OtherUserProfileScreen(viewModel: OtherUserProfileScreenViewModel = hiltView
}

@SuppressLint("UnusedCrossfadeTargetStateParameter", "LongParameterList")
@OptIn(
ExperimentalPagerApi::class,
ExperimentalMaterial3Api::class,
)
@Composable
fun OtherProfileScreenContent(
scope: CoroutineScope,
Expand Down Expand Up @@ -332,7 +327,6 @@ private fun TopBarCollapsing(state: OtherUserProfileState) {
}
}

@OptIn(ExperimentalPagerApi::class)
@Composable
private fun TopBarFooter(
state: OtherUserProfileState,
Expand Down Expand Up @@ -363,7 +357,7 @@ private fun TopBarFooter(
}
}

@OptIn(ExperimentalPagerApi::class, ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun Content(
state: OtherUserProfileState,
Expand Down

0 comments on commit 018d35e

Please sign in to comment.