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: UI bug for user message to take available screen space #32

Closed
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
19 changes: 17 additions & 2 deletions src/components/UserMessage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import user from '../img/user-img.png';
import { UserResponseList } from './UserResponseList';
import urlToJSON from './utils/urlToJSON';
Expand All @@ -7,14 +7,29 @@ import BackIcon from '../img/back.png';

export default function UserMessage({ setjsonPathMap, jsonPathMap, pathId }) {
const [userName, setuserName] = useState('Test-User >');
const userMessageSection = useRef(null);

useEffect(() => {
setjsonPathMap(urlToJSON(pathId));
urlToJSON(pathId);
setuserName('You');
if(userMessageSection.current)
applyAvailableHeight()
}, [pathId, setjsonPathMap]);

//This function finds the available space and set the user-message parent wrapper height accordingly
function applyAvailableHeight(){
const windowWidth = window.innerHeight;
const userMessageSectionOffset = userMessageSection.current.getBoundingClientRect().top;
const userMessageSectionStyle = window.getComputedStyle(userMessageSection.current);
let marginOffset = Number.parseInt(userMessageSectionStyle.getPropertyValue('margin-top'));
let availableSpace = windowWidth - ( userMessageSectionOffset + 2*marginOffset );

userMessageSection.current.style.height = `${availableSpace}px`
}

return (
<div className='user-message-section scroll'>
<div className='user-message-section scroll' ref={userMessageSection}>
{/* Back button link */}
{/* when pathId===undefined (i.e. First Message) --> Don't render back buttom. */}
{pathId !== undefined ? (
Expand Down
7 changes: 3 additions & 4 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,18 @@ body {
display: flex;
justify-content: flex-end;
flex-direction: row;
height: 50%;
}
.user-message {
box-sizing: border-box;
overflow: auto;
border: solid 0.2em;
border-color: $greenUtility;
width: fit-content;
position: relative;
border-radius: 10px;
max-height: 10em;
min-height: 35%;
height: fit-content;
max-height: 100%;
padding: 1em;
padding-bottom: 0;
background: $blackPrimary;
font-size: 1.5em;
opacity: 0.85;
Expand Down