Skip to content

Commit

Permalink
template(question): add set private button
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Aug 17, 2024
1 parent eea8813 commit 71fde1d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/db/questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type CreateQuestionOptions struct {
Content string
ReceiveReplyEmail string
AskerUserID uint
IsPrivate bool
}

func (db *questions) Create(ctx context.Context, opts CreateQuestionOptions) (*Question, error) {
Expand All @@ -73,6 +74,7 @@ func (db *questions) Create(ctx context.Context, opts CreateQuestionOptions) (*Q
Content: opts.Content,
ReceiveReplyEmail: opts.ReceiveReplyEmail,
AskerUserID: opts.AskerUserID,
IsPrivate: opts.IsPrivate,
}
return &question, db.WithContext(ctx).Create(&question).Error
}
Expand Down
1 change: 1 addition & 0 deletions internal/form/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type NewQuestion struct {
ReceiveReplyEmail string `label:"接收回复的电子邮箱"`
Recaptcha string `form:"g-recaptcha-response" valid:"required" label:"Recaptcha" msg:"无感验证码加载错误,请尝试刷新页面重试。"`
Images []*multipart.FileHeader `form:"images" label:"图片"`
IsPrivate string `form:"private"`
}

type PublishAnswerQuestion struct {
Expand Down
2 changes: 2 additions & 0 deletions route/question/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func New(ctx context.Context, f form.NewQuestion, pageUser *db.User, recaptcha r
}

content := f.Content
isPrivate := f.IsPrivate != ""

// 🚨 Content security check.
censorResponse, err := censor.Text(ctx.Request().Context(), content)
Expand Down Expand Up @@ -191,6 +192,7 @@ func New(ctx context.Context, f form.NewQuestion, pageUser *db.User, recaptcha r
Content: content,
ReceiveReplyEmail: receiveReplyEmail,
AskerUserID: askerUserID,
IsPrivate: isPrivate,
})
if err != nil {
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to create new question")
Expand Down
2 changes: 1 addition & 1 deletion templates/question/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h4 class="uk-text-center uk-margin-top uk-margin-bottom uk-text-break">{{.Quest
{{ else }}
<form class="uk-float-right" method="post" action="/_/{{ .PageUser.Domain }}/{{ .Question.ID }}/set-private">
{{ .CSRFTokenHTML }}
<button type="submit" class="uk-button uk-button-default uk-button-small">设为仅自己可见</button>
<button type="submit" class="uk-button uk-button-default uk-button-small">设为私密</button>
</form>
{{ end }}

Expand Down
3 changes: 3 additions & 0 deletions templates/question/new-question-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
</div>
</div>
<div class="uk-margin uk-grid-small" x-data="{ receiveReplyViaEmail: '{{.receive_reply_via_email}}' === 'on' }">
<label class="uk-text-small">
<input name="private" class="uk-checkbox" type="checkbox"> 回复后不公开提问
</label>
<label class="uk-text-small">
<input name="receive_reply_via_email" class="uk-checkbox" type="checkbox"
x-model="receiveReplyViaEmail"> 我想接收回复通知
Expand Down
2 changes: 1 addition & 1 deletion templates/user/question-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div>
<hr>
{{if eq $elem.Answer ""}}<span class="uk-label uk-float-right uk-margin-small-right">未回答</span>{{end}}
{{if $elem.IsPrivate}}<span class="uk-label uk-label-warning uk-float-right uk-margin-small-right">个人可见</span>{{end}}
{{if $elem.IsPrivate}}<span class="uk-label uk-label-warning uk-float-right uk-margin-small-right">私密</span>{{end}}
<div class="uk-text-left uk-text-small uk-text-muted">{{Date $elem.CreatedAt "Y-m-d H:i:s"}}</div>
<p class="uk-text-small">{{$elem.Content}}</p>
</div>
Expand Down

0 comments on commit 71fde1d

Please sign in to comment.