From 152e819a2b5cfe659c94bef387457a22696f670e Mon Sep 17 00:00:00 2001 From: shuai Date: Fri, 30 Sep 2022 12:13:59 +0800 Subject: [PATCH 01/83] fix: question detail closed reason --- ui/src/hooks/useReportModal/index.tsx | 5 +++ ui/src/i18n/locales/en.json | 8 +++-- .../Detail/components/Alert/index.tsx | 33 +++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ui/src/hooks/useReportModal/index.tsx b/ui/src/hooks/useReportModal/index.tsx index 88b975f6..0424cfc4 100644 --- a/ui/src/hooks/useReportModal/index.tsx +++ b/ui/src/hooks/useReportModal/index.tsx @@ -187,6 +187,11 @@ const useReportModal = (callback?: () => void) => { } value={content.value} isInvalid={content.isInvalid} + placeholder={ + item.content_type === 'text' + ? t('input_placeholder') + : t('textarea_placeholder') + } onChange={(e) => setContent({ value: e.target.value, diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json index a64aca32..8fcaf75d 100644 --- a/ui/src/i18n/locales/en.json +++ b/ui/src/i18n/locales/en.json @@ -199,7 +199,9 @@ }, "msg": { "empty": "Please select a reason." - } + }, + "input_placeholder": "Enter the existing question link", + "textarea_placeholder": "Let us know specifically what you are concerned about" }, "tag_modal": { "title": "Create New Tag", @@ -590,6 +592,8 @@ "edit": "edit", "Views": "Views", "answered": "answered", + "closed_in": "Closed in", + "show_exist": "Show existing question.", "answers": { "title": "Answers", "score": "Score", @@ -869,4 +873,4 @@ } } } -} \ No newline at end of file +} diff --git a/ui/src/pages/Questions/Detail/components/Alert/index.tsx b/ui/src/pages/Questions/Detail/components/Alert/index.tsx index 4b84c797..49cb428a 100644 --- a/ui/src/pages/Questions/Detail/components/Alert/index.tsx +++ b/ui/src/pages/Questions/Detail/components/Alert/index.tsx @@ -1,15 +1,44 @@ import { memo, FC } from 'react'; import { Alert } from 'react-bootstrap'; +import { useTranslation } from 'react-i18next'; + +import dayjs from 'dayjs'; interface Props { data; } const Index: FC = ({ data }) => { + const { t } = useTranslation(); return (
- {data.operation_msg} - {data.operation_description} + {data.operation_msg.indexOf('http') > -1 ? ( +

+ {data.operation_description} + + {t('question_detail.show_exist')} + +

+ ) : ( +

+ {data.operation_msg + ? data.operation_msg + : data.operation_description} +

+ )} +
+ {t('question_detail.closed_in')}{' '} + + . +
); From 97f959dfd4a37a9b1e9920f15a533b935b6556ef Mon Sep 17 00:00:00 2001 From: shuai Date: Fri, 30 Sep 2022 12:16:14 +0800 Subject: [PATCH 02/83] fix: delete no used text --- ui/src/hooks/useReportModal/index.tsx | 6 +----- ui/src/i18n/locales/en.json | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/ui/src/hooks/useReportModal/index.tsx b/ui/src/hooks/useReportModal/index.tsx index 0424cfc4..fe8d4593 100644 --- a/ui/src/hooks/useReportModal/index.tsx +++ b/ui/src/hooks/useReportModal/index.tsx @@ -187,11 +187,7 @@ const useReportModal = (callback?: () => void) => { } value={content.value} isInvalid={content.isInvalid} - placeholder={ - item.content_type === 'text' - ? t('input_placeholder') - : t('textarea_placeholder') - } + placeholder={item.placeholder} onChange={(e) => setContent({ value: e.target.value, diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json index 8fcaf75d..733eab86 100644 --- a/ui/src/i18n/locales/en.json +++ b/ui/src/i18n/locales/en.json @@ -199,9 +199,7 @@ }, "msg": { "empty": "Please select a reason." - }, - "input_placeholder": "Enter the existing question link", - "textarea_placeholder": "Let us know specifically what you are concerned about" + } }, "tag_modal": { "title": "Create New Tag", From eca0431e896ee1e19dab10294f83b72a0e984b72 Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 30 Sep 2022 14:20:06 +0800 Subject: [PATCH 03/83] fix: solve the problem that pictures cannot be uploaded through the clipboard --- ui/src/components/Editor/ToolBars/image.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/components/Editor/ToolBars/image.tsx b/ui/src/components/Editor/ToolBars/image.tsx index fdde738d..5f4475a2 100644 --- a/ui/src/components/Editor/ToolBars/image.tsx +++ b/ui/src/components/Editor/ToolBars/image.tsx @@ -105,7 +105,7 @@ const Image: FC = ({ editor }) => { editor.replaceRange(text.join('\n'), startPos, endPos); }; - const paste = async (event) => { + const paste = async (_, event) => { const clipboard = event.clipboardData; const bool = verifyImageSize(clipboard.files); From ab45ca256896d9afe78c24adf9a2297f4cc500c1 Mon Sep 17 00:00:00 2001 From: shuai Date: Fri, 30 Sep 2022 14:21:50 +0800 Subject: [PATCH 04/83] fix: #881 --- ui/src/i18n/locales/en.json | 3 ++- ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json index bbbb04ad..8e638ddc 100644 --- a/ui/src/i18n/locales/en.json +++ b/ui/src/i18n/locales/en.json @@ -602,7 +602,8 @@ "write_answer": { "title": "Your Answer", "btn_name": "Post your answer", - "confirm_info": "you have answered, confirm to continue answer", + "tips": "Tips", + "confirm_info": "

Are you sure you want to add another answer?

You could use the edit link to refine and improve your existing answer, instead.

", "empty": "Answer cannot be empty." } }, diff --git a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx index 1f6934e6..eb423d36 100644 --- a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx +++ b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx @@ -62,6 +62,7 @@ const Index: FC = ({ visible = false, data, callback }) => { const clickBtn = () => { if (data?.answered && !showEditor) { Modal.confirm({ + title: t('tips'), content: t('confirm_info'), onConfirm: () => { setShowEditor(true); From d74e250d26ee0aff33c61a49e59aeffdc8c33fef Mon Sep 17 00:00:00 2001 From: aichy Date: Fri, 30 Sep 2022 14:26:13 +0800 Subject: [PATCH 05/83] fix question add pv --- internal/controller/question_controller.go | 2 +- internal/service/question_service.go | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go index 748710e0..8b93230e 100644 --- a/internal/controller/question_controller.go +++ b/internal/controller/question_controller.go @@ -85,7 +85,7 @@ func (qc *QuestionController) GetQuestion(c *gin.Context) { id := c.Query("id") ctx := context.Background() userID := middleware.GetLoginUserIDFromContext(c) - info, err := qc.questionService.GetQuestion(ctx, id, userID) + info, err := qc.questionService.GetQuestion(ctx, id, userID, true) if err != nil { handler.HandleResponse(c, err, nil) return diff --git a/internal/service/question_service.go b/internal/service/question_service.go index f2273a1f..73a53e76 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -149,7 +149,7 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question log.Error("user IncreaseQuestionCount error", err.Error()) } - questionInfo, err = qs.GetQuestion(ctx, question.ID, question.UserID) + questionInfo, err = qs.GetQuestion(ctx, question.ID, question.UserID, false) return } @@ -229,20 +229,23 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest return } - questionInfo, err = qs.GetQuestion(ctx, question.ID, question.UserID) + questionInfo, err = qs.GetQuestion(ctx, question.ID, question.UserID, false) return } // GetQuestion get question one -func (qs *QuestionService) GetQuestion(ctx context.Context, id, loginUserID string) (resp *schema.QuestionInfo, err error) { +func (qs *QuestionService) GetQuestion(ctx context.Context, id, loginUserID string, addpv bool) (resp *schema.QuestionInfo, err error) { question, err := qs.questioncommon.Info(ctx, id, loginUserID) if err != nil { return } - err = qs.questioncommon.UpdataPv(ctx, id) - if err != nil { - log.Error("UpdataPv", err) + if addpv { + err = qs.questioncommon.UpdataPv(ctx, id) + if err != nil { + log.Error("UpdataPv", err) + } } + question.MemberActions = permission.GetQuestionPermission(loginUserID, question.UserId) return question, nil } @@ -466,7 +469,7 @@ func (qs *QuestionService) SearchByTitleLike(ctx context.Context, title string, // SimilarQuestion func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID string, loginUserID string) ([]*schema.QuestionInfo, int64, error) { list := make([]*schema.QuestionInfo, 0) - questionInfo, err := qs.GetQuestion(ctx, questionID, loginUserID) + questionInfo, err := qs.GetQuestion(ctx, questionID, loginUserID, false) if err != nil { return list, 0, err } From 7c8e109987a1b3ae524924d7cc2f261b6dfd2f50 Mon Sep 17 00:00:00 2001 From: "haitao(lj)" Date: Fri, 30 Sep 2022 14:35:31 +0800 Subject: [PATCH 06/83] chore: remove unused console.log --- ui/src/pages/Search/components/SearchItem/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/src/pages/Search/components/SearchItem/index.tsx b/ui/src/pages/Search/components/SearchItem/index.tsx index 73e98a03..6855d1cf 100644 --- a/ui/src/pages/Search/components/SearchItem/index.tsx +++ b/ui/src/pages/Search/components/SearchItem/index.tsx @@ -10,7 +10,6 @@ interface Props { } const Index: FC = ({ data }) => { const { t } = useTranslation('translation', { keyPrefix: 'question' }); - console.log('t: ', t); if (!data?.object_type) { return null; } From 6da181a7bf128982b47462e41cfbc3e92ec502d3 Mon Sep 17 00:00:00 2001 From: aichy Date: Fri, 30 Sep 2022 14:43:15 +0800 Subject: [PATCH 07/83] remove spew --- internal/base/middleware/auth.go | 99 ++++++++++++-------------------- internal/repo/question_repo.go | 1 - internal/schema/user_schema.go | 4 -- 3 files changed, 38 insertions(+), 66 deletions(-) diff --git a/internal/base/middleware/auth.go b/internal/base/middleware/auth.go index c3fd6dc0..ccf40dda 100644 --- a/internal/base/middleware/auth.go +++ b/internal/base/middleware/auth.go @@ -3,7 +3,6 @@ package middleware import ( "strings" - "github.com/davecgh/go-spew/spew" "github.com/segmentfault/answer/internal/schema" "github.com/gin-gonic/gin" @@ -39,20 +38,13 @@ func (am *AuthUserMiddleware) Auth() gin.HandlerFunc { ctx.Next() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 Auth", userInfo) + userInfo, err := am.authService.GetUserCacheInfo(ctx, token) + if err != nil { + ctx.Next() + return + } + if userInfo != nil { ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetUserCacheInfo(ctx, token) - if err != nil { - ctx.Next() - return - } - if userInfo != nil { - ctx.Set(ctxUuidKey, userInfo) - } } ctx.Next() } @@ -67,38 +59,30 @@ func (am *AuthUserMiddleware) MustAuth() gin.HandlerFunc { ctx.Abort() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 MustAuth", userInfo) - ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetUserCacheInfo(ctx, token) - spew.Dump(userInfo, err) - if err != nil || userInfo == nil { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - if userInfo.EmailStatus != entity.EmailStatusAvailable { - handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified), - &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive}) - ctx.Abort() - return - } - if userInfo.UserStatus == entity.UserStatusSuspended { - handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), - &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) - ctx.Abort() - return - } - if userInfo.UserStatus == entity.UserStatusDeleted { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - ctx.Set(ctxUuidKey, userInfo) + userInfo, err := am.authService.GetUserCacheInfo(ctx, token) + if err != nil || userInfo == nil { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return } + if userInfo.EmailStatus != entity.EmailStatusAvailable { + handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified), + &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive}) + ctx.Abort() + return + } + if userInfo.UserStatus == entity.UserStatusSuspended { + handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), + &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) + ctx.Abort() + return + } + if userInfo.UserStatus == entity.UserStatusDeleted { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return + } + ctx.Set(ctxUuidKey, userInfo) ctx.Next() } } @@ -111,26 +95,19 @@ func (am *AuthUserMiddleware) CmsAuth() gin.HandlerFunc { ctx.Abort() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 CmsAuth", userInfo) - ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token) - if err != nil { + userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token) + if err != nil { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return + } + if userInfo != nil { + if userInfo.UserStatus == entity.UserStatusDeleted { handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) ctx.Abort() return } - if userInfo != nil { - if userInfo.UserStatus == entity.UserStatusDeleted { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - ctx.Set(ctxUuidKey, userInfo) - } + ctx.Set(ctxUuidKey, userInfo) } ctx.Next() } diff --git a/internal/repo/question_repo.go b/internal/repo/question_repo.go index 986a34e5..9514d6b7 100644 --- a/internal/repo/question_repo.go +++ b/internal/repo/question_repo.go @@ -218,7 +218,6 @@ func (qr *questionRepo) SearchList(ctx context.Context, search *schema.QuestionS session = session.Limit(search.PageSize, offset) session = session.Select("question.id,question.user_id,question.title,question.original_text,question.parsed_text,question.status,question.view_count,question.unique_view_count,question.vote_count,question.answer_count,question.collection_count,question.follow_count,question.accepted_answer_id,question.last_answer_id,question.created_at,question.updated_at,question.post_update_time,question.revision_id") count, err = session.FindAndCount(&rows) - //spew.Dump("search", err, count, rows) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() return rows, count, err diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index e51c0a93..38a9938f 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -3,7 +3,6 @@ package schema import ( "encoding/json" - "github.com/davecgh/go-spew/spew" "github.com/jinzhu/copier" "github.com/segmentfault/answer/internal/base/validator" "github.com/segmentfault/answer/internal/entity" @@ -133,7 +132,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User if ok { r.Status = statusShow } - spew.Dump(userInfo) if userInfo.MailStatus == entity.EmailStatusToBeVerified { statusMsgShow, ok := UserStatusShowMsg[11] if ok { @@ -146,8 +144,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User } } - spew.Dump(r) - } const ( From 2cf314f0c5235a6f17895fd34a41f97843f14752 Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 30 Sep 2022 14:43:41 +0800 Subject: [PATCH 08/83] refactor: responsive layout adjustments --- ui/src/pages/Users/Settings/index.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ui/src/pages/Users/Settings/index.tsx b/ui/src/pages/Users/Settings/index.tsx index a2e8418a..45f3080c 100644 --- a/ui/src/pages/Users/Settings/index.tsx +++ b/ui/src/pages/Users/Settings/index.tsx @@ -59,13 +59,21 @@ const Index: React.FC = () => { return ( <> - -

{t('page_title', { keyPrefix: 'settings' })}

+ + + +

+ {t('page_title', { keyPrefix: 'settings' })} +

+ +
+ - + +