@@ -17,21 +17,26 @@ import UI.PageLayout as PageLayout exposing (PageLayout)
1717import UI.PageTitle as PageTitle
1818import UI.Placeholder as Placeholder
1919import UI.ProfileSnippet as ProfileSnippet
20- import UnisonShare.Api as ShareApi
2120import UnisonShare.AppContext exposing (AppContext )
21+ import UnisonShare.Link as Link
2222import UnisonShare.Page.ErrorPage as ErrorPage
2323import UnisonShare.PageFooter as PageFooter
24+ import UnisonShare.Paginated as Paginated exposing (Paginated (..) )
2425import UnisonShare.Project as Project exposing (ProjectDetails )
25- import UnisonShare.Project.BranchHistory as BranchHistory exposing (BranchHistory , HistoryEntry )
26+ import UnisonShare.Project.BranchHistory as BranchHistory exposing (HistoryEntry )
2627import UnisonShare.Project.ProjectRef exposing (ProjectRef )
2728
2829
2930
3031-- MODEL
3132
3233
34+ type alias PaginatedBranchHistory =
35+ Paginated . Paginated HistoryEntry
36+
37+
3338type alias Model =
34- { history : WebData BranchHistory
39+ { history : WebData PaginatedBranchHistory
3540 }
3641
3742
@@ -41,15 +46,15 @@ preInit =
4146 }
4247
4348
44- init : AppContext -> ProjectDetails -> Maybe BranchRef -> ( Model , Cmd Msg )
45- init appContext project branchRef =
49+ init : AppContext -> ProjectDetails -> Maybe BranchRef -> Paginated . PageCursorParam -> ( Model , Cmd Msg )
50+ init appContext project branchRef cursor =
4651 let
4752 branchRef_ : BranchRef
4853 branchRef_ =
4954 Maybe . withDefault ( Project . defaultBrowsingBranch project) branchRef
5055 in
5156 ( { history = Loading }
52- , fetchProjectBranchHistory appContext project. ref branchRef_
57+ , fetchProjectBranchHistory appContext project. ref branchRef_ cursor
5358 )
5459
5560
@@ -58,28 +63,36 @@ init appContext project branchRef =
5863
5964
6065type Msg
61- = FetchProjectBranchHistoryFinished BranchRef ( WebData BranchHistory )
66+ = FetchProjectBranchHistoryFinished BranchRef ( WebData PaginatedBranchHistory )
6267
6368
6469update : AppContext -> ProjectDetails -> Maybe BranchRef -> Msg -> Model -> ( Model , Cmd Msg )
65- update appContext project branchRef msg model =
70+ update _ _ _ msg model =
6671 case msg of
67- FetchProjectBranchHistoryFinished branchRef_ history ->
72+ FetchProjectBranchHistoryFinished _ history ->
6873 ( { model | history = history }, Cmd . none )
6974
7075
7176
7277-- EFFECTS
7378
7479
75- fetchProjectBranchHistory : AppContext -> ProjectRef -> BranchRef -> Cmd Msg
76- fetchProjectBranchHistory appContext projectRef branchRef =
80+ fetchProjectBranchHistory : AppContext -> ProjectRef -> BranchRef -> Paginated . PageCursorParam -> Cmd Msg
81+ fetchProjectBranchHistory _ _ branchRef cursor =
7782 let
83+ params =
84+ { limit = 64
85+ , cursor = cursor
86+ }
87+
88+ mkPaginated prev next items =
89+ Paginated . Paginated { prev = prev, next = next, items = items }
90+
7891 mock =
7992 RemoteData . Success
80- { projectRef = projectRef
81- , branchRef = branchRef
82- , history =
93+ ( mkPaginated
94+ Nothing
95+ ( Just ( Paginated . PageCursor " asdf-1234 " ))
8396 [ BranchHistory . Comment
8497 { createdAt = DateTime . unsafeFromISO8601 " 2025-11-03T13:35:33-05:00"
8598 , afterCausalHash = Hash . unsafeFromString " commenthash1"
@@ -110,7 +123,7 @@ fetchProjectBranchHistory appContext projectRef branchRef =
110123 , body = " And it was really cool"
111124 }
112125 ]
113- }
126+ )
114127 in
115128 Util . delayMsg 500 ( FetchProjectBranchHistoryFinished branchRef mock)
116129
@@ -243,22 +256,40 @@ viewHistoryEntry appContext entry =
243256 [ viewCardContent changeset ]
244257
245258
246- viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> BranchHistory -> PageContent Msg
247- viewPageContent appContext _ _ history =
259+ viewPaginationControls : ProjectRef -> Maybe BranchRef -> { a | prev : Maybe Paginated .PageCursor , next : Maybe Paginated .PageCursor } -> Html msg
260+ viewPaginationControls projectRef branchRef cursors =
261+ let
262+ toLink cursor =
263+ Link . projectHistory projectRef branchRef cursor
264+ in
265+ Paginated . view toLink cursors
266+
267+
268+ viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> PaginatedBranchHistory -> PageContent Msg
269+ viewPageContent appContext project branchRef ( Paginated history) =
248270 let
249271 entries =
250- if List . isEmpty history. history then
272+ if List . isEmpty history. items then
251273 [ div [] [ text " No entries" ] ]
252274
253275 else
254- List . map ( viewHistoryEntry appContext) history. history
276+ List . map ( viewHistoryEntry appContext) history. items
255277 in
256- PageContent . oneColumn [ div [ class " history-entries" ] entries ]
278+ PageContent . oneColumn
279+ [ div [ class " history-entries" ] entries
280+ , viewPaginationControls project. ref branchRef history
281+ ]
257282 |> PageContent . withPageTitle ( PageTitle . title " History" )
258283
259284
260- view : AppContext -> ProjectDetails -> Maybe BranchRef -> Model -> ( PageLayout Msg , Maybe (Html Msg ) )
261- view appContext project branchRef model =
285+ view :
286+ AppContext
287+ -> ProjectDetails
288+ -> Maybe BranchRef
289+ -> Paginated . PageCursorParam
290+ -> Model
291+ -> ( PageLayout Msg , Maybe ( Html Msg ) )
292+ view appContext project branchRef _ model =
262293 case model. history of
263294 NotAsked ->
264295 ( viewLoadingPage, Nothing )
0 commit comments