Skip to content

Commit

Permalink
update frontend to support only activate and deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
hgaol committed May 7, 2024
1 parent 806dbaf commit 9eaad32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion internal/repo/meta/meta_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions ui/src/pages/Questions/Detail/components/Reactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
});
};
Expand Down

0 comments on commit 9eaad32

Please sign in to comment.