Skip to content

Commit 7669b63

Browse files
authored
Merge pull request #82 from unisoncomputing/prev-next-cursor
Migrate to using prev and next cursor explicitly
2 parents c54bdd0 + dada6a6 commit 7669b63

File tree

11 files changed

+51
-33
lines changed

11 files changed

+51
-33
lines changed

src/UnisonShare/Api.elm

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import UnisonShare.DefinitionDiff as DefinitionDiff
2727
import UnisonShare.Notification as Notification exposing (NotificationStatus)
2828
import UnisonShare.OrgMember as OrgMember exposing (OrgMember)
2929
import UnisonShare.OrgRole as OrgRole
30-
import UnisonShare.Paginated as Paginated exposing (PageCursorParam(..))
30+
import UnisonShare.Paginated as Paginated exposing (PageCursorParam)
3131
import UnisonShare.Project as Project exposing (ProjectVisibility)
3232
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
3333
import UnisonShare.ProjectCollaborator exposing (ProjectCollaborator)
@@ -77,7 +77,7 @@ type alias UserBranchesParams =
7777
{ searchQuery : Maybe String
7878
, projectRef : Maybe ProjectRef
7979
, limit : Int
80-
, cursor : Maybe String
80+
, cursor : PageCursorParam
8181
}
8282

8383

@@ -86,10 +86,7 @@ userBranches handle params =
8686
let
8787
queryParams =
8888
int "limit" params.limit
89-
:: (params.cursor
90-
|> Maybe.map (string "cursor")
91-
|> MaybeE.toList
92-
)
89+
:: Paginated.toQueryParams params.cursor
9390
++ (params.searchQuery
9491
|> Maybe.map (string "name-prefix")
9592
|> MaybeE.toList
@@ -202,15 +199,7 @@ notifications account status paginationCursor =
202199
[]
203200

204201
paginationQueryParams =
205-
case paginationCursor of
206-
PrevPage c ->
207-
[ string "prevCursor" (Paginated.cursorToString c) ]
208-
209-
NextPage c ->
210-
[ string "nextCursor" (Paginated.cursorToString c) ]
211-
212-
NoPageCursor ->
213-
[]
202+
Paginated.toQueryParams paginationCursor
214203
in
215204
GET
216205
{ path =
@@ -363,7 +352,7 @@ type alias ProjectBranchesParams =
363352
{ kind : ProjectBranchesKindFilter
364353
, searchQuery : Maybe String
365354
, limit : Int
366-
, cursor : Maybe String
355+
, cursor : PageCursorParam
367356
}
368357

369358

@@ -389,10 +378,7 @@ projectBranches projectRef params =
389378

390379
queryParams =
391380
[ kind, int "limit" params.limit ]
392-
++ (params.cursor
393-
|> Maybe.map (string "cursor")
394-
|> MaybeE.toList
395-
)
381+
++ Paginated.toQueryParams params.cursor
396382
++ (params.searchQuery
397383
|> Maybe.map (string "name-prefix")
398384
|> MaybeE.toList

src/UnisonShare/Page/ProjectBranchesPage.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import UnisonShare.AppContext exposing (AppContext)
2828
import UnisonShare.BranchSummary exposing (BranchSummary)
2929
import UnisonShare.Link as Link
3030
import UnisonShare.PageFooter as PageFooter
31+
import UnisonShare.Paginated as Paginated
3132
import UnisonShare.Project as Project exposing (ProjectDetails)
3233
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
3334
import UnisonShare.Session as Session exposing (Session)
@@ -123,7 +124,7 @@ fetchBranches appContext projectRef =
123124
{ kind = ShareApi.AllBranches Nothing
124125
, searchQuery = Nothing
125126
, limit = 100
126-
, cursor = Nothing
127+
, cursor = Paginated.NoPageCursor
127128
}
128129
in
129130
ShareApi.projectBranches projectRef params

src/UnisonShare/Page/ProjectContributionsPage.elm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import UnisonShare.Contribution.ContributionRef as ContributionRef
3131
import UnisonShare.Contribution.ContributionStatus as ContributionStatus
3232
import UnisonShare.Link as Link
3333
import UnisonShare.PageFooter as PageFooter
34+
import UnisonShare.Paginated as Paginated
3435
import UnisonShare.Project as Project exposing (ProjectDetails)
3536
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
3637
import UnisonShare.ProjectContributionFormModal as ProjectContributionFormModal
@@ -82,15 +83,15 @@ init appContext projectRef =
8283
{ kind = ShareApi.ContributorBranches (Just a.handle)
8384
, searchQuery = Nothing
8485
, limit = 3
85-
, cursor = Nothing
86+
, cursor = Paginated.NoPageCursor
8687
}
8788
, fetchBranches FetchProjectBranchesFinished
8889
appContext
8990
projectRef
9091
{ kind = ShareApi.ProjectBranches
9192
, searchQuery = Nothing
9293
, limit = 3
93-
, cursor = Nothing
94+
, cursor = Paginated.NoPageCursor
9495
}
9596
]
9697
)

src/UnisonShare/Page/ProjectReleasesPage.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
4242
import UnisonShare.InteractiveDoc as InteractiveDoc
4343
import UnisonShare.Link as Link
4444
import UnisonShare.PageFooter as PageFooter
45+
import UnisonShare.Paginated as Paginated
4546
import UnisonShare.Project as Project exposing (ProjectDetails)
4647
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
4748
import UnisonShare.Project.Release as Release exposing (Release)
@@ -423,7 +424,7 @@ fetchReleaseDrafts appContext projectRef =
423424
{ kind = ShareApi.ProjectBranches
424425
, searchQuery = Just "releases/drafts/"
425426
, limit = 10
426-
, cursor = Nothing
427+
, cursor = Paginated.NoPageCursor
427428
}
428429
in
429430
ShareApi.projectBranches projectRef params

src/UnisonShare/Page/UserContributionsPage.elm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import UnisonShare.Api as ShareApi
3131
import UnisonShare.AppContext exposing (AppContext)
3232
import UnisonShare.Link as Link
3333
import UnisonShare.PageFooter as PageFooter
34+
import UnisonShare.Paginated as Paginated
3435
import UnisonShare.Project as Project exposing (Project)
3536
import UnisonShare.Project.ProjectListing as ProjectListing
3637
import UnisonShare.Project.ProjectRef as ProjectRef
@@ -79,7 +80,7 @@ init appContext handle =
7980
{ searchQuery = Nothing
8081
, projectRef = Nothing
8182
, limit = 100
82-
, cursor = Nothing
83+
, cursor = Paginated.NoPageCursor
8384
}
8485

8586
model =
@@ -137,7 +138,7 @@ update appContext handle msg model =
137138
{ searchQuery = Just query
138139
, projectRef = Nothing
139140
, limit = 100
140-
, cursor = Nothing
141+
, cursor = Paginated.NoPageCursor
141142
}
142143
in
143144
fetchContributions (FetchSearchResultsFinished query) appContext handle params

src/UnisonShare/Paginated.elm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module UnisonShare.Paginated exposing (..)
22

3+
import Url.Builder exposing (QueryParameter, string)
4+
35

46
type PageCursorParam
57
= NoPageCursor
@@ -22,3 +24,24 @@ type Paginated a
2224
cursorToString : PageCursor -> String
2325
cursorToString (PageCursor c) =
2426
c
27+
28+
29+
toQueryParam : PageCursorParam -> Maybe QueryParameter
30+
toQueryParam param =
31+
case param of
32+
NoPageCursor ->
33+
Nothing
34+
35+
PrevPage c ->
36+
Just (string "cursor" (cursorToString c))
37+
38+
NextPage c ->
39+
Just (string "cursor" (cursorToString c))
40+
41+
42+
toQueryParams : PageCursorParam -> List QueryParameter
43+
toQueryParams param =
44+
param
45+
|> toQueryParam
46+
|> Maybe.map List.singleton
47+
|> Maybe.withDefault []

src/UnisonShare/ProjectContributionFormModal.elm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import UnisonShare.Contribution as Contribution exposing (ContributionSummary)
3535
import UnisonShare.Contribution.ContributionRef as ContributionRef exposing (ContributionRef)
3636
import UnisonShare.Contribution.ContributionStatus as ContributionStatus exposing (ContributionStatus)
3737
import UnisonShare.Link as Link
38+
import UnisonShare.Paginated as Paginated
3839
import UnisonShare.Project as Project exposing (ProjectDetails)
3940
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
4041
import UnisonShare.SearchBranchSheet as SearchBranchSheet
@@ -389,14 +390,14 @@ fetchRecentBranches appContext currentUser projectRef =
389390
{ kind = ShareApi.ContributorBranches (Just currentUser.handle)
390391
, searchQuery = Nothing
391392
, limit = 3
392-
, cursor = Nothing
393+
, cursor = Paginated.NoPageCursor
393394
}
394395

395396
projectBranchesParams =
396397
{ kind = ShareApi.ProjectBranches
397398
, searchQuery = Nothing
398399
, limit = 3
399-
, cursor = Nothing
400+
, cursor = Paginated.NoPageCursor
400401
}
401402
in
402403
Task.map2

src/UnisonShare/PublishProjectReleaseModal.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import UnisonShare.AppContext as AppContext exposing (AppContext)
2525
import UnisonShare.BranchSummary as BranchSummary exposing (BranchSummary)
2626
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
2727
import UnisonShare.InteractiveDoc as InteractiveDoc
28+
import UnisonShare.Paginated as Paginated
2829
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
2930
import UnisonShare.Project.Release as Release exposing (Release)
3031
import UnisonShare.SearchBranchSheet as SearchBranchSheet
@@ -309,7 +310,7 @@ fetchLatestBranches appContext projectRef =
309310
{ kind = ShareApi.ProjectBranches
310311
, searchQuery = Nothing
311312
, limit = 3
312-
, cursor = Nothing
313+
, cursor = Paginated.NoPageCursor
313314
}
314315
|> HttpApi.toRequest (Decode.field "items" (Decode.list BranchSummary.decode))
315316
(RemoteData.fromResult >> FetchLatestBranchesFinished)

src/UnisonShare/SearchBranchSheet.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import UI.Tag as Tag
2121
import UnisonShare.Api as ShareApi exposing (ProjectBranchesKindFilter)
2222
import UnisonShare.AppContext exposing (AppContext)
2323
import UnisonShare.BranchSummary as BranchSummary exposing (BranchSummary)
24+
import UnisonShare.Paginated as Paginated
2425
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
2526

2627

@@ -85,7 +86,7 @@ update appContext projectRef msg model =
8586
{ kind = model.branchKindFilter
8687
, searchQuery = Just query
8788
, limit = 10
88-
, cursor = Nothing
89+
, cursor = Paginated.NoPageCursor
8990
}
9091
, NoOutMsg
9192
)

src/UnisonShare/SwitchBranch.elm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import UnisonShare.Api as ShareApi
1313
import UnisonShare.AppContext exposing (AppContext)
1414
import UnisonShare.BranchSummary as BranchSummary exposing (BranchSummary)
1515
import UnisonShare.Link as Link
16+
import UnisonShare.Paginated as Paginated
1617
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
1718
import UnisonShare.SearchBranchSheet as SearchBranchSheet
1819
import UnisonShare.Session as Session
@@ -79,7 +80,7 @@ update appContext projectRef msg model =
7980
{ kind = ShareApi.ContributorBranches (Just handle)
8081
, searchQuery = Nothing
8182
, limit = 3
82-
, cursor = Nothing
83+
, cursor = Paginated.NoPageCursor
8384
}
8485
, Just RemoteData.Loading
8586
)
@@ -96,7 +97,7 @@ update appContext projectRef msg model =
9697
{ kind = ShareApi.ProjectBranches
9798
, searchQuery = Nothing
9899
, limit = 3
99-
, cursor = Nothing
100+
, cursor = Paginated.NoPageCursor
100101
}
101102
in
102103
( Open sheet

0 commit comments

Comments
 (0)