Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Wentzel committed Feb 10, 2025
1 parent 7d595f3 commit ce69038
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 45 deletions.
37 changes: 21 additions & 16 deletions assets/js/Containers/FrevaGPT/components/ChatBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,36 @@ class ChatBlock extends React.Component {
this.enlargeImage = this.enlargeImage.bind(this);

this.state = {
showModal: false
}
showModal: false,
};
}

enlargeImage(imageString) {
this.setState({showModal: true, image: `data:image/jpeg;base64,${imageString}`})
this.setState({
showModal: true,
image: `data:image/jpeg;base64,${imageString}`,
});
}

renderImage(element, index) {
return (
<Col
<Col
key={`${index}-image`}
md={constants.BOT_COLUMN_STYLE}
className="border-0 border-bottom mb-3 shadow-sm card-body">
className="border-0 border-bottom mb-3 shadow-sm card-body"
>
<img
className="w-100"
onClick={() => this.enlargeImage(element.content)}
src={`data:image/jpeg;base64,${element.content}`}
/>
<div className="d-flex justify-content-end">
<Button
<Button
variant="link"
onClick={() => this.enlargeImage(element.content)}
className="d-flex align-items-center">
<FaExpand/>
className="d-flex align-items-center"
>
<FaExpand />
</Button>
</div>
</Col>
Expand Down Expand Up @@ -146,19 +151,19 @@ class ChatBlock extends React.Component {
})}
</Col>

<Modal
size="lg"
aria-labelledby="contained-modal-title-vcenter"
centered
show={this.state.showModal}
onHide={() => this.setState({ showModal: false, image: '' })}>
<Modal
size="lg"
aria-labelledby="contained-modal-title-vcenter"
centered
show={this.state.showModal}
onHide={() => this.setState({ showModal: false, image: "" })}
>
<Modal.Header closeButton></Modal.Header>
<Modal.Body>
<img className="w-100" src={this.state.image}/>
<img className="w-100" src={this.state.image} />
</Modal.Body>
</Modal>
</>

);
}
}
Expand Down
72 changes: 43 additions & 29 deletions assets/js/Containers/FrevaGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class FrevaGPT extends React.Component {
// const signal = abortController.signal;

constructor(props) {

super(props);
this.handleUserInput = this.handleUserInput.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
Expand Down Expand Up @@ -69,7 +68,6 @@ class FrevaGPT extends React.Component {
}

async componentDidMount() {

// document.querySelector
// document.getElementById('chatContainer').addEventListener('scroll', this.handleScroll)

Expand Down Expand Up @@ -334,17 +332,21 @@ class FrevaGPT extends React.Component {
}

handleScroll() {
const container = document.querySelector('#chatContainer');
this.setState({ atBottom: container.scrollTop + container.clientHeight >= container.scrollHeight - 200});
const container = document.querySelector("#chatContainer");
this.setState({
atBottom:
container.scrollTop + container.clientHeight >=
container.scrollHeight - 200,
});
}

resizeInputField() {
const input_field = document.getElementById('input_field');
const input_field = document.getElementById("input_field");
const style = input_field.style;

style.height = input_field.style.minHeight = 'auto';
style.minHeight = `${ Math.min(input_field.scrollHeight, parseInt(input_field.style.maxHeight)) }px`;
style.height = `${ input_field.scrollHeight }px`;
style.height = input_field.style.minHeight = "auto";
style.minHeight = `${Math.min(input_field.scrollHeight, parseInt(input_field.style.maxHeight))}px`;
style.height = `${input_field.scrollHeight}px`;
}

renderAlert() {
Expand All @@ -366,10 +368,10 @@ class FrevaGPT extends React.Component {
// here also no suitable solutions using bootstrap found -> need for better solution
const scrollButtonStyle = {
zIndex: 10,
right: '40px',
bottom: '10px',
position: 'sticky',
}
right: "40px",
bottom: "10px",
position: "sticky",
};

return (
<>
Expand All @@ -387,8 +389,11 @@ class FrevaGPT extends React.Component {
}
style={chatWindow}
>

<Row className="overflow-auto position-relative" id="chatContainer" onScroll={debounce(this.handleScroll, 100)}>
<Row
className="overflow-auto position-relative"
id="chatContainer"
onScroll={debounce(this.handleScroll, 100)}
>
<Col md={12}>
<ChatBlock />

Expand All @@ -408,19 +413,29 @@ class FrevaGPT extends React.Component {
<div ref={this.chatEndRef}></div>
</Col>

{this.state.atBottom ? <Col md={12}></Col> : (
<Col md={12} style={scrollButtonStyle} className="d-flex flex-row justify-content-end">
<Button
{this.state.atBottom ? (
<Col md={12}></Col>
) : (
<Col
md={12}
style={scrollButtonStyle}
className="d-flex flex-row justify-content-end"
>
<Button
variant="secondary"
onClick={() => this.chatEndRef.current?.scrollIntoView({behavior: 'smooth'})}>
<FaArrowDown/>
</Button>
onClick={() =>
this.chatEndRef.current?.scrollIntoView({
behavior: "smooth",
})
}
>
<FaArrowDown />
</Button>
</Col>
)}

</Row>
<Row>

<Row>
{this.state.showSuggestions ? (
<Row className="mb-2 g-2">
{botSuggestions.map((element) => {
Expand Down Expand Up @@ -451,11 +466,10 @@ class FrevaGPT extends React.Component {
id="input_field"
rows={1}
value={this.state.userInput}
onChange={e => {
this.handleUserInput(e);
this.resizeInputField();
}
}
onChange={(e) => {
this.handleUserInput(e);
this.resizeInputField();
}}
onKeyDown={this.handleKeyDown}
placeholder="Ask a question"
/>
Expand Down

0 comments on commit ce69038

Please sign in to comment.