This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit a6838eb4dc31888641d0ed4d11ba46033bfc8aee Author: hgaol <[email protected]> AuthorDate: Wed May 8 00:49:07 2024 +0800 update frontend to support only activate and deactivate --- internal/repo/meta/meta_repo.go | 1 - .../pages/Questions/Detail/components/Reactions/index.tsx | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/repo/meta/meta_repo.go b/internal/repo/meta/meta_repo.go index 160201cf..c3e85c71 100644 --- a/internal/repo/meta/meta_repo.go +++ b/internal/repo/meta/meta_repo.go @@ -88,7 +88,6 @@ func (mr *metaRepo) AddOrUpdateMetaByObjectIdAndKey(ctx context.Context, req *sc // if not exist, create new one if !exist { reaction = schema.ReactSummaryMeta{} - return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() } else { err = json.Unmarshal([]byte(metaEntity.Value), &reaction) if err != nil { diff --git a/ui/src/pages/Questions/Detail/components/Reactions/index.tsx b/ui/src/pages/Questions/Detail/components/Reactions/index.tsx index f7318dd8..5ade0319 100644 --- a/ui/src/pages/Questions/Detail/components/Reactions/index.tsx +++ b/ui/src/pages/Questions/Detail/components/Reactions/index.tsx @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'; import { Icon } from '@/components'; import { queryReactions, updateReaction } from '@/services'; import { tryNormalLogged } from '@/utils/guard'; +import { loggedUserInfoStore } from '@/stores'; interface Props { objectId: string; @@ -35,8 +36,9 @@ const Index: FC<Props> = ({ showAddCommentBtn, handleClickComment, }) => { - const [reactions, setReactions] = useState<Record<string, string[]>>(); + const [reactions, setReactions] = useState<Record<string, string[]>>({}); const { t } = useTranslation('translation'); + const { username = '' } = loggedUserInfoStore((state) => state.user); useEffect(() => { queryReactions(objectId).then((res) => { @@ -48,7 +50,15 @@ const Index: FC<Props> = ({ if (!tryNormalLogged(true)) { return; } - updateReaction({ ...params, type: 'toggle' }).then((res) => { + let reaction = 'activate'; + if ( + reactions && + reactions[params.emoji] && + reactions[params.emoji].includes(username) + ) { + reaction = 'deactivate'; + } + updateReaction({ ...params, reaction }).then((res) => { setReactions(res); }); };
