| 1 |
import apiFetch from '@wordpress/api-fetch'; |
| 2 |
import { useEffect } from '@wordpress/element'; |
| 3 |
|
| 4 |
export const useLockPost = ({ postId, enabled }) => { |
| 5 |
useEffect(() => { |
| 6 |
if (!postId || !enabled) return; |
| 7 |
let timeoutId; |
| 8 |
const lockPost = async () => { |
| 9 |
await apiFetch({ |
| 10 |
path: '/extendify/v1/agent/lock-post', |
| 11 |
method: 'POST', |
| 12 |
data: { postId }, |
| 13 |
}).catch(() => undefined); |
| 14 |
// Send lock post signal every 2 minutes (must be under WP's 150s lock expiry) |
| 15 |
timeoutId = setTimeout(lockPost, 2 * 60 * 1000); |
| 16 |
}; |
| 17 |
lockPost(); |
| 18 |
return () => clearTimeout(timeoutId); |
| 19 |
}, [postId, enabled]); |
| 20 |
}; |
| 21 |
|