@@ -66,15 +66,20 @@ import cmp.navigation.components.MifosTopAppBar
6666import cmp.navigation.components.ScaffoldNavigationData
6767import cmp.navigation.navigation.HomeDestinationsScreen
6868import cmp.navigation.ui.rememberMifosNavController
69+ import co.touchlab.kermit.Logger
6970import com.mifos.core.common.utils.Constants
7071import com.mifos.core.designsystem.theme.DesignToken
72+ import com.mifos.core.model.objects.searchrecord.GenericSearchRecord
73+ import com.mifos.core.model.objects.searchrecord.RecordType
7174import com.mifos.core.ui.RootTransitionProviders
7275import com.mifos.core.ui.util.EventsEffect
7376import com.mifos.feature.activate.navigateToActivateRoute
7477import com.mifos.feature.center.navigation.centerNavGraph
7578import com.mifos.feature.center.navigation.navigateCenterDetailsScreenRoute
7679import com.mifos.feature.center.navigation.navigateCreateCenterScreenRoute
7780import com.mifos.feature.center.navigation.navigateToCenterListScreenRoute
81+ import com.mifos.feature.client.clientAddress.navigateToClientAddressRoute
82+ import com.mifos.feature.client.clientIdentifiersList.navigateToClientIdentifiersListScreen
7883import com.mifos.feature.client.clientProfile.navigateToClientProfileRoute
7984import com.mifos.feature.client.navigation.clientNavGraph
8085import com.mifos.feature.client.navigation.navigateClientDetailsScreen
@@ -94,15 +99,18 @@ import com.mifos.feature.savings.navigation.navigateToSavingsAccountSummaryScree
9499import com.mifos.feature.search.navigation.SearchScreenRoute
95100import com.mifos.feature.search.navigation.navigateToSearchScreen
96101import com.mifos.feature.search.navigation.searchNavGraph
102+ import com.mifos.feature.searchrecord.navigation.navigateToSearchRecord
103+ import com.mifos.feature.searchrecord.navigation.searchRecordNavigation
97104import kotlinx.collections.immutable.persistentListOf
98105import kotlinx.coroutines.launch
99106import org.jetbrains.compose.resources.painterResource
100107import org.jetbrains.compose.resources.stringResource
101108import org.koin.compose.viewmodel.koinViewModel
102- import org.mifos.core.designsystem.component.MifosTopAppBar
103109import org.mifos.navigation.generated.resources.Res
110+ import org.mifos.navigation.generated.resources.cmp_navigation_dp_placeholder
104111import org.mifos.navigation.generated.resources.cmp_navigation_mifos
105112import org.mifos.navigation.generated.resources.cmp_navigation_no_internet
113+ import org.mifos.navigation.generated.resources.cmp_navigation_profile_header
106114import org.mifos.navigation.generated.resources.drawer_profile_header
107115import org.mifos.navigation.generated.resources.ic_dp_placeholder
108116
@@ -120,6 +128,7 @@ internal fun AuthenticatedNavbarNavigationScreen(
120128 val scope = rememberCoroutineScope()
121129 val snackbarHostState = remember { SnackbarHostState () }
122130 val isOffline by viewModel.isOffline.collectAsStateWithLifecycle()
131+ val state by viewModel.stateFlow.collectAsStateWithLifecycle()
123132
124133 EventsEffect (eventFlow = viewModel.eventFlow) { event ->
125134 navController.apply {
@@ -166,6 +175,7 @@ internal fun AuthenticatedNavbarNavigationScreen(
166175 }
167176
168177 AuthenticatedNavbarNavigationScreenContent (
178+ state = state,
169179 navController = navController,
170180 snackbarHostState = snackbarHostState,
171181 modifier = modifier,
@@ -181,6 +191,7 @@ internal fun AuthenticatedNavbarNavigationScreen(
181191@OptIn(ExperimentalMaterial3Api ::class )
182192@Composable
183193internal fun AuthenticatedNavbarNavigationScreenContent (
194+ state : AuthenticatedNavbarState ,
184195 navController : NavHostController ,
185196 onDrawerItemClick : (String ) -> Unit ,
186197 navigateToDocumentScreen : (Int , String ) -> Unit ,
@@ -190,8 +201,13 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
190201 onAction : (AuthenticatedNavBarAction ) -> Unit ,
191202) {
192203 val navBackStackEntry by navController.currentBackStackEntryAsState()
193- var selectedItemIndex by rememberSaveable { mutableStateOf<Int ?>(null ) }
204+ val currentRoute = navBackStackEntry?.destination?.route
205+
206+ LaunchedEffect (currentRoute) {
207+ onAction(AuthenticatedNavBarAction .OnRouteChanged (currentRoute))
208+ }
194209
210+ var selectedItemIndex by rememberSaveable { mutableStateOf<Int ?>(null ) }
195211 val drawerState = rememberDrawerState(initialValue = DrawerValue .Closed )
196212 val scope = rememberCoroutineScope()
197213
@@ -217,66 +233,27 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
217233 drawerState = drawerState,
218234 drawerContent = {
219235 ModalDrawerSheet (modifier = Modifier .requiredWidth(320 .dp)) {
220- Column (
221- modifier = Modifier .verticalScroll(rememberScrollState()),
222- ) {
223- Box (
224- modifier = Modifier
225- .fillMaxWidth()
226- .height(200 .dp),
227- ) {
228- Image (
229- modifier = Modifier .fillMaxSize(),
230- contentScale = ContentScale .Crop ,
231- painter = painterResource(Res .drawable.drawer_profile_header),
232- contentDescription = " Profile header" ,
233- )
236+ Column (modifier = Modifier .verticalScroll(rememberScrollState())) {
237+ Box (modifier = Modifier .fillMaxWidth().height(200 .dp)) {
238+ Image (modifier = Modifier .fillMaxSize(), contentScale = ContentScale .Crop , painter = painterResource(Res .drawable.drawer_profile_header), contentDescription = stringResource(Res .string.cmp_navigation_profile_header))
234239 Column (modifier = Modifier .padding(32 .dp)) {
235240 Column (horizontalAlignment = Alignment .CenterHorizontally ) {
236- Image (
237- modifier = Modifier
238- .size(64 .dp)
239- .clip(CircleShape ),
240- painter = painterResource(Res .drawable.ic_dp_placeholder),
241- contentDescription = " DP place holder" ,
242- )
243- Text (
244- text = stringResource(Res .string.cmp_navigation_mifos),
245- color = Color .White ,
246- style = MaterialTheme .typography.titleMedium,
247- )
241+ Image (modifier = Modifier .size(64 .dp).clip(CircleShape ), painter = painterResource(Res .drawable.ic_dp_placeholder), contentDescription = stringResource(Res .string.cmp_navigation_dp_placeholder))
242+ Text (text = stringResource(Res .string.cmp_navigation_mifos), color = Color .White , style = MaterialTheme .typography.titleMedium)
248243 }
249244 }
250245 }
251246 Spacer (modifier = Modifier .height(DesignToken .padding.small))
252247 navigationDrawerTabs.forEachIndexed { index, item ->
253248 NavigationDrawerItem (
254- label = {
255- Text (
256- text = stringResource(item.title),
257- style = MaterialTheme .typography.bodyMedium,
258- )
259- },
249+ label = { Text (text = stringResource(item.title), style = MaterialTheme .typography.bodyMedium) },
260250 selected = index == selectedItemIndex,
261251 onClick = {
262252 selectedItemIndex = index
263253 onDrawerItemClick(navigationDrawerTabs[index].route)
264- scope.launch {
265- drawerState.close()
266- }
267- },
268- icon = {
269- item.icon?.let {
270- Icon (
271- imageVector = if (index == selectedItemIndex) {
272- it
273- } else {
274- it
275- },
276- contentDescription = stringResource(item.title),
277- )
278- }
254+ scope.launch { drawerState.close() }
279255 },
256+ icon = { item.icon?.let { Icon (imageVector = it, contentDescription = stringResource(item.title)) } },
280257 modifier = Modifier .padding(NavigationDrawerItemDefaults .ItemPadding ),
281258 )
282259 if (index == (navigationDrawerTabs.size - 2 )) {
@@ -289,15 +266,17 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
289266 ) {
290267 MifosScaffold (
291268 topBar = {
292- MifosTopAppBar (
293- onNavigationIconClick = {
294- scope.launch {
295- drawerState.open()
296- }
297- },
298- onSearchIconClick = {},
299- onNotificationIconClick = {},
300- )
269+ if (state.isTopBarVisible) {
270+ MifosTopAppBar (
271+ onNavigationIconClick = {
272+ scope.launch {
273+ drawerState.open()
274+ }
275+ },
276+ onSearchIconClick = {},
277+ onNotificationIconClick = {},
278+ )
279+ }
301280 },
302281 contentWindowInsets = WindowInsets (0 .dp),
303282 navigationData = ScaffoldNavigationData (
@@ -393,6 +372,30 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
393372 )
394373 },
395374 hasDatatables = navController::navigateDataTableList,
375+ onNavigateToSearch = { type ->
376+ navController.navigateToSearchRecord(type)
377+ },
378+ )
379+
380+ searchRecordNavigation(
381+ onBackClick = { navController.popBackStack() },
382+ onRecordSelected = { record: GenericSearchRecord ->
383+ val clientId = record.metadata[Constants .CLIENT_ID ]?.toIntOrNull()
384+
385+ if (clientId != null ) {
386+ when {
387+ record.type.equals(RecordType .ADDRESS .name, ignoreCase = true ) -> {
388+ navController.navigateToClientAddressRoute(id = clientId)
389+ }
390+
391+ record.type.equals(RecordType .IDENTIFIER .name, ignoreCase = true ) -> {
392+ navController.navigateToClientIdentifiersListScreen(clientId = clientId)
393+ }
394+ }
395+ } else {
396+ Logger .w(" AuthenticatedNavbar" ) { " Invalid Client ID selected for record: ${record.id} " }
397+ }
398+ },
396399 )
397400 }
398401 }
0 commit comments