@@ -4,41 +4,48 @@ import ReactScrolla from 'react-scrolla';
44import { LogProvider } from './Providers/LogProvider.js' ;
55import { LogTable } from './Components/LogTable.js' ;
66import { ToggleEntry } from './Components/ToggleEntry.js' ;
7- import { App as AppContainer , SideBar , Content } from 'oc-react-components' ;
7+ import { LogUploader } from './Components/LogUploader.js' ;
8+ import { App as AppContainer , Entry , SideBar , Content , Separator } from 'oc-react-components' ;
89
910import { LogSearch } from './Search.js' ;
11+ import { LogFile } from './Providers/LogFile.js'
1012
1113import styles from '../css/app.css' ;
1214
1315export class App extends Component {
1416 state = {
1517 'entries' : [ ] ,
1618 'loading' : false ,
17- 'levels' : [ false , false , false , false , false ]
19+ 'levels' : [ false , false , false , false , false ] ,
20+ provider : null
1821 } ;
1922
2023 constructor ( ) {
2124 super ( ) ;
2225 this . logProvider = new LogProvider ( 50 ) ;
2326 this . logProvider . on ( 'entries' , entries => {
24- this . setState ( { entries} ) ;
27+ if ( this . state . provider === this . logProvider ) {
28+ this . setState ( { entries} ) ;
29+ }
2530 } ) ;
2631 OCA . Search . logreader = new LogSearch ( this . logProvider ) ;
2732 this . saveLevels = _ . debounce ( this . logProvider . setLevels , 100 ) ;
2833 }
2934
30- async componentDidMount ( ) {
35+ async componentDidMount ( ) {
3136 const levels = await this . logProvider . getLevels ( ) ;
32- this . setState ( { levels} ) ;
37+ this . setState ( { levels, provider : this . logProvider } ) ;
3338 this . logProvider . load ( ) ;
3439 }
3540
36- fetchNextPage = async ( ) => {
37- this . setState ( { loading : true } ) ;
38- this . logProvider . limit += 25 ;
39- await this . logProvider . load ( ) ;
40- this . setState ( { loading : false } ) ;
41- } ;
41+ fetchNextPage = _ . throttle ( async ( ) => {
42+ if ( this . state . provider . hasMore ) {
43+ this . setState ( { loading : true } ) ;
44+ this . state . provider . limit += 25 ;
45+ await this . state . provider . load ( ) ;
46+ this . setState ( { loading : false } ) ;
47+ }
48+ } , 100 ) ;
4249
4350 setLevel ( level , newState ) {
4451 let levels = this . state . levels ;
@@ -53,6 +60,17 @@ export class App extends Component {
5360 this . saveLevels ( levels ) ;
5461 }
5562
63+ onLogFile = ( content ) => {
64+ const logFile = new LogFile ( content ) ;
65+ logFile . on ( 'entries' , entries => {
66+ if ( this . state . provider === logFile ) {
67+ this . setState ( { entries} ) ;
68+ }
69+ } ) ;
70+ this . setState ( { provider : logFile , entries : [ ] } ) ;
71+ logFile . load ( ) ;
72+ } ;
73+
5674 render ( ) {
5775 let entries = this . state . entries . filter ( entry => {
5876 return this . state . levels [ entry . level ] ;
@@ -70,6 +88,8 @@ export class App extends Component {
7088 return (
7189 < AppContainer appId = "logreader" >
7290 < SideBar >
91+ < Entry > < LogUploader onLogFile = { this . onLogFile } /> </ Entry >
92+ < Separator />
7393 { filters }
7494 </ SideBar >
7595
0 commit comments