| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { escapeHTML } from '@wordpress/escape-html'; |
| 3 |
import { formatFileSize } from '../../utils'; |
| 4 |
|
| 5 |
const notOptimizedTemplate = () => { |
| 6 |
return ` |
| 7 |
<p class="image-optimization-control__property"> |
| 8 |
${ __( 'Status', 'image-optimizer' ) }: |
| 9 |
|
| 10 |
<span class="image-optimization-control__property-value"> |
| 11 |
${ __( 'Not optimized', 'image-optimizer' ) } |
| 12 |
</span> |
| 13 |
</p> |
| 14 |
|
| 15 |
<div class="image-optimization-control__action-button-wrapper"> |
| 16 |
<button type="button" |
| 17 |
class="button button-primary image-optimization-control__button image-optimization-control__button--optimize"> |
| 18 |
${ __( 'Optimize now', 'image-optimizer' ) } |
| 19 |
</button> |
| 20 |
</div> |
| 21 |
`; |
| 22 |
}; |
| 23 |
|
| 24 |
const loadingTemplate = () => { |
| 25 |
return ` |
| 26 |
<p class="image-optimization-control__property"> |
| 27 |
${ __( 'Status', 'image-optimizer' ) }: |
| 28 |
|
| 29 |
<span class="image-optimization-control__property-value"> |
| 30 |
${ __( 'In Progress', 'image-optimizer' ) } |
| 31 |
</span> |
| 32 |
</p> |
| 33 |
|
| 34 |
<div class="image-optimization-control__action-spinner-wrapper"> |
| 35 |
<span class="spinner is-active"></span> |
| 36 |
</div> |
| 37 |
`; |
| 38 |
}; |
| 39 |
|
| 40 |
const errorTemplate = ( message ) => { |
| 41 |
return ` |
| 42 |
<p class="image-optimization-control__property"> |
| 43 |
${ __( 'Status', 'image-optimizer' ) }: |
| 44 |
|
| 45 |
<span class="image-optimization-control__property-value"> |
| 46 |
${ __( 'Error', 'image-optimizer' ) } |
| 47 |
</span> |
| 48 |
</p> |
| 49 |
|
| 50 |
<p class="image-optimization-control__property"> |
| 51 |
${ __( 'Reason', 'image-optimizer' ) }: |
| 52 |
|
| 53 |
<span class="image-optimization-control__property-value"> |
| 54 |
${ escapeHTML( message ) } |
| 55 |
</span> |
| 56 |
</p> |
| 57 |
|
| 58 |
<div class="image-optimization-control__action-button-wrapper"> |
| 59 |
<button class="button button-secondary button-large button-link-delete image-optimization-control__button image-optimization-control__button--try-again" |
| 60 |
type="button"> |
| 61 |
${ __( 'Try again', 'image-optimizer' ) } |
| 62 |
</button> |
| 63 |
</div> |
| 64 |
`; |
| 65 |
}; |
| 66 |
|
| 67 |
const successTemplate = ( data ) => { |
| 68 |
const absoluteValue = formatFileSize( data?.saved?.absolute, 1 ); |
| 69 |
|
| 70 |
return ` |
| 71 |
<p class="image-optimization-control__property"> |
| 72 |
${ __( 'Status', 'image-optimizer' ) }: |
| 73 |
|
| 74 |
<span class="image-optimization-control__property-value"> |
| 75 |
${ __( 'Optimized', 'image-optimizer' ) } |
| 76 |
</span> |
| 77 |
</p> |
| 78 |
|
| 79 |
<p class="image-optimization-control__property"> |
| 80 |
${ __( 'Image sizes optimized', 'image-optimizer' ) }: |
| 81 |
|
| 82 |
<span class="image-optimization-control__property-value"> |
| 83 |
${ data?.sizesOptimized } |
| 84 |
</span> |
| 85 |
</p> |
| 86 |
|
| 87 |
<p class="image-optimization-control__property"> |
| 88 |
${ __( 'Overall saving', 'image-optimizer' ) }: |
| 89 |
|
| 90 |
<span class="image-optimization-control__property-value"> |
| 91 |
${ data?.saved?.relative }% (${ absoluteValue }) |
| 92 |
</span> |
| 93 |
</p> |
| 94 |
|
| 95 |
${ data?.canBeRestored ? ` |
| 96 |
<div class="image-optimization-control__action-button-wrapper"> |
| 97 |
<button class="button button-link image-optimization-control__button image-optimization-control__button--restore-original" |
| 98 |
type="button"> |
| 99 |
${ __( 'Restore original', 'image-optimizer' ) } |
| 100 |
|
| 101 |
<button class="button button-link image-optimization-control__button image-optimization-control__button--reoptimize" |
| 102 |
type="button"> |
| 103 |
${ __( 'Reoptimize', 'image-optimizer' ) } |
| 104 |
</button> |
| 105 |
</div> |
| 106 |
` : '' } |
| 107 |
`; |
| 108 |
}; |
| 109 |
|
| 110 |
const metaBoxTemplates = Object.freeze( { |
| 111 |
notOptimizedTemplate, |
| 112 |
loadingTemplate, |
| 113 |
errorTemplate, |
| 114 |
successTemplate, |
| 115 |
} ); |
| 116 |
|
| 117 |
export default metaBoxTemplates; |
| 118 |
|