-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(boards2): add pagination #3216
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ed2d21
feat: use pagination for boards list
x1unix b2daf93
feat: add pagination to post
x1unix 77e4c53
chore: add todos
x1unix fa7efe8
fix: display pagination only if necessary
x1unix fcb8924
feat: add pagination to threads
x1unix 0652731
fix: requestUri -> requestURI
x1unix 1e8b30d
fix: refactor router wrapper
x1unix e8a898d
fix: strings.Builder
x1unix 8f1ac86
chore: tidy and fmt
x1unix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package boards2 | ||
|
||
import ( | ||
"strings" | ||
|
||
"gno.land/p/demo/avl/pager" | ||
"gno.land/p/demo/mux" | ||
) | ||
|
||
type wrappedRouter struct { | ||
*mux.Router | ||
|
||
requestURI string | ||
} | ||
|
||
// newWrappedRouter returns a wrapped mux router that supports query strings. | ||
// | ||
// TODO: remove this when query strings PR will be merged: https://github.com/gnolang/gno/pull/2594 | ||
func newWrappedRouter(r *mux.Router) *wrappedRouter { | ||
return &wrappedRouter{ | ||
Router: r, | ||
} | ||
} | ||
|
||
func (r *wrappedRouter) Render(path string) string { | ||
reqPath := trimRequestPath(path) | ||
r.requestURI = path | ||
return r.Router.Render(reqPath) | ||
} | ||
|
||
func (r *wrappedRouter) HandleFunc(pattern string, fn mux.HandlerFunc) { | ||
r.Router.HandleFunc(pattern, func(rw *mux.ResponseWriter, req *mux.Request) { | ||
fn(rw, &mux.Request{ | ||
Path: r.requestURI, | ||
HandlerPath: req.HandlerPath, | ||
}) | ||
}) | ||
} | ||
|
||
// trimRequestPath returns request path without query params | ||
func trimRequestPath(path string) string { | ||
i := strings.Index(path, "?") | ||
if i == -1 { | ||
return path | ||
} | ||
|
||
return path[:i] | ||
} | ||
|
||
func getPagination(r *mux.Request, defaultPageSize int) Pagination { | ||
// reuse query parameter extract logic from pager. | ||
pg := pager.NewPager(nil, defaultPageSize) | ||
pg.SizeQueryParam = "" | ||
pageNum, limit, err := pg.ParseQuery(r.Path) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return Pagination{ | ||
PageNumber: pageNum, | ||
PageSize: limit, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not possible to use something like the following?
Where path is the render path. This would allow to remove the
Pagination
struct.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeronimoalbi the idea here is to have separation of concerns, so
render.gno
which acts as a controller will be responsible for getting pagination query string information.