Skip to content

Commit

Permalink
fix(contributions): bug d'affichage des commentaires (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Jun 20, 2023
1 parent 484840f commit 839c784
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion targets/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@urql/exchange-auth": "^0.1.6",
"@zeit/next-source-maps": "0.0.4-canary.1",
"ace-builds": "^1.4.12",
"argon2": "^0.28.2",
"argon2": "^0.30.3",
"cookie": "^0.4.1",
"d3": "^6.7.0",
"d3-hierarchy": "^2.0.0",
Expand Down
25 changes: 3 additions & 22 deletions targets/frontend/src/components/contributions/answers/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ type Props = {

export const Comments = (props: Props) => {
const { user }: any = useUser();
const [localComments, setLocalComments] = React.useState<AnswerComments[]>(
props.comments ?? []
);

React.useEffect(() => {
setLocalComments(props.comments);
}, [props.comments]);

const listRef = React.useRef<HTMLDivElement>(null);

Expand All @@ -53,27 +46,15 @@ export const Comments = (props: Props) => {
if (listRef.current) {
listRef.current.scrollTop = listRef.current.scrollHeight;
}
}, [localComments]);
}, [props.comments]);

const onSubmit = async (data: MutationProps) => {
try {
await insertComment({
answerId: props.answerId,
content: data.content,
userId: user.id,
});
if (localComments.length === 0) {
setLocalComments([
{
answerId: props.answerId,
content: data.content,
createdAt: new Date().toISOString(),
id: "new",
user,
userId: user.id,
} as any,
]);
}
}, { additionalTypenames: ['AnswerComments'] });
setSnack({
open: true,
severity: "success",
Expand Down Expand Up @@ -104,7 +85,7 @@ export const Comments = (props: Props) => {
overflow: "auto",
}}
>
{localComments.map((comment) => (
{props.comments.map((comment) => (
<Comment key={comment.id} comment={comment} />
))}
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from "urql";
import {useMemo} from "react";

import { Answer, AnswerStatus } from "../type";
import { initStatus } from "../status/utils";
Expand Down Expand Up @@ -80,11 +81,13 @@ type QueryResult = {
export const useContributionAnswerQuery = ({
id,
}: QueryProps): AnswerWithStatus | undefined => {
const context = useMemo(() => ({ additionalTypenames: ['AnswerComments'] }), []);
const [result] = useQuery<QueryResult>({
query: contributionAnswerQuery,
variables: {
id,
},
context
});
if (
!result?.data?.contribution_answers ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export type MutationProps = Omit<
"user" | "answer" | "id" | "createdAt"
>;

type MutationResult = (props: MutationProps) => Promise<OperationResult>;

export const useCommentsInsert = (): MutationResult => {
export const useCommentsInsert = () => {
const [, executeUpdate] = useMutation<MutationProps>(insertCommentMutation);
return executeUpdate;
};
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@
"@linaria/logger" "^4.0.0"
babel-merge "^3.0.0"

"@mapbox/node-pre-gyp@^1.0.9":
"@mapbox/node-pre-gyp@^1.0.10":
version "1.0.10"
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz#8e6735ccebbb1581e5a7e652244cadc8a844d03c"
integrity sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==
Expand Down Expand Up @@ -5487,12 +5487,12 @@ arg@^4.1.0:
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

argon2@^0.28.2:
version "0.28.7"
resolved "https://registry.yarnpkg.com/argon2/-/argon2-0.28.7.tgz#f6cc1f1c9e3ef5455d2186d4ec5b27cfeda41591"
integrity sha512-pvsScM3Fq7b+jolXkZHh8nRQx0uD/WeelnwYPMRpn4pAydoa1gqeL/KRdWAag4Hnu1TJNBTAfqyTjV+ZHwNnYA==
argon2@^0.30.3:
version "0.30.3"
resolved "https://registry.yarnpkg.com/argon2/-/argon2-0.30.3.tgz#795ca57acad76fc67dd5695732662a03018b84ed"
integrity sha512-DoH/kv8c9127ueJSBxAVJXinW9+EuPA3EMUxoV2sAY1qDE5H9BjTyVF/aD2XyHqbqUWabgBkIfcP3ZZuGhbJdg==
dependencies:
"@mapbox/node-pre-gyp" "^1.0.9"
"@mapbox/node-pre-gyp" "^1.0.10"
"@phc/format" "^1.0.0"
node-addon-api "^5.0.0"

Expand Down

0 comments on commit 839c784

Please sign in to comment.