-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04e77ce
commit 8788cb7
Showing
7 changed files
with
225 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Steam Trader</title> | ||
<link | ||
|
||
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" | ||
rel="stylesheet" | ||
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" | ||
|
@@ -18,6 +19,7 @@ | |
></script> | ||
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script> | ||
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script> | ||
<script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,57 @@ | ||
import React from 'react'; | ||
import React, { Component, useState, createRef } from 'react'; | ||
import io from 'socket.io-client'; | ||
import './logs.css'; | ||
|
||
export default function () { | ||
return <div>Logs</div>; | ||
interface LogsState { | ||
logs: JSX.Element[]; | ||
} | ||
|
||
export default class Logs extends Component<any, LogsState> { | ||
logger: React.RefObject<HTMLDivElement> = createRef(); | ||
socket = io('ws://localhost:1228'); | ||
|
||
constructor(props: any) { | ||
super(props); | ||
this.state = { logs: [] }; | ||
this.openSocket(); | ||
} | ||
|
||
private openSocket() { | ||
this.socket.on('log', (msg: any) => { | ||
this.setState({ logs: [...this.state.logs, createLog(msg)] }); | ||
}); | ||
} | ||
|
||
componentDidUpdate() { | ||
const logger = this.logger.current; | ||
logger && (logger.scrollTop = logger.scrollHeight); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div ref={this.logger} className="logger overflow-y-scroll"> | ||
{this.state.logs} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
function createLog({message, level, timestamp}: any) { | ||
return <div className={`log ${getColor(level)} border-bottom border-2`}> | ||
<span className="timestamp">{new Date(timestamp).toLocaleTimeString()}</span> | ||
{message} | ||
</div>; | ||
} | ||
|
||
function getColor(level: string) { | ||
switch(level) { | ||
case 'warn': | ||
return 'border-warning'; | ||
case 'info': | ||
return 'border-info'; | ||
case 'debug': | ||
return 'border-secondary'; | ||
default: | ||
return '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
div.logger { | ||
max-height: 50vh; | ||
overflow-y: scroll; | ||
overflow-wrap: break-word; | ||
} | ||
|
||
div.log { | ||
line-height: 25px; | ||
min-height: 25px; | ||
} | ||
|
||
div.log .timestamp { | ||
color: #666; | ||
padding-right: 20px; | ||
} |