Skip to content

Commit

Permalink
code clean up and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OkelloSam21 committed Apr 16, 2024
1 parent 6287759 commit 1667a5d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -56,13 +51,13 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.samuelokello.kazihub.R
import com.samuelokello.kazihub.presentation.destinations.SignInScreenDestination
import com.samuelokello.kazihub.presentation.shared.authentication.common.HandleError
import com.samuelokello.kazihub.presentation.shared.authentication.common.HandleLoading
import com.samuelokello.kazihub.presentation.shared.authentication.common.HandleSuccess
import com.samuelokello.kazihub.presentation.shared.authentication.sign_up.SignUpEvent
import com.samuelokello.kazihub.presentation.shared.authentication.sign_up.SignUpState
import com.samuelokello.kazihub.presentation.shared.authentication.sign_up.SignUpViewModel
import com.samuelokello.kazihub.presentation.shared.destinations.SignInScreenDestination
import com.samuelokello.kazihub.ui.theme.KaziHubTheme
import com.samuelokello.kazihub.ui.theme.primaryLight
import com.samuelokello.kazihub.utils.UserRole
Expand All @@ -88,6 +83,7 @@ fun SignUpScreen(userType: UserRole, navigator: DestinationsNavigator) {
state = state,
onEvent = viewModel::onEvent,
navigateToSIgnIn = { navigator.navigate(SignInScreenDestination(userType)) },
onClick = {},
userType = userType
)
}
Expand All @@ -99,27 +95,29 @@ private fun SignUpContent(
state: SignUpState,
onEvent: (SignUpEvent) -> Unit,
onClick: () -> Unit,
navigateToSIgnIn: () -> Unit
navigateToSIgnIn: () -> Unit,
userType: UserRole
) {
val isPasswordVisible = remember { mutableStateOf(false) }
val isFormValid =
state.userName.isNotBlank() &&
state.firstName.isNotBlank() &&
state.lastName.isNotBlank() &&
state.password.length > 8
state.userName.isNotBlank() &&
state.firstName.isNotBlank() &&
state.lastName.isNotBlank() &&
state.password.length > 8


HandleLoading(state)
HandleError(state)
HandleSuccess(state,"Sign Up Successful")
HandleSuccess(state, "Sign Up Successful")
HandleNavigation(state, navigateToSIgnIn)


SignUpForm(
state = state,
isPasswordVisible = isPasswordVisible,
isFormValid = isFormValid,
onEvent = onEvent,
navigateToSIgnIn = navigateToSIgnIn,
onClick = navigateToSIgnIn,
userRole = userType
)

Expand All @@ -131,7 +129,7 @@ fun SignUpForm(
isPasswordVisible: MutableState<Boolean>,
isFormValid: Boolean,
onEvent: (SignUpEvent) -> Unit,
navigateToSIgnIn: () -> Unit,
onClick: () -> Unit,
userRole: UserRole
) {
Column(
Expand Down Expand Up @@ -226,12 +224,16 @@ fun SignUpForm(
label = { Text(text = "Password") },
placeholder = { Text(text = "Password") },
trailingIcon = {
IconButton(onClick = {
isPasswordVisible.value = !isPasswordVisible.value
}) {
IconButton(
onClick = {
isPasswordVisible.value = !isPasswordVisible.value
}
) {
Icon(
imageVector = if (isPasswordVisible.value) Icons.Default.VisibilityOff else Icons.Default.Visibility,
contentDescription = null
imageVector = if (isPasswordVisible.value)
Icons.Default.VisibilityOff
else Icons.Default.Visibility,
contentDescription = null,
)
}
},
Expand Down Expand Up @@ -260,15 +262,16 @@ fun SignUpForm(
Log.d("SignUpScreen", "Password: ${state.password}")
Log.d("SignUpScreen", "IsFormValid: $isFormValid")
if (isFormValid) {
onEvent(
SignUpEvent.OnSignUpClicked(
state.userName,
state.firstName,
state.lastName,
state.password,
role = userRole.name
onEvent(
SignUpEvent.OnSignUpClicked(
state.userName,
state.firstName,
state.lastName,
state.password,
role = userRole.name
)
)
)}
}
Log.d("SignUpScreen", "SignUpContent: $userRole")
},
modifier = Modifier
Expand All @@ -292,10 +295,10 @@ fun SignUpForm(
Column(
modifier = Modifier.fillMaxWidth()
) {
Row (
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally)
){
) {
HorizontalDivider(
modifier = Modifier
.weight(1f)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.samuelokello.kazihub.presentation.shared.authentication.sign_up

import com.samuelokello.kazihub.presentation.shared.authentication.common.AuthState

data class SignUpState (
// val isSignUpSuccessful: Boolean = false,
val authenticationError: String? = null,
val signUpError: String? = null,
val signUpSuccess: Boolean = false,
val userName: String = "",
val firstName: String = "",
val lastName: String = "",
val role: String = "",
val password: String = "",
val navigateToHome: Boolean = false,
val isLoading: Boolean = false,
override val isLoading: Boolean = false,
val navigateToSignIn: Boolean = false
)
): AuthState
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.samuelokello.kazihub.presentation.shared.navigation.bottom_bar_navig


import com.samuelokello.kazihub.R
import com.samuelokello.kazihub.presentation.destinations.Destination
import com.samuelokello.kazihub.presentation.destinations.*
import com.samuelokello.kazihub.presentation.shared.destinations.Destination
import com.samuelokello.kazihub.presentation.shared.destinations.HomeScreenDestination
import com.samuelokello.kazihub.presentation.shared.destinations.MessagesScreenDestination
import com.samuelokello.kazihub.presentation.shared.destinations.ProfileScreenDestination
import com.samuelokello.kazihub.presentation.shared.destinations.SettingsScreenDestination

sealed class BottomNavItem(var title: String, var icon: Int, var destination: Destination) {
data object Home : BottomNavItem(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.samuelokello.kazihub.presentation.shared.profile

import android.os.Build
import androidx.annotation.RequiresExtension
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import com.samuelokello.kazihub.presentation.business.BusinessProfileViewModel

@RequiresExtension(extension = Build.VERSION_CODES.S, version = 7)
@Composable
fun BusinessProfileScreen(viewModel: BusinessProfileViewModel) {
val state by viewModel.profile.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.samuelokello.kazihub.presentation.worker

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.lifecycle.viewmodel.compose.viewModel
import com.samuelokello.kazihub.ui.theme.KaziHubTheme

@Composable
fun WorkerDetailScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SearchBarDefaults
Expand All @@ -49,7 +45,6 @@ import androidx.compose.ui.unit.dp
import com.samuelokello.kazihub.R
import com.samuelokello.kazihub.presentation.shared.components.AppBar
import com.samuelokello.kazihub.presentation.shared.components.JobCard
import com.samuelokello.kazihub.presentation.shared.navigation.bottom_bar_navigation.navigationItems
import kotlinx.coroutines.launch

/**
Expand All @@ -68,48 +63,48 @@ fun WorkerHomeScreen() {
val searchQuery by remember { mutableStateOf("") }
var selectedItemIndex by remember { mutableIntStateOf(0) }

ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet {
Spacer(modifier = Modifier.height(16.dp))
navigationItems.forEachIndexed { index, item ->
NavigationDrawerItem(
label = {
Text(text = item.title)
},
selected = index == selectedItemIndex,
onClick = {
// navController.navigate(item.route)
selectedItemIndex = index
scope.launch {
drawerState.close()
}
},
icon = {
Icon(
imageVector = if (index == selectedItemIndex) {
item.selectedIcon
} else item.unselectedIcon,
contentDescription = item.title
)
},
badge = {
item.badgeCount?.let {
Text(text = item.badgeCount.toString())
}
},
modifier = Modifier
.padding(NavigationDrawerItemDefaults.ItemPadding),
colors = NavigationDrawerItemDefaults.colors(
selectedContainerColor = MaterialTheme.colorScheme.primary,
unselectedContainerColor = MaterialTheme.colorScheme.surface,
)
)
}
}
}
) {
// ModalNavigationDrawer(
// drawerState = drawerState,
// drawerContent = {
// ModalDrawerSheet {
// Spacer(modifier = Modifier.height(16.dp))
// navigationItems.forEachIndexed { index, item ->
// NavigationDrawerItem(
// label = {
// Text(text = item.title)
// },
// selected = index == selectedItemIndex,
// onClick = {
//// navController.navigate(item.route)
// selectedItemIndex = index
// scope.launch {
// drawerState.close()
// }
// },
// icon = {
// Icon(
// imageVector = if (index == selectedItemIndex) {
// item.selectedIcon
// } else item.unselectedIcon,
// contentDescription = item.title
// )
// },
// badge = {
// item.badgeCount?.let {
// Text(text = item.badgeCount.toString())
// }
// },
// modifier = Modifier
// .padding(NavigationDrawerItemDefaults.ItemPadding),
// colors = NavigationDrawerItemDefaults.colors(
// selectedContainerColor = MaterialTheme.colorScheme.primary,
// unselectedContainerColor = MaterialTheme.colorScheme.surface,
// )
// )
// }
// }
// }
// ) {
Scaffold(
topBar = {
AppBar {
Expand Down Expand Up @@ -224,7 +219,7 @@ fun WorkerHomeScreen() {
}
}
}
}
//}

/**
* Recent Post
Expand Down

0 comments on commit 1667a5d

Please sign in to comment.