Skip to content

Commit

Permalink
Merge pull request #17 from DevlinRocha/view-profile
Browse files Browse the repository at this point in the history
Prevents profile card from rendering off-screen
  • Loading branch information
DevlinRocha authored Jan 9, 2022
2 parents 1d95b82 + 15d0af4 commit b20f5e2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/components/MemberProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@ import {
useServersState,
} from "../features/servers";
import { useAppDispatch } from "../redux/hooks";
import { useEffect, useRef, useState } from "react";
import { useEffect, useLayoutEffect, useRef } from "react";
import { doc, onSnapshot } from "firebase/firestore";
import { UserData } from "../features/user";
import { db } from "../../firebase";

export default function MemberProfileCard() {
const { member, memberID, memberProfileCardPosition } = useServersState();
const [setContainerStyle] = useState<any>({});
const containerRef = useRef<HTMLElement>();
const dispatch = useAppDispatch();

const containerRef = useRef<HTMLElement | null>(null);
const skippedRender = useRef(false);

const onRef = (node: HTMLElement) => {
if (node) containerRef.current = node;
};

useEffect(() => {
if (skippedRender.current) {
return;
}
skippedRender.current = true;
}, []);

useEffect(() => {
useLayoutEffect(() => {
if (
!memberProfileCardPosition ||
!memberProfileCardPosition.top ||
Expand All @@ -45,9 +47,7 @@ export default function MemberProfileCard() {
})
);
}

setContainerStyle(memberProfileCardPosition);
}, [memberProfileCardPosition]);
}, [memberProfileCardPosition, onRef]);

useEffect(() => {
const unsubscribe = onSnapshot(doc(db, "users", memberID), (doc) => {
Expand Down Expand Up @@ -90,10 +90,10 @@ export default function MemberProfileCard() {

return (
<Backdrop onClick={closeWindow}>
{skippedRender.current ? (
{skippedRender.current && (
<Container
onClick={stopPropagation}
ref={containerRef}
ref={onRef}
style={memberProfileCardPosition}
>
<Banner style={bannerStyle} />
Expand Down Expand Up @@ -122,7 +122,7 @@ export default function MemberProfileCard() {
<AboutMeContainer>{member.about}</AboutMeContainer>
</ProfileContainer>
</Container>
) : null}
)}
</Backdrop>
);
}
Expand Down

1 comment on commit b20f5e2

@vercel
Copy link

@vercel vercel bot commented on b20f5e2 Jan 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.