Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): fix chat icon position #164

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ export function Footer({ isProtected }: FooterProps) {
</Typography>
</Grid>
<Grid
alignItems="center"
item
justifyContent="flex-end"
sx={{
position: isMobile ? 'absolute' : 'relative',
right: isMobile ? '32px' : 0,
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
}}
xs={isMobile ? 12 : 1}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,61 @@ export function Chat() {
const ref = useRef<HTMLDivElement>(null);

useEffect(() => {
const observer = new MutationObserver((mutationsList) => {
let chatElement: HTMLElement | undefined;
const root = document.getElementById('root') as Element | undefined;
if (!root) return;

const positionChatElement = () => {
if (chatElement && ref.current) {
const refRect = ref.current.getBoundingClientRect();
const rootRect = root.getBoundingClientRect();

chatElement.style.position = 'absolute';
chatElement.style.top = `${refRect.top - rootRect.top}px`;
chatElement.style.left = `${refRect.left - rootRect.left}px`;
chatElement.style.width = `${refRect.width}px`;
chatElement.style.height = `${refRect.height}px`;
}
};

const mutationObserver = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const chatElement = document.querySelector('[data-id="zsalesiq"]') as
chatElement = document.querySelector('[data-id="zsalesiq"]') as
| HTMLElement
| undefined;
if (
chatElement &&
ref.current &&
!ref.current.contains(chatElement)
) {
chatElement.style.position = 'absolute';
chatElement.style.top = '0';
chatElement.style.bottom = '0';
chatElement.style.right = '0';
chatElement.style.left = '0';
ref.current.appendChild(chatElement);
if (chatElement && ref.current) {
positionChatElement();
}
}
}
});

observer.observe(document.body, {
mutationObserver.observe(document.body, {
childList: true,
subtree: true,
});

const resizeObserverElement = document.createElement('div');
resizeObserverElement.style.position = 'absolute';
resizeObserverElement.style.width = '100%';
resizeObserverElement.style.height = '100%';
resizeObserverElement.style.top = '0';
resizeObserverElement.style.left = '0';
resizeObserverElement.style.opacity = '0';
resizeObserverElement.style.pointerEvents = 'none';
document.body.appendChild(resizeObserverElement);

const resizeObserver = new ResizeObserver(positionChatElement);

resizeObserver.observe(resizeObserverElement);

return () => {
observer.disconnect();
resizeObserver.disconnect();
mutationObserver.disconnect();
if (resizeObserverElement.parentNode) {
resizeObserverElement.parentNode.removeChild(resizeObserverElement);
}
};
}, [ref]);

Expand Down
Loading