From abeecaa6383d33403f9a0efab19d95ed9817c987 Mon Sep 17 00:00:00 2001 From: Gandharv Date: Thu, 11 Nov 2021 21:23:02 +0530 Subject: [PATCH] Fix for users api being called multiple times (#1389) --- frontend/src/Editor/Comment/CommentFooter.jsx | 9 +- frontend/src/Editor/Comment/index.jsx | 3 +- frontend/src/Editor/Comments.jsx | 17 +++- frontend/src/_ui/Mentions/index.js | 87 +------------------ 4 files changed, 25 insertions(+), 91 deletions(-) diff --git a/frontend/src/Editor/Comment/CommentFooter.jsx b/frontend/src/Editor/Comment/CommentFooter.jsx index 7b32759f0d..63a3bf8fde 100644 --- a/frontend/src/Editor/Comment/CommentFooter.jsx +++ b/frontend/src/Editor/Comment/CommentFooter.jsx @@ -7,7 +7,7 @@ import Button from '@/_ui/Button'; import useShortcuts from '@/_hooks/use-shortcuts'; import usePopover from '@/_hooks/use-popover'; -function CommentFooter({ editComment = '', editCommentId, handleSubmit }) { +function CommentFooter({ users, editComment = '', editCommentId, handleSubmit }) { const [comment, setComment] = React.useState(editComment); const [loading, setLoading] = React.useState(false); const [open, trigger, content, setOpen] = usePopover(false); @@ -38,7 +38,12 @@ function CommentFooter({ editComment = '', editCommentId, handleSubmit }) {
- +
diff --git a/frontend/src/Editor/Comment/index.jsx b/frontend/src/Editor/Comment/index.jsx index fc216653ed..a0ecf5cba2 100644 --- a/frontend/src/Editor/Comment/index.jsx +++ b/frontend/src/Editor/Comment/index.jsx @@ -11,7 +11,7 @@ import usePopover from '@/_hooks/use-popover'; import { commentsService } from '@/_services'; import useRouter from '@/_hooks/use-router'; -const Comment = ({ socket, x, y, threadId, user = {}, isResolved, fetchThreads, appVersionsId }) => { +const Comment = ({ socket, x, y, threadId, user = {}, isResolved, fetchThreads, appVersionsId, users }) => { const [loading, setLoading] = React.useState(true); const [editComment, setEditComment] = React.useState(''); const [editCommentId, setEditCommentId] = React.useState(''); @@ -156,6 +156,7 @@ const Comment = ({ socket, x, y, threadId, user = {}, isResolved, fetchThreads, thread={thread} /> { const [threads, setThreads] = React.useState([]); const router = useRouter(); + const [users, setUsers] = React.useState([]); + + React.useEffect(() => { + organizationService.getUsers(null).then((data) => { + const _users = data.users.map((u) => ({ + id: u.id, + display: `${capitalize(u.first_name)} ${capitalize(u.last_name)}`, + })); + setUsers(_users); + }); + }, []); + async function fetchData() { const { data } = await commentsService.getThreads(router.query.id, appVersionsId); setThreads(data); @@ -43,6 +55,7 @@ const Comments = ({ newThread = {}, appVersionsId, socket }) => { fetchThreads={fetchData} socket={socket} threadId={id} + users={users} {...thread} /> ); diff --git a/frontend/src/_ui/Mentions/index.js b/frontend/src/_ui/Mentions/index.js index 6c4fad9a02..84807299fc 100644 --- a/frontend/src/_ui/Mentions/index.js +++ b/frontend/src/_ui/Mentions/index.js @@ -1,36 +1,8 @@ import React from 'react'; -import { capitalize } from 'lodash'; -import { organizationService } from '@/_services'; import { MentionsInput, Mention } from 'react-mentions'; -// const { emojis } = require('./emojis.json'); - -const Mentions = ({ value, setValue, placeholder }) => { - const [users, setUsers] = React.useState([]); - - // TODO: move this to context etc, this loads the users x number to imports - React.useEffect(() => { - organizationService.getUsers(null).then((data) => { - const _users = data.users.map((u) => ({ - id: u.id, - display: `${capitalize(u.first_name)} ${capitalize(u.last_name)}`, - })); - setUsers(_users); - }); - }, []); - - const queryEmojis = (query) => { - if (query.length === 0) return; - - return; - // const matches = emojis - // .filter((emoji) => { - // return emoji.name.indexOf(query.toLowerCase()) > -1; - // }) - // .slice(0, 10); - // return matches.map(({ emoji }) => ({ id: emoji })); - }; +const Mentions = ({ users, value, setValue, placeholder }) => { return ( { // }} appendSpaceOnAdd /> - ); }; -// const Mentions = ({ value, setValue, placeholder }) => { -// const [open, trigger, content, setOpen] = usePopover(false); -// const handleChange = (e) => { -// e.stopPropagation(); -// if (e.target.value.includes('@')) { -// setOpen(true); -// } -// setValue(e.target.value); -// }; - -// let conditionalProps = {}; - -// if (open) { -// conditionalProps = { ...trigger }; -// } -// return ( -// <> -// -//
-//
-//
-//
-//
-// -// JL -// -//
-//
-// -// Jeffie Lewzey -// -// -// justify-content:between ⇒ justify-content:space-between (#29734) -// -//
-//
-//
-//
-//
-// -// ); -// }; - export default Mentions;