<commit_before>module Main where

import Pux.Routing.Bob.Component as Pux.Routing.Bob.Component
import Routing.Bob as Routing.Bob
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import DOM (DOM)
import Data.Bifunctor (class Bifunctor, bimap)
import Data.Generic (class Generic)
import Data.Maybe (Maybe(Just, Nothing))
import Partial.Unsafe (unsafePartial)
import Pux (renderToDOM, start, noEffects, Update)
import Pux.Html (Html, div, ul, text, br, a, li)
import Pux.Html.Attributes (href, className)
import Pux.Html.Elements (p)
import Pux.Html.Events (onClick)
import Pux.Routing.Bob (RoutingAction(RoutingError, Routed), setInitialRoute)
import Pux.Routing.Bob.Component (View, Action(RawAction, RoutingAction), link', sampleUrl)
import Routing.Bob (Router)
import Signal.Channel (CHANNEL)
import Type.Proxy (Proxy(Proxy))
import Prelude hiding (div)

-- Main window component

data MainWindowRoute
  = Profile
  | Inbox
  | Settings
derive instance genericMainWindowRoute :: Generic MainWindowRoute
derive instance eqMainWindowRoute :: Eq MainWindowRoute

data MainWindowRawAction
  = ProfileClick
  | InboxClick
  | SettingsClick

type MainWindowState =
  { activeTab :: MainWindowRoute
  -- clicks counters - just to include other state and actions
  , profileCounter :: Int
  , inboxCounter :: Int
  , settingsCounter :: Int
  }

type MainWindowAction = Action MainWindowRoute MainWindowRawAction

mainWindowUpdate :: (Router MainWindowRoute) -> Update MainWindowState MainWindowAction (dom :: DOM)
mainWindowUpdate _ (RawAction ProfileClick) state =
  noEffects $ state { profileCounter = state.profileCounter + 1 }
mainWindowUpdate _ (RawAction InboxClick) state =
  noEffects $ state { inboxCounter = state.inboxCounter + 1 }
mainWindowUpdate _ (RawAction SettingsClick) state =
  noEffects $ state { settingsCounter = state.settingsCounter + 1 }
mainWindowUpdate _ (RoutingAction (Routed r)) state =
  noEffects $ state { activeTab = r }
mainWindowUpdate _ (RoutingAction (RoutingError _)) state = noEffects state
mainWindowUpdate router (RoutingAction a) state =
  Pux.Routing.Bob.Component.update router a state

mainWindowView :: View MainWindowState MainWindowRoute MainWindowRawAction
mainWindowView router mapAction state =
  div []
    [ ul []
        [ tabHeader Profile "profile"
        , tabHeader Inbox "inbox"
        , tabHeader Settings "settings"
        ]
    , div []
        case state.activeTab of
          Profile -> [ tabBody (mapAction (RawAction ProfileClick)) state.profileCounter "profile" ]
          Inbox -> [ tabBody (mapAction (RawAction InboxClick)) state.inboxCounter "inbox" ]
          Settings -> [ tabBody (mapAction (RawAction SettingsClick)) state.settingsCounter "settings" ]
    ]
 where
  link'' = link' mapAction router
  tabHeader route label =
    li
      (if state.activeTab == route
        then [className "active"]
        else [])
      [ link''
          route
          []
          [ text label ]
      ]
  tabBody action counter label =
    a [ href "#", onClick $ const action]
      [ text (label <> " action"), br [] [], text <<< show $ counter ]

-- Sidebar component

data SideBarRoute
  = Expanded
  | Minimized
derive instance genericSideBarRoute :: Generic SideBarRoute
derive instance eqSideBarRoute :: Eq SideBarRoute

type SideBarState = SideBarRoute

type SideBarRawAction = Unit

type SideBarAction = Action SideBarRoute SideBarRawAction

-- | This is how you can cheat to cleanup your subcomponent
-- | `update` API a bit and make subcomponent more self-contained.
-- | I've left this example here, side by side with default,
-- | safe implementation of `Router MainWidowRoute` construction,
-- | just for comparison.
sideBarRouter :: Router SideBarRoute
sideBarRouter =
  unsafePartial
    (case (Routing.Bob.router (Proxy :: Proxy SideBarRoute)) of Just r -> r)

sideBarUpdate :: forall eff. Update SideBarState SideBarAction (dom :: DOM | eff)
sideBarUpdate (RawAction _) state = noEffects state
sideBarUpdate (RoutingAction (Routed r)) state | r == Expanded = noEffects Expanded
                                               | r == Minimized = noEffects Minimized
sideBarUpdate (RoutingAction (RoutingError _)) state = noEffects state
sideBarUpdate (RoutingAction a) state =
  Pux.Routing.Bob.Component.update sideBarRouter a state

sideBarView :: View SideBarState SideBarRoute SideBarRawAction
sideBarView router mapAction state =<commit_msg>Cosmetics<commit_after>module Main where

import Pux.Routing.Bob.Component as Pux.Routing.Bob.Component
import Routing.Bob as Routing.Bob
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import DOM (DOM)
import Data.Bifunctor (class Bifunctor, bimap)
import Data.Generic (class Generic)
import Data.Maybe (Maybe(Just, Nothing))
import Partial.Unsafe (unsafePartial)
import Pux (renderToDOM, start, noEffects, Update)
import Pux.Html (Html, div, ul, text, br, a, li)
import Pux.Html.Attributes (href, className)
import Pux.Html.Elements (p)
import Pux.Html.Events (onClick)
import Pux.Routing.Bob (RoutingAction(RoutingError, Routed), setInitialRoute)
import Pux.Routing.Bob.Component (View, Action(RawAction, RoutingAction), link', sampleUrl)
import Routing.Bob (Router)
import Signal.Channel (CHANNEL)
import Type.Proxy (Proxy(Proxy))
import Prelude hiding (div)

-- Main window component

data MainWindowRoute
  = Profile
  | Inbox
  | Settings
derive instance genericMainWindowRoute :: Generic MainWindowRoute
derive instance eqMainWindowRoute :: Eq MainWindowRoute

data MainWindowRawAction
  = ProfileClick
  | InboxClick
  | SettingsClick

type MainWindowState =
  { activeTab :: MainWindowRoute
  -- clicks counters - just to include other state and actions
  , profileCounter :: Int
  , inboxCounter :: Int
  , settingsCounter :: Int
  }

type MainWindowAction = Action MainWindowRoute MainWindowRawAction

mainWindowUpdate :: (Router MainWindowRoute) -> Update MainWindowState MainWindowAction (dom :: DOM)
mainWindowUpdate _ (RawAction ProfileClick) state =
  noEffects $ state { profileCounter = state.profileCounter + 1 }
mainWindowUpdate _ (RawAction InboxClick) state =
  noEffects $ state { inboxCounter = state.inboxCounter + 1 }
mainWindowUpdate _ (RawAction SettingsClick) state =
  noEffects $ state { settingsCounter = state.settingsCounter + 1 }
mainWindowUpdate _ (RoutingAction (Routed r)) state =
  noEffects $ state { activeTab = r }
mainWindowUpdate _ (RoutingAction (RoutingError _)) state = noEffects state
mainWindowUpdate router (RoutingAction a) state =
  Pux.Routing.Bob.Component.update router a state

mainWindowView :: View MainWindowState MainWindowRoute MainWindowRawAction
mainWindowView router mapAction state =
  div []
    [ ul []
        [ tabHeader Profile "profile"
        , tabHeader Inbox "inbox"
        , tabHeader Settings "settings"
        ]
    , div []
        case state.activeTab of
          Profile -> [ tabBody (mapAction (RawAction ProfileClick)) state.profileCounter "profile" ]
          Inbox -> [ tabBody (mapAction (RawAction InboxClick)) state.inboxCounter "inbox" ]
          Settings -> [ tabBody (mapAction (RawAction SettingsClick)) state.settingsCounter "settings" ]
    ]
 where
  link'' = link' mapAction router
  tabHeader route label =
    li
      (if state.activeTab == route
        then [className "active"]
        else [])
      [ link''
          route
          []
          [ text label ]
      ]
  tabBody action counter label =
    a [ href "#", onClick $ const action]
      [ text (label <> " action"), br [] [], text <<< show $ counter ]

-- Sidebar component

data SideBarRoute
  = Expanded
  | Minimized
derive instance genericSideBarRoute :: Generic SideBarRoute
derive instance eqSideBarRoute :: Eq SideBarRoute

type SideBarState = SideBarRoute

type SideBarRawAction = Unit

type SideBarAction = Action SideBarRoute SideBarRawAction

-- | This is how you can cheat to cleanup your subcomponent
-- | `update` API a bit and make subcomponent more self-contained.
-- | I've left this example here, side by side with default,
-- | safe implementation of `Router MainWidowRoute` construction,
-- | just for comparison.
sideBarRouter :: Router SideBarRoute
sideBarRouter =
  unsafePartial
    (case (Routing.Bob.router (Proxy :: Proxy SideBarRoute)) of Just r -> r)

sideBarUpdate :: forall eff. Update SideBarState SideBarAction (dom :: DOM | eff)
sideBarUpdate (RawAction _) state = noEffects state
-- current state is just given route, because State = SideBarRoute ;-)
sideBarUpdate (RoutingAction (Routed r)) _ = noEffects r
sideBarUpdate (RoutingAction (RoutingError _)) state = noEffects state
sideBarUpdate (RoutingAction a) state =
  Pux.Routing.Bob.Component.update sideBarRouter a state

sideBarView :: View SideBarState SideBarRoute SideBarRawAction
sideBarView router mapAction state =
{'fraction_non_alphanumeric': 0.08607480847228481, 'fraction_numerical': 0.0006759801712483101, 'mean_word_length': 4.1017241379310345, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1455034', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2477, 'n_words': 806}