11import PropTypes from 'prop-types' ;
2- import React , { useCallback } from 'react' ;
3- import { checkResponse , fetchWithTimeout } from '../js/utils' ;
2+ import React from 'react' ;
43
54/**
65 * Display an error message depending on props
76 */
8- const ErrorMessage = ( { code, url, timestamp, conf, errorHandledCallback } ) => {
9-
7+ const ErrorMessage = ( { code, url, timestamp } ) => {
108 let msg = 'We are sorry but there is a problem comparing these captures. Please try two different ones.' ;
119 let simhash = false ;
1210 let year = timestamp ? timestamp . substring ( 0 , 4 ) : '' ;
1311
14- const calculateSimhash = useCallback ( ( ) => {
15- const targetUrl = `${ conf . waybackDiscoverDiff } /calculate-simhash?url=${ encodeURIComponent ( url ) } &year=${ timestamp . substring ( 0 , 4 ) } ` ;
16- fetchWithTimeout ( targetUrl ) . then ( checkResponse )
17- . then ( ( ) => { setTimeout ( function ( ) { window . location . reload ( true ) ; } , 10000 ) ; } )
18- . catch ( error => { errorHandledCallback ( error . message ) ; } ) ;
19- } , [ conf , url , timestamp ] ) ;
20-
2112 switch ( code ) {
2213 case '404' :
2314 msg = `The Wayback Machine has not archived ${ url } .` ;
24- simhash = false ;
2515 break ;
2616 case '422' :
2717 // https://github.com/edgi-govdata-archiving/web-monitoring-diff/blob/be748a7f0bbdd4251f680e22d3e433d1be93f858/web_monitoring_diff/server/server.py#L568
2818 msg = `The captures of ${ url } cannot be compared because we support only HTML comparison.` ;
29- simhash = false ;
3019 break ;
3120 case 'CAPTURE_NOT_FOUND' :
3221 msg = `There are no data available for ${ url } at ${ timestamp } .` ;
@@ -38,39 +27,40 @@ const ErrorMessage = ({ code, url, timestamp, conf, errorHandledCallback }) => {
3827 break ;
3928 case 'NO_CAPTURES' :
4029 msg = `The Wayback Machine has not archived ${ url } for year ${ year } .` ;
41- simhash = false ;
4230 break ;
4331 case 'NO_DIFFERENT_CAPTURES' :
4432 msg = `There aren't any different captures for ${ url } for year ${ year } to display their similarity.` ;
45- simhash = false ;
4633 break ;
4734 // Occurs when AJAX fetch for CDX is canceled.
4835 case '_this4.errorHandled is not a function' : // Chrome
4936 case 'NetworkError when attempting to fetch resource.' : // FF
5037 case 'Load failed' : // Safari
5138 msg = `The capture of ${ url } at ${ timestamp } cannot be used for comparisons. Its possible it is a redirect.` ;
52- simhash = false ;
5339 break ;
5440 }
5541
42+ const changesUrl = `/web/changes/${ url } ` ;
43+
5644 return (
5745 < >
5846 < div className = 'alert alert-warning' role = 'alert' > { msg } </ div >
59- { simhash &&
60- < button className = "btn btn-sm" id = "calcButton"
61- onClick = { calculateSimhash } > Calculate now</ button >
62- }
63- < button className = "btn btn-sm" onClick = { ( ) => window . history . back ( ) } > « Go back</ button >
47+ < div className = "btn-group" >
48+ < button className = "btn btn-sm" onClick = { ( ) => window . history . back ( ) } > « Go back</ button >
49+ { simhash &&
50+ < >
51+ < span > </ span >
52+ < a href = { changesUrl } className = "btn btn-default btn-sm" id = "calcButton" > Visit Wayback Changes to calculate now</ a >
53+ </ >
54+ }
55+ </ div >
6456 </ >
6557 ) ;
6658} ;
6759
6860ErrorMessage . propTypes = {
6961 code : PropTypes . string ,
7062 url : PropTypes . string ,
71- timestamp : PropTypes . string ,
72- conf : PropTypes . object ,
73- errorHandledCallback : PropTypes . func
63+ timestamp : PropTypes . string
7464} ;
7565
7666export default ErrorMessage ;
0 commit comments