This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit b558de8a236476c3dc5f338174d3ac663c48d4c7
Author: LinkinStars <[email protected]>
AuthorDate: Fri Nov 29 15:15:23 2024 +0800

    feat(user): add top questions and answers to user homepage
---
 internal/controller/template_controller.go | 12 +++++++++--
 ui/template/homepage.html                  | 33 +++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/internal/controller/template_controller.go 
b/internal/controller/template_controller.go
index df10931e..0b22360f 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -546,12 +546,20 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
                return
        }
 
+       questionList, answerList, err := 
tc.questionService.SearchUserTopList(ctx, req.Username, "")
+       if err != nil {
+               tc.Page404(ctx)
+               return
+       }
+
        siteInfo := tc.SiteInfo(ctx)
        siteInfo.Canonical = fmt.Sprintf("%s/users/%s", 
siteInfo.General.SiteUrl, username)
        siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name)
        tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{
-               "userinfo": userinfo,
-               "bio":      template.HTML(userinfo.BioHTML),
+               "userinfo":     userinfo,
+               "bio":          template.HTML(userinfo.BioHTML),
+               "topQuestions": questionList,
+               "topAnswers":   answerList,
        })
 
 }
diff --git a/ui/template/homepage.html b/ui/template/homepage.html
index 2f68200d..84887a09 100644
--- a/ui/template/homepage.html
+++ b/ui/template/homepage.html
@@ -63,10 +63,41 @@
             <div>
                 <h5 class="mb-3">{{translator $.language 
"ui.personal.about_me"}}</h5>
                 {{if .bio }}
-                <div class="text-center mb-4">{{.bio}}</div>
+                <div class="mb-5 text-break fmt">{{.bio}}</div>
                 {{else}}
                 <div class="text-center py-5 mb-4">{{translator $.language 
"ui.personal.about_me_empty"}}</div>
                 {{end}}
+                <div class="mb-4 row">
+                    <div class="mb-4 col-md-6 col-sm-12">
+                        <h5 class="mb-3">Top Answers</h5>
+                        <ol class="list-unstyled">
+                            {{ range .topAnswers }}
+                            <li class="mb-2">
+                                <a class="text-truncate-1" 
href="{{$.baseURL}}/questions/{{.QuestionID}}/{{.AnswerID}}">{{.QuestionInfo.Title}}</a>
+                                <div class="text-secondary small">
+                                    <i class="br bi-hand-thumbs-up-fill 
me-1"></i><span>{{.VoteCount}} votes</span>
+                                </div>
+                            </li>
+                            {{ end }}
+                        </ol>
+                    </div>
+                    <div class="col-md-6 col-sm-12">
+                        <h5 class="mb-3">Top Questions</h5>
+                        <ol class="list-unstyled">
+                            {{ range .topQuestions }}
+                            <li class="mb-2">
+                                <a class="text-truncate-1" 
href="{{$.baseURL}}/questions/{{.ID}}">{{.Title}}</a>
+                                <div class="text-secondary small">
+                                    <i class="br bi-hand-thumbs-up-fill 
me-1"></i><span> {{.VoteCount}} votes</span>
+                                    <div class="d-inline-block text-secondary 
ms-3 small text-success">
+                                        <i class="br 
bi-check-circle-fill"></i><span> {{.AnswerCount}} answers</span>
+                                    </div>
+                                </div>
+                            </li>
+                            {{ end }}
+                        </ol>
+                    </div>
+                </div>
             </div>
         </div>
         <div class="mt-5 mt-lg-0 col-xxl-3 col-lg-4 col-sm-12">

Reply via email to