ScoreReanalyzing.js
3 years ago
notOptimized.js
3 years ago
optimized.js
3 years ago
optimizing.js
3 years ago
score.js
3 years ago
set_scoreData.js
3 years ago
optimized.js
90 lines
| 1 | import {Score} from "./score"; |
| 2 | import {useEffect,useState} from "react"; |
| 3 | import {set_scoreData} from "./set_scoreData"; |
| 4 | import {ScoreReanalyzing} from "./ScoreReanalyzing"; |
| 5 | import {Optimizing} from "./optimizing"; |
| 6 | const { __ } = wp.i18n; |
| 7 | |
| 8 | export const Optimized = ({metas, post_id}) => { |
| 9 | let score_data = set_scoreData( {post_id, metas} ); |
| 10 | let scoreReanalyzingValues = ScoreReanalyzing( {post_id, score_data} ); |
| 11 | useEffect(() => { |
| 12 | const elements = document.getElementsByClassName('two-score-circle'); |
| 13 | for (let i = 0; i < elements.length; i++) { |
| 14 | two_draw_score_circle(elements[i]); |
| 15 | } |
| 16 | }, [score_data]); |
| 17 | const [isLoading, setIsLoading] = useState(false); |
| 18 | const optimize = (post_id) => { |
| 19 | setIsLoading(true); |
| 20 | fetch(two_speed.ajax_url + '?action=two_optimize_page&post_id=' + post_id + '&nonce=' + two_speed.nonce + '&initiator=gutenberg') |
| 21 | .then(_res => { |
| 22 | }); |
| 23 | } |
| 24 | let date = 0; |
| 25 | if ( score_data && score_data['current_score'] ) { |
| 26 | if( (post_id in two_speed.critical_pages) && two_speed.critical_pages[post_id]['critical_date'] ) { |
| 27 | date = two_speed.critical_pages[post_id]['critical_date']; |
| 28 | } else if( score_data['current_score']['date'] ) { |
| 29 | date = Date.parse(score_data['current_score']['date']); |
| 30 | } |
| 31 | } |
| 32 | let modified_date='',re_optimize = false; |
| 33 | modified_date = Date.parse(wp.data.select('core/editor').getEditedPostAttribute('modified') + 'Z')/1000; |
| 34 | if ( modified_date > date && date != 0 ) { |
| 35 | re_optimize = true; |
| 36 | } |
| 37 | |
| 38 | let re_opt_button = <div className="two-score-container-reoptimize"> |
| 39 | <a onClick={() => optimize(post_id)} |
| 40 | data-initiator="gutenberg" |
| 41 | className="two-button-green ">{__('Re-optimize', 'tenweb-speed-optimizer')}</a> |
| 42 | </div>; |
| 43 | if ( scoreReanalyzingValues.reanalyzingStatus ) { |
| 44 | re_opt_button = <div className="two-score-container-reoptimize"> |
| 45 | <a href='#' |
| 46 | className="two-button-green two-deactivated-button">{__('Re-optimize', 'tenweb-speed-optimizer')}</a> |
| 47 | </div>; |
| 48 | } |
| 49 | const title = wp.data.select("core/editor").getEditedPostAttribute( 'title' ); |
| 50 | |
| 51 | if ( isLoading ) { |
| 52 | let optimizingTitle = 'Re-optimizing...'; |
| 53 | return <Optimizing title={optimizingTitle} />; |
| 54 | } else { |
| 55 | return ( |
| 56 | <div className="two-score-section two-score-section-gutenberg"> |
| 57 | <p className="two-gutenberg-container-title"> |
| 58 | <span><b>{title}</b></span>{__(' page is successfully optimized', 'tenweb-speed-optimizer')}</p> |
| 59 | <div className="two-score-container-both"> |
| 60 | <div className="two-score-container-old"> |
| 61 | <div className="two-score-header">{__('Before optimization', 'tenweb-speed-optimizer')}</div> |
| 62 | <div className={"two-old-scores " + scoreReanalyzingValues.no_old_scores}> |
| 63 | <Score score={ score_data && score_data.previous_score && score_data.previous_score.mobile_score} |
| 64 | tti={score_data && score_data.previous_score && score_data.previous_score.mobile_tti} |
| 65 | device='Mobile'/> |
| 66 | <Score score={score_data && score_data.previous_score && score_data.previous_score.desktop_score} |
| 67 | tti={score_data && score_data.previous_score && score_data.previous_score.desktop_tti} |
| 68 | device='Desktop'/> |
| 69 | {scoreReanalyzingValues.score_check_link_before} |
| 70 | </div> |
| 71 | </div> |
| 72 | <div className="two-score-container-new"> |
| 73 | <div className="two-score-header">{__('After optimization', 'tenweb-speed-optimizer')}</div> |
| 74 | <div className={"two-new-scores " + scoreReanalyzingValues.no_new_scores}> |
| 75 | <Score score={score_data && score_data.current_score && score_data.current_score.mobile_score} |
| 76 | tti={score_data && score_data.current_score && score_data.current_score.mobile_tti} |
| 77 | device='Mobile'/> |
| 78 | <Score score={score_data && score_data.current_score && score_data.current_score.desktop_score} |
| 79 | tti={score_data && score_data.current_score && score_data.current_score.desktop_tti} |
| 80 | device='Desktop'/> |
| 81 | {scoreReanalyzingValues.score_check_link_after} |
| 82 | </div> |
| 83 | </div> |
| 84 | </div> |
| 85 | {scoreReanalyzingValues.score_check_button} |
| 86 | {re_optimize && re_opt_button} |
| 87 | </div> |
| 88 | ); |
| 89 | } |
| 90 | } |