@@ -9,6 +9,7 @@ import Lib.Util as Util
99import RemoteData exposing (RemoteData (..) , WebData )
1010import String.Extra exposing (pluralize )
1111import UI
12+ import UI.AnchoredOverlay as AnchoredOverlay exposing (AnchoredOverlay )
1213import UI.Card as Card
1314import UI.DateTime as DateTime
1415import UI.Icon as Icon exposing (Icon )
@@ -25,6 +26,8 @@ import UnisonShare.Paginated as Paginated exposing (Paginated(..))
2526import UnisonShare.Project as Project exposing (ProjectDetails )
2627import UnisonShare.Project.BranchHistory as BranchHistory exposing (HistoryEntry )
2728import UnisonShare.Project.ProjectRef exposing (ProjectRef )
29+ import UnisonShare.Route as Route
30+ import UnisonShare.SwitchBranch as SwitchBranch
2831
2932
3033
@@ -37,23 +40,26 @@ type alias PaginatedBranchHistory =
3740
3841type alias Model =
3942 { history : WebData PaginatedBranchHistory
43+ , switchBranch : SwitchBranch . Model
4044 }
4145
4246
4347preInit : Model
4448preInit =
4549 { history = NotAsked
50+ , switchBranch = SwitchBranch . init
4651 }
4752
4853
4954init : AppContext -> ProjectDetails -> Maybe BranchRef -> Paginated .PageCursorParam -> ( Model , Cmd Msg )
5055init appContext project branchRef cursor =
5156 let
52- branchRef_ : BranchRef
5357 branchRef_ =
5458 Maybe . withDefault ( Project . defaultBrowsingBranch project) branchRef
5559 in
56- ( { history = Loading }
60+ ( { history = Loading
61+ , switchBranch = SwitchBranch . init
62+ }
5763 , fetchProjectBranchHistory appContext project. ref branchRef_ cursor
5864 )
5965
@@ -64,14 +70,41 @@ init appContext project branchRef cursor =
6470
6571type Msg
6672 = FetchProjectBranchHistoryFinished BranchRef ( WebData PaginatedBranchHistory )
73+ | SwitchBranchMsg SwitchBranch . Msg
6774
6875
6976update : AppContext -> ProjectDetails -> Maybe BranchRef -> Msg -> Model -> ( Model , Cmd Msg )
70- update _ _ _ msg model =
77+ update appContext project _ msg model =
7178 case msg of
7279 FetchProjectBranchHistoryFinished _ history ->
7380 ( { model | history = history }, Cmd . none )
7481
82+ SwitchBranchMsg sbMsg ->
83+ let
84+ ( switchBranch, switchBranchCmd, out ) =
85+ SwitchBranch . update appContext project. ref sbMsg model. switchBranch
86+
87+ navCmd =
88+ case out of
89+ SwitchBranch . SwitchToBranchRequest branchRef ->
90+ Route . navigate
91+ appContext. navKey
92+ ( Route . projectHistory
93+ project. ref
94+ ( Just branchRef)
95+ Paginated . NoPageCursor
96+ )
97+
98+ _ ->
99+ Cmd . none
100+ in
101+ ( { model | switchBranch = switchBranch }
102+ , Cmd . batch
103+ [ Cmd . map SwitchBranchMsg switchBranchCmd
104+ , navCmd
105+ ]
106+ )
107+
75108
76109
77110-- EFFECTS
@@ -265,9 +298,12 @@ viewPaginationControls projectRef branchRef cursors =
265298 Paginated . view toLink cursors
266299
267300
268- viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> PaginatedBranchHistory -> PageContent Msg
269- viewPageContent appContext project branchRef ( Paginated history) =
301+ viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> SwitchBranch . Model -> PaginatedBranchHistory -> PageContent Msg
302+ viewPageContent appContext project branchRef switchBranch ( Paginated history) =
270303 let
304+ branchRef_ =
305+ Maybe . withDefault ( Project . defaultBrowsingBranch project) branchRef
306+
271307 entries =
272308 if List . isEmpty history. items then
273309 [ div [] [ text " No entries" ] ]
@@ -279,7 +315,17 @@ viewPageContent appContext project branchRef (Paginated history) =
279315 [ div [ class " history-entries" ] entries
280316 , viewPaginationControls project. ref branchRef history
281317 ]
282- |> PageContent . withPageTitle ( PageTitle . title " History" )
318+ |> PageContent . withPageTitle
319+ ( PageTitle . title " History"
320+ |> PageTitle . withRightSide
321+ [ SwitchBranch . toAnchoredOverlay project. ref
322+ branchRef_
323+ False
324+ switchBranch
325+ |> AnchoredOverlay . map SwitchBranchMsg
326+ |> AnchoredOverlay . view
327+ ]
328+ )
283329
284330
285331view :
@@ -299,7 +345,7 @@ view appContext project branchRef _ model =
299345
300346 Success history ->
301347 ( PageLayout . centeredNarrowLayout
302- ( viewPageContent appContext project branchRef history)
348+ ( viewPageContent appContext project branchRef model . switchBranch history)
303349 PageFooter . pageFooter
304350 |> PageLayout . withSubduedBackground
305351 , Nothing
0 commit comments