| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { Button } from '@wordpress/components'; |
| 5 |
import { WPElement } from '@wordpress/element'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
/** |
| 9 |
* Internal dependencies. |
| 10 |
*/ |
| 11 |
import { useSync } from '../../sync'; |
| 12 |
import { useSyncSettings } from '../provider'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Sync controls component. |
| 16 |
* |
| 17 |
* @returns {WPElement} Component. |
| 18 |
*/ |
| 19 |
export default () => { |
| 20 |
const { isPaused, isSyncing, logMessage, pauseSync, resumeSync, stopSync } = useSync(); |
| 21 |
|
| 22 |
const { args } = useSyncSettings(); |
| 23 |
|
| 24 |
/** |
| 25 |
* Handle clicking pause button. |
| 26 |
* |
| 27 |
* @returns {void} |
| 28 |
*/ |
| 29 |
const onPause = () => { |
| 30 |
pauseSync(); |
| 31 |
logMessage(__('Pausing sync…', 'elasticpress'), 'info'); |
| 32 |
}; |
| 33 |
|
| 34 |
/** |
| 35 |
* Handle clicking play button. |
| 36 |
* |
| 37 |
* @returns {void} |
| 38 |
*/ |
| 39 |
const onResume = () => { |
| 40 |
resumeSync(args); |
| 41 |
logMessage(__('Resuming sync…', 'elasticpress'), 'info'); |
| 42 |
}; |
| 43 |
|
| 44 |
/** |
| 45 |
* Handle clicking stop button. |
| 46 |
* |
| 47 |
* @returns {void} |
| 48 |
*/ |
| 49 |
const onStop = () => { |
| 50 |
stopSync(); |
| 51 |
logMessage(__('Sync stopped', 'elasticpress'), 'info'); |
| 52 |
}; |
| 53 |
|
| 54 |
/** |
| 55 |
* Render. |
| 56 |
*/ |
| 57 |
return ( |
| 58 |
<div className="ep-sync-controls"> |
| 59 |
{isSyncing ? ( |
| 60 |
<> |
| 61 |
<Button onClick={onStop} variant="primary"> |
| 62 |
{__('Stop sync', 'elasticpress')} |
| 63 |
</Button> |
| 64 |
{isPaused ? ( |
| 65 |
<Button onClick={onResume} variant="secondary"> |
| 66 |
{__('Resume sync', 'elasticpress')} |
| 67 |
</Button> |
| 68 |
) : ( |
| 69 |
<Button onClick={onPause} variant="secondary"> |
| 70 |
{__('Pause sync', 'elasticpress')} |
| 71 |
</Button> |
| 72 |
)} |
| 73 |
</> |
| 74 |
) : ( |
| 75 |
<Button variant="primary" type="submit"> |
| 76 |
{__('Start sync', 'elasticpress')} |
| 77 |
</Button> |
| 78 |
)} |
| 79 |
<Button |
| 80 |
href="https://elasticpress.zendesk.com/hc/en-us/articles/5205632443533" |
| 81 |
target="_blank" |
| 82 |
variant="link" |
| 83 |
> |
| 84 |
{__('Learn more about Sync', 'elasticpress')} |
| 85 |
</Button> |
| 86 |
</div> |
| 87 |
); |
| 88 |
}; |
| 89 |
|