fix: prevent UserButton from fetching user info even before click

This commit is contained in:
hippoz 2021-10-23 17:49:40 +03:00
parent 0090f5dc90
commit cbe1feb2a2
Signed by: hippoz
GPG key ID: 7C52899193467641
2 changed files with 6 additions and 4 deletions

View file

@ -80,8 +80,8 @@ export default function ChannelCreateButton() {
{/* ugly: AnimatePresence is needed to animate the modal closing */} {/* ugly: AnimatePresence is needed to animate the modal closing */}
<AnimatePresence> <AnimatePresence>
{(isDialogOpen) && <Modal {(isDialogOpen) && <Modal
width="500px" width="425px"
height="300px" height="275px"
title="Create a channel" title="Create a channel"
alignItems="center" alignItems="center"
onClose={ handleClose } onClose={ handleClose }

View file

@ -10,6 +10,8 @@ export default function ChannelUserButton({ user, subtext }) {
const [userObject, setUserObject] = useState(null); const [userObject, setUserObject] = useState(null);
useEffect(() => { useEffect(() => {
if (!isPromptOpen) return;
if (userObject) return;
authenticated(`/api/v1/users/user/${user._id}/info`, { authenticated(`/api/v1/users/user/${user._id}/info`, {
method: 'GET', method: 'GET',
headers: { headers: {
@ -20,7 +22,7 @@ export default function ChannelUserButton({ user, subtext }) {
setUserObject(json.user); setUserObject(json.user);
} }
}); });
}, [user]); }, [user, isPromptOpen, userObject]);
return ( return (
<> <>