Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@ ui:
recommend: Recommend
score: Score
unanswered: Unanswered
views: Most viewed
modified: modified
answered: answered
asked: asked
Expand Down
4 changes: 4 additions & 0 deletions internal/repo/question/question_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
session.OrderBy("question.pin desc,question.created_at DESC")
case "frequent":
session.OrderBy("question.pin DESC, question.linked_count DESC, question.updated_at DESC")
case "views":
session.OrderBy("question.pin DESC, question.view_count DESC, question.created_at DESC")
}

session.GroupBy("question.id")
Expand Down Expand Up @@ -854,6 +856,8 @@ func (qr *questionRepo) GetQuestionLink(ctx context.Context, page, pageSize int,
session.OrderBy("question.pin desc,question.created_at DESC")
case "frequent":
session.OrderBy("question.pin DESC, question.linked_count DESC, question.updated_at DESC")
case "views":
session.OrderBy("question.pin DESC, question.view_count DESC, question.created_at DESC")
}

if page > 0 && pageSize > 0 {
Expand Down
5 changes: 3 additions & 2 deletions internal/schema/question_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ const (
QuestionOrderCondUnanswered = "unanswered"
QuestionOrderCondRecommend = "recommend"
QuestionOrderCondFrequent = "frequent"
QuestionOrderCondViews = "views"

// HotInDays limit max days of the hottest question
HotInDays = 90
Expand All @@ -368,7 +369,7 @@ const (
type QuestionPageReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent" form:"order"`
OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent views" form:"order"`
Tag string `validate:"omitempty,gt=0,lte=100" form:"tag"`
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
InDays int `validate:"omitempty,min=1" form:"in_days"`
Expand Down Expand Up @@ -517,7 +518,7 @@ type GetQuestionLinkReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1,max=100" form:"page_size"`
QuestionID string `validate:"required" form:"question_id"`
OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent" form:"order"`
OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent views" form:"order"`
InDays int `validate:"omitempty,min=1" form:"in_days"`

LoginUserID string `json:"-"`
Expand Down
3 changes: 2 additions & 1 deletion ui/src/common/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ export type QuestionOrderBy =
| 'hot'
| 'score'
| 'unanswered'
| 'frequent';
| 'frequent'
| 'views';

export interface QueryQuestionsReq extends Paging {
order: QuestionOrderBy;
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/QuestionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const QUESTION_ORDER_KEYS: Type.QuestionOrderBy[] = [
'recommend',
'frequent',
'score',
'views',
];
interface Props {
source: 'questions' | 'tag' | 'linked';
Expand Down