@@ -16,7 +16,6 @@ import createPlotlyComponent from "react-plotly.js/factory";
1616import Plotly from "plotly.js/lib/core" ;
1717import { textChangeRangeIsUnchanged } from "typescript" ;
1818
19-
2019const Plot = createPlotlyComponent ( Plotly ) ;
2120
2221function formatDuration ( sec_num : number ) {
@@ -90,11 +89,15 @@ function formatBytes(b: number) {
9089 return b + "B" ;
9190}
9291
93- const SqliteStats : React . FC < { stats : SqliteStats } > = observer ( ( { stats } ) => {
92+ const SqliteStats : React . FC < {
93+ stats : SqliteStats ;
94+ lastUpdated : number ;
95+ } > = observer ( ( { stats, lastUpdated } ) => {
9496 return (
9597 < >
9698 Sqlite stats: fetched { formatBytes ( stats . totalFetchedBytes ) } in{ " " }
97- { stats . totalRequests } requests (DB size: { formatBytes ( stats . totalBytes ) } )
99+ { stats . totalRequests } requests (DB size: { formatBytes ( stats . totalBytes ) } ,
100+ updated: { new Date ( lastUpdated * 1000 ) . toLocaleDateString ( ) } )
98101 </ >
99102 ) ;
100103} ) ;
@@ -107,7 +110,7 @@ const VideoMetaDisplay: React.FC<{ video: SponsorInfo }> = observer(
107110 < img
108111 src = { video . meta . maxresdefault_thumbnail }
109112 width = { 200 }
110- style = { { float : "left" } }
113+ style = { { float : "left" , margin : "0.5em" } }
111114 > </ img >
112115 < h4 > { video . meta . title } </ h4 >
113116 </ a >
@@ -139,6 +142,8 @@ export class UI extends React.Component {
139142 @observable
140143 stats : SqliteStats | null = null ;
141144 @observable
145+ dbConfig : { lastUpdated : number } | null = null ;
146+ @observable
142147 focussedVideo : SponsorInfo | null = null ;
143148 @observable searchInput : string = "" ;
144149
@@ -147,7 +152,7 @@ export class UI extends React.Component {
147152 this . init ( ) ;
148153 makeObservable ( this ) ;
149154 }
150- interval : number = 0 ;
155+ interval : any = 0 ;
151156 componentDidMount ( ) {
152157 this . interval = setInterval ( async ( ) => {
153158 this . stats = ( await this . worker ?. getStats ( ) ) || null ;
@@ -157,10 +162,11 @@ export class UI extends React.Component {
157162 clearInterval ( this . interval ) ;
158163 }
159164 async init ( ) {
160- this . initState = "connectingToDb" ;
165+ this . initState = "connectingToDb" ;
161166 const res = await createDbWorker ( ) ;
162167 this . db = res . db ;
163168 this . worker = res . worker ;
169+ this . dbConfig = res . config ;
164170 const initialAuthor = new URLSearchParams ( location . search ) . get ( "uploader" ) ;
165171 if ( initialAuthor ) this . setAuthor ( initialAuthor ) ;
166172 this . initState = "" ;
@@ -199,7 +205,7 @@ export class UI extends React.Component {
199205 setFocussed = ( e : SponsorInfo ) => ( this . focussedVideo = e ) ;
200206
201207 render ( ) {
202- if ( this . initState ) return < div > { this . initState } </ div > ;
208+ if ( this . initState ) return < div > { this . initState } </ div > ;
203209 return (
204210 < div >
205211 < div >
@@ -211,7 +217,7 @@ export class UI extends React.Component {
211217 loadOptions = { this . authorsSearchDebounce }
212218 getOptionLabel = { ( e ) => e . name }
213219 getOptionValue = { ( e ) => e . name }
214- onChange = { ( e ) => this . setAuthor ( e . name ) }
220+ onChange = { ( e ) => e && this . setAuthor ( e . name ) }
215221 />
216222 </ div >
217223 { this . data . state === "noinput" ? (
@@ -227,9 +233,19 @@ export class UI extends React.Component {
227233 < SponsorPlot data = { this . data . segs } onHover = { this . setFocussed } />
228234 </ div >
229235 ) }
230- { this . focussedVideo && < VideoMetaDisplay video = { this . focussedVideo } /> }
236+ { this . focussedVideo && < > Selected video: < VideoMetaDisplay video = { this . focussedVideo } /> < /> }
231237 < footer style = { { marginTop : "5em" , color : "gray" } } >
232- { this . stats ? < SqliteStats stats = { this . stats } /> : "" } { " " }
238+ < div > { this . stats ? (
239+ < SqliteStats
240+ stats = { this . stats }
241+ lastUpdated = { this . dbConfig . lastUpdated }
242+ />
243+ ) : (
244+ ""
245+ ) } { " " }
246+ </ div >
247+ < div > Source Code: < a href = "https://github.com/phiresky/youtube-sponsorship-stats/" > https://github.com/phiresky/youtube-sponsorship-stats/</ a > </ div >
248+
233249 </ footer >
234250 </ div >
235251 ) ;
0 commit comments