Skip to content

Commit

Permalink
Mix in main App and new LogViewerComponent based on react-log-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed Feb 6, 2023
1 parent c7a31dc commit ff45a28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
40 changes: 40 additions & 0 deletions web/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//const wsurl = 'ws://' + window.location.host + '/ws'; //PROD //TODO: Set this to PROD before ship
//const url = window.location.protocol + "//" + window.location.host //PROD
import ReconnectingWebSocket from "reconnecting-websocket";
import MainLayout from "./MainLayout";
import {useEffect, useState} from "react";

const wsurl = 'ws://localhost:8884/ws' //DEV
const url = 'http://localhost:8884' //DEV

const rws = new ReconnectingWebSocket(wsurl);

const App = (props) => {
const [lines, setLines] = useState([]);
const [title, setTitle] = useState("logstation");
useEffect(() => {
connect()

});

function connect() {
rws.onopen = () => {
console.log('WebSocket Connected');
fetch(url + "/settings/logstation-name")
.then(response => response.json())
.then(data => {
setTitle(data.name)
document.title = title
});
};
rws.onmessage = (message) => {
console.log(message.data);
setLines([...lines, JSON.parse(message.data).text])
};
}

return <MainLayout name={title} lines={lines}/>
}


export default App;
13 changes: 13 additions & 0 deletions web/src/LogViewerComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { LogViewer } from '@patternfly/react-log-viewer';

const BasicLogViewer = (props) => {

return (
<React.Fragment>
<LogViewer hasLineNumbers={false} height={'100%'} width={'100%'} data={props.data} theme={'dark'} isTextWrapped={true}/>
</React.Fragment>
);
};

export default BasicLogViewer;

0 comments on commit ff45a28

Please sign in to comment.