Skip to content

Commit

Permalink
Revert "fix nit"
Browse files Browse the repository at this point in the history
This reverts commit cca7ff0.
  • Loading branch information
leohhhn committed Mar 18, 2024
1 parent cca7ff0 commit 7a5df33
Showing 1 changed file with 15 additions and 44 deletions.
59 changes: 15 additions & 44 deletions api/p/memeland/memeland.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Post struct {
UpvoteTracker *avl.Tree // address > struct{}{}
}

type UpvoteSorter []*Post
type DateSorter []*Post

type Memeland struct {
*ownable.Ownable
Posts []*Post
Expand Down Expand Up @@ -100,22 +103,10 @@ func (m *Memeland) GetPostsInRange(startTimestamp, endTimestamp int64, page, pag
switch sortBy {
// Sort by upvote descending
case "UPVOTES":
dateSorter := PostSorter{
posts: filteredPosts,
less: func(i, j int) bool {
return filteredPosts[i].UpvoteTracker.Size() > filteredPosts[j].UpvoteTracker.Size()
},
}
sort.Sort(dateSorter)
sort.Sort(UpvoteSorter(filteredPosts))
default:
// Sort by timestamp, beginning with newest
dateSorter := PostSorter{
posts: filteredPosts,
less: func(i, j int) bool {
return filteredPosts[i].Timestamp.Before(filteredPosts[j].Timestamp)
},
}
sort.Sort(dateSorter)
sort.Sort(DateSorter(filteredPosts))
}

// Pagination
Expand Down Expand Up @@ -198,36 +189,16 @@ func (m *Memeland) getPost(id string) *Post {
return nil
}

type PostSorter struct {
posts []*Post
less func(i, j int) bool
}

func (p PostSorter) Len() int {
return len(p.posts)
}

func (p PostSorter) Swap(i, j int) {
p.posts[i], p.posts[j] = p.posts[j], p.posts[i]
// Sort by newest first
func (a DateSorter) Len() int { return len(a) }
func (a DateSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a DateSorter) Less(i, j int) bool {
return a[i].Timestamp.Before(a[j].Timestamp)
}

func (p PostSorter) Less(i, j int) bool {
return p.Less(i, j)
// Sort by upvote count
func (a UpvoteSorter) Len() int { return len(a) }
func (a UpvoteSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a UpvoteSorter) Less(i, j int) bool {
return a[i].UpvoteTracker.Size() > a[j].UpvoteTracker.Size()
}

//type UpvoteSorter []*Post
//type DateSorter []*Post
//
//// Sort by newest first
//func (a DateSorter) Len() int { return len(a) }
//func (a DateSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
//func (a DateSorter) Less(i, j int) bool {
// return a[i].Timestamp.Before(a[j].Timestamp)
//}
//
//// Sort by upvote count
//func (a UpvoteSorter) Len() int { return len(a) }
//func (a UpvoteSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
//func (a UpvoteSorter) Less(i, j int) bool {
// return a[i].UpvoteTracker.Size() > a[j].UpvoteTracker.Size()
//}

0 comments on commit 7a5df33

Please sign in to comment.