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 14, 2025
1 parent 11dacbe commit 4969ff7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 35 deletions.
8 changes: 6 additions & 2 deletions assets/js/Containers/FrevaGPT/components/ChatBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ class ChatBlock extends React.Component {

for (const element of conversation) {
if (element.variant !== "Code" && element.variant !== "CodeOutput") {
if (element.variant !== "ServerHint" && element.variant !== "StreamEnd") {
if (
element.variant !== "ServerHint" &&
element.variant !== "StreamEnd"
) {
newConv.push([element]);
}
} else {
const existingIndex = newConv.findIndex(
(x) => x[0].content.length > 1 && x[0].content[1] === element.content[1]
(x) =>
x[0].content.length > 1 && x[0].content[1] === element.content[1]
);
if (existingIndex === -1) {
newConv.push([element]);
Expand Down
72 changes: 47 additions & 25 deletions assets/js/Containers/FrevaGPT/components/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,81 @@ import Highlight from "react-highlight";
import { formatCode } from "../utils";

class CodeBlock extends React.Component {

constructor(props) {
super(props);
this.toggleShowCode = this.toggleShowCode.bind(this);
this.extractElements = this.extractElements.bind(this);

this.state = {
showCode: true,
}
};
}

toggleShowCode(status) {
this.setState({showCode: !status});
this.setState({ showCode: !status });
}

extractElements(content, variant) {
return content.filter(elem => elem.variant === variant)
return content.filter((elem) => elem.variant === variant);
}

render() {
return (
<Card className="shadow-sm card-body border-0 border-bottom mb-3 bg-light">
<Button variant="link" className="m-0 p-0 d-inline-flex text-decoration-none" onClick={() => {this.toggleShowCode(this.state.showCode)}}>
<span style={{ fontWeight: "bold" }} className="color">Analyzed</span>
<Button
variant="link"
className="m-0 p-0 d-inline-flex text-decoration-none"
onClick={() => {
this.toggleShowCode(this.state.showCode);
}}
>
<span style={{ fontWeight: "bold" }} className="color">
Analyzed
</span>
<span>
{this.state.showCode ? <FaAngleUp className="color"/> : <FaAngleDown className="color"/>}
{this.state.showCode ? (
<FaAngleUp className="color" />
) : (
<FaAngleDown className="color" />
)}
</span>
</Button>

<Collapse in={this.state.showCode} className="mt-2">
<Card className="shadow-sm">
<Card.Header style={{ backgroundColor: "#eee" }}>python</Card.Header>
<Card.Header style={{ backgroundColor: "#eee" }}>
python
</Card.Header>

{this.extractElements(this.props.content, "Code").map((codeElement) => {
return(
<Card.Body className="p-0 m-0" key={`${codeElement.content[1]}-code`}>
<Highlight className="python">
{formatCode("Code", codeElement.content[0])}
</Highlight>
</Card.Body>
)}
{this.extractElements(this.props.content, "Code").map(
(codeElement) => {
return (
<Card.Body
className="p-0 m-0"
key={`${codeElement.content[1]}-code`}
>
<Highlight className="python">
{formatCode("Code", codeElement.content[0])}
</Highlight>
</Card.Body>
);
}
)}

{this.extractElements(this.props.content, "CodeOutput").map((codeElement, index) => {
return(
<Card.Footer className="p-0 m-0" key={`${codeElement.content[1]}-codeoutput-${index}`}>
<Highlight className="python">
{formatCode("CodeOutput", codeElement.content[0])}
</Highlight>
</Card.Footer>
)}
{this.extractElements(this.props.content, "CodeOutput").map(
(codeElement, index) => {
return (
<Card.Footer
className="p-0 m-0"
key={`${codeElement.content[1]}-codeoutput-${index}`}
>
<Highlight className="python">
{formatCode("CodeOutput", codeElement.content[0])}
</Highlight>
</Card.Footer>
);
}
)}

</Card>
</Collapse>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const PendingAnswerComponent = forwardRef((props, ref) => {
if (parsedCode !== "") {
setRenderedCode(parsedCode);
}

if (props.position && props.content !== "") {
ref.current?.scrollIntoView({behavior: 'smooth'});
ref.current?.scrollIntoView({ behavior: "smooth" });
}
}, [props.content]);

Expand Down Expand Up @@ -61,9 +61,7 @@ const PendingAnswerComponent = forwardRef((props, ref) => {
<Card className="shadow-sm mt-2">
<Card.Header>python</Card.Header>
<Card.Body className="p-0 m-0">
<Highlight className="python">
{renderedCode}
</Highlight>
<Highlight className="python">{renderedCode}</Highlight>
<span>
<Spinner size="sm" />
</span>
Expand Down
10 changes: 7 additions & 3 deletions assets/js/Containers/FrevaGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class FrevaGPT extends React.Component {
onScroll={debounce(this.handleScroll, 100)}
>
<Col md={12}>
<ChatBlock onScrollDown={this.scrollDown}/>
<ChatBlock onScrollDown={this.scrollDown} />

<PendingAnswerComponent
content={this.state.dynamicAnswer}
Expand All @@ -417,8 +417,12 @@ class FrevaGPT extends React.Component {
<Row className="mb-3">
<Col md={3}>
<Card className="shadow-sm card-body border-0 border-bottom mb-3 bg-light d-flex flex-row align-items-center">
<Spinner size="sm"/>
<span className="ms-2">{ this.lastVariant.current === "Code" ? "Executing..." : "Thinking..." }</span>
<Spinner size="sm" />
<span className="ms-2">
{this.lastVariant.current === "Code"
? "Executing..."
: "Thinking..."}
</span>
</Card>
</Col>
</Row>
Expand Down

0 comments on commit 4969ff7

Please sign in to comment.