Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update frontend to support only activate and deactivate

hgaola6838eb4dc31
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);
});
};