1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.components.menu.middleware
7 import androidx.navigation.NavController
8 import kotlinx.coroutines.CoroutineScope
9 import kotlinx.coroutines.Dispatchers
10 import kotlinx.coroutines.launch
11 import mozilla.components.lib.state.Middleware
12 import mozilla.components.lib.state.MiddlewareContext
13 import org.mozilla.fenix.R
14 import org.mozilla.fenix.components.menu.MenuDialogFragmentDirections
15 import org.mozilla.fenix.components.menu.store.MenuAction
16 import org.mozilla.fenix.components.menu.store.MenuState
17 import org.mozilla.fenix.components.menu.store.MenuStore
18 import org.mozilla.fenix.ext.nav
21 * [Middleware] implementation for handling navigating events based on [MenuAction]s that are
22 * dispatched to the [MenuStore].
24 class MenuNavigationMiddleware(
25 private val navController: NavController,
26 private val scope: CoroutineScope = CoroutineScope(Dispatchers.Main),
27 ) : Middleware<MenuState, MenuAction> {
30 context: MiddlewareContext<MenuState, MenuAction>,
31 next: (MenuAction) -> Unit,
38 is MenuAction.Navigate.Settings -> navController.nav(
39 R.id.menuDialogFragment,
40 MenuDialogFragmentDirections.actionGlobalSettingsFragment(),