Bladeren bron

Fix inconsistent navigation

NobeKanai 4 jaren geleden
bovenliggende
commit
cf1939f063
7 gewijzigde bestanden met toevoegingen van 15 en 13 verwijderingen
  1. 9 7
      storage/entry_pagination_builder.go
  2. 1 1
      ui/entry_bookmark.go
  3. 1 1
      ui/entry_category.go
  4. 1 1
      ui/entry_feed.go
  5. 1 1
      ui/entry_read.go
  6. 1 1
      ui/entry_search.go
  7. 1 1
      ui/entry_unread.go

+ 9 - 7
storage/entry_pagination_builder.go

@@ -20,6 +20,7 @@ type EntryPaginationBuilder struct {
 	conditions []string
 	args       []interface{}
 	entryID    int64
+	order      string
 	direction  string
 }
 
@@ -107,20 +108,20 @@ func (e *EntryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID
 		WITH entry_pagination AS (
 			SELECT
 				e.id,
-				lag(e.id) over (order by e.published_at asc, e.id desc) as prev_id,
-				lead(e.id) over (order by e.published_at asc, e.id desc) as next_id
+				lag(e.id) over (order by e.%[1]s asc, e.id desc) as prev_id,
+				lead(e.id) over (order by e.%[1]s asc, e.id desc) as next_id
 			FROM entries AS e
 			JOIN feeds AS f ON f.id=e.feed_id
 			JOIN categories c ON c.id = f.category_id
-			WHERE %s
-			ORDER BY e.published_at asc, e.id desc
+			WHERE %[2]s
+			ORDER BY e.%[1]s asc, e.id desc
 		)
-		SELECT prev_id, next_id FROM entry_pagination AS ep WHERE %s;
+		SELECT prev_id, next_id FROM entry_pagination AS ep WHERE %[3]s;
 	`
 
 	subCondition := strings.Join(e.conditions, " AND ")
 	finalCondition := fmt.Sprintf("ep.id = $%d", len(e.args)+1)
-	query := fmt.Sprintf(cte, subCondition, finalCondition)
+	query := fmt.Sprintf(cte, e.order, subCondition, finalCondition)
 	e.args = append(e.args, e.entryID)
 
 	var pID, nID sql.NullInt64
@@ -162,12 +163,13 @@ func (e *EntryPaginationBuilder) getEntry(tx *sql.Tx, entryID int64) (*model.Ent
 }
 
 // NewEntryPaginationBuilder returns a new EntryPaginationBuilder.
-func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, direction string) *EntryPaginationBuilder {
+func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, order, direction string) *EntryPaginationBuilder {
 	return &EntryPaginationBuilder{
 		store:      store,
 		args:       []interface{}{userID, "removed"},
 		conditions: []string{"e.user_id = $1", "e.status <> $2"},
 		entryID:    entryID,
+		order:      order,
 		direction:  direction,
 	}
 }

+ 1 - 1
ui/entry_bookmark.go

@@ -49,7 +49,7 @@ func (h *handler) showStarredEntryPage(w http.ResponseWriter, r *http.Request) {
 		entry.Status = model.EntryStatusRead
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithStarred()
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
 	if err != nil {

+ 1 - 1
ui/entry_category.go

@@ -52,7 +52,7 @@ func (h *handler) showCategoryEntryPage(w http.ResponseWriter, r *http.Request)
 		entry.Status = model.EntryStatusRead
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithCategoryID(categoryID)
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
 	if err != nil {

+ 1 - 1
ui/entry_feed.go

@@ -52,7 +52,7 @@ func (h *handler) showFeedEntryPage(w http.ResponseWriter, r *http.Request) {
 		entry.Status = model.EntryStatusRead
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithFeedID(feedID)
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
 	if err != nil {

+ 1 - 1
ui/entry_read.go

@@ -39,7 +39,7 @@ func (h *handler) showReadEntryPage(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithStatus(model.EntryStatusRead)
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
 	if err != nil {

+ 1 - 1
ui/entry_search.go

@@ -51,7 +51,7 @@ func (h *handler) showSearchEntryPage(w http.ResponseWriter, r *http.Request) {
 		entry.Status = model.EntryStatusRead
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithSearchQuery(searchQuery)
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
 	if err != nil {

+ 1 - 1
ui/entry_unread.go

@@ -48,7 +48,7 @@ func (h *handler) showUnreadEntryPage(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
-	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryDirection)
+	entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection)
 	entryPaginationBuilder.WithStatus(model.EntryStatusUnread)
 	entryPaginationBuilder.WithGloballyVisible()
 	prevEntry, nextEntry, err := entryPaginationBuilder.Entries()