HEX
Server: LiteSpeed
System: Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: swifizcd (1555)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/swifizcd/shopup.com.ng/wp-content/plugins/extendify/src/Agent/hooks/useLockPost.js
import apiFetch from '@wordpress/api-fetch';
import { useEffect } from '@wordpress/element';

export const useLockPost = ({ postId, enabled }) => {
	useEffect(() => {
		if (!postId || !enabled) return;
		let timeoutId;
		const lockPost = async () => {
			await apiFetch({
				path: '/extendify/v1/agent/lock-post',
				method: 'POST',
				data: { postId },
			}).catch(() => undefined);
			// Send lock post signal every 2 minutes (must be under WP's 150s lock expiry)
			timeoutId = setTimeout(lockPost, 2 * 60 * 1000);
		};
		lockPost();
		return () => clearTimeout(timeoutId);
	}, [postId, enabled]);
};