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
Support reversing tags #120
base: develop
Are you sure you want to change the base?
Conversation
Nice idea!
|
@mrvdb This is the first time I've ever touched Go; I'm not really sure how to implement something like that. What's your usecase for this? |
My apologies, I see I've mis-assumed what this was about. I thought it was about filtering instead of ordering. For the filtering I had something like this in mind for a while but I have no specific usecase other than the need to filter a collection. Using the
Having the sort order reversed is something else indeed. :-) |
Thanks for working on this, @leo60228! We have some other things on our plate at the moment, but I do think this would be a great addition to the platform. My only feedback right now is that I'd prefer to use
Thoughts? (Also, I like the filtering idea, @mrvdb -- it's been discussed a bit on the forum. Would love to get your input over there.) |
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.
Just need to address some of the naming and logic choices before merging.
@@ -810,9 +814,10 @@ func handleViewCollectionTag(app *app, w http.ResponseWriter, r *http.Request) e | |||
return err | |||
} | |||
|
|||
coll := newDisplayCollection(c, cr, page) | |||
rev := strings.HasSuffix(r.URL.Path, "/rev") || strings.HasSuffix(r.URL.Path, "/rev") |
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.
We can remove the duplicate condition here. Also check for /chrono
instead.
@@ -712,7 +716,7 @@ func handleViewCollection(app *app, w http.ResponseWriter, r *http.Request) erro | |||
|
|||
// Fetch extra data about the Collection | |||
// TODO: refactor out this logic, shared in collection.go:fetchCollection() | |||
coll := newDisplayCollection(c, cr, page) | |||
coll := newDisplayCollection(c, cr, page, strings.HasSuffix(r.URL.Path, "/rev") || strings.HasSuffix(r.URL.Path, "/rev")) |
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.
We can remove the duplicate condition here. Also should check for /chrono
instead.
@@ -1127,10 +1127,10 @@ func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecen | |||
// given tag. | |||
// It will return future posts if `includeFuture` is true. | |||
// TODO: change includeFuture to isOwner, since that's how it's used | |||
func (db *datastore) GetPostsTagged(c *Collection, tag string, page int, includeFuture bool) (*[]PublicPost, error) { | |||
func (db *datastore) GetPostsTagged(c *Collection, tag string, page int, includeFuture bool, reversed bool) (*[]PublicPost, error) { |
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.
Let's use chrono
or chronological
as the parameter name, to avoid confusion.
@@ -105,7 +105,7 @@ type writestore interface { | |||
|
|||
GetPostsCount(c *CollectionObj, includeFuture bool) | |||
GetPosts(c *Collection, page int, includeFuture, forceRecentFirst, includePinned bool) (*[]PublicPost, error) | |||
GetPostsTagged(c *Collection, tag string, page int, includeFuture bool) (*[]PublicPost, error) | |||
GetPostsTagged(c *Collection, tag string, page int, includeFuture bool, reversed bool) (*[]PublicPost, error) |
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.
Let's use chrono
or chronological
as the parameter name, to avoid confusion.
@@ -170,6 +170,7 @@ func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datasto | |||
func RouteCollections(handler *Handler, r *mux.Router) { | |||
r.HandleFunc("/page/{page:[0-9]+}", handler.Web(handleViewCollection, UserLevelOptional)) | |||
r.HandleFunc("/tag:{tag}", handler.Web(handleViewCollectionTag, UserLevelOptional)) | |||
r.HandleFunc("/tag:{tag}/rev", handler.Web(handleViewCollectionTag, UserLevelOptional)) |
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.
Let's go with /tag:{tag}/chrono
for the route, instead of /tag:{tag}/rev
.
@@ -93,6 +93,7 @@ type ( | |||
} | |||
CollectionFormat struct { | |||
Format string | |||
Reversed bool |
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.
Let's name this Chronological
, instead, to make this less confusing.
@@ -146,8 +150,8 @@ func (cf *CollectionFormat) Valid() bool { | |||
} | |||
|
|||
// NewFormat creates a new CollectionFormat object from the Collection. | |||
func (c *Collection) NewFormat() *CollectionFormat { | |||
cf := &CollectionFormat{Format: c.Format} | |||
func (c *Collection) NewFormat(reversed bool) *CollectionFormat { |
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.
Let's use chrono
or maybe forceChrono
as the parameter name, instead, to make this less confusing.
@@ -126,6 +127,9 @@ const ( | |||
) | |||
|
|||
func (cf *CollectionFormat) Ascending() bool { | |||
if cf.Reversed { | |||
return cf.Format != "novel" |
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.
It would be helpful to have some comments here explaining the logic a bit (or some explanation here on github). I'm not sure why we're checking for the novel
format here instead of always returning true
.
@@ -659,13 +663,13 @@ func checkUserForCollection(app *app, cr *collectionReq, r *http.Request, isPost | |||
return u, nil | |||
} | |||
|
|||
func newDisplayCollection(c *Collection, cr *collectionReq, page int) *DisplayCollection { | |||
func newDisplayCollection(c *Collection, cr *collectionReq, page int, reversed bool) *DisplayCollection { |
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.
Again let's use chrono
or maybe forceChrono
as the parameter name, instead, to make this less confusing.
The reason it's |
You can now use
/tag:test/rev
instead of/tag:test/
to reverse the order from the default for that collection.