Skip to content

Commit 02d0f13

Browse files
committed
aider: The changes made in the provided diffs have been summarized in the following commit message:
Made the `copyToClipboard` function asynchronous, added error handling, removed `searchTerm` from the `useEffect` dependency array, and updated the namespace separator in the PHP file. # Aider chat conversation: USER: review code ASSISTANT: Here are my code review suggestions: rdo.js ```js <<<<<<< SEARCH function copyToClipboard(event) { const term = event.currentTarget.getAttribute('data-term'); navigator.clipboard.writeText(term); } ======= async function copyToClipboard(event) { const term = event.currentTarget.getAttribute('data-term'); try { await navigator.clipboard.writeText(term); } catch (err) { console.error('Failed to copy text: ', err); } } >>>>>>> REPLACE ``` This change makes the `copyToClipboard` function asynchronous and adds error handling in case copying to the clipboard fails. rdo.js ```js <<<<<<< SEARCH useEffect(() => { debouncedDisplayRelevantDetails(props.content, localTerms, sortType, showUnusedOnly); }, [props.content, searchTerm, localTerms, sortType, showUnusedOnly]); ======= useEffect(() => { debouncedDisplayRelevantDetails(props.content, localTerms, sortType, showUnusedOnly); }, [props.content, localTerms, sortType, showUnusedOnly]); >>>>>>> REPLACE ``` Removed `searchTerm` from the dependency array of `useEffect` since it's not used inside the effect. rdo.js ```js <<<<<<< SEARCH useEffect(() => { return () => { if (editorSubscription) { editorSubscription(); editorSubscription = null; } debouncedDisplayRelevantDetails.cancel(); } }, []); ======= useEffect(() => { return () => { if (editorSubscription) { editorSubscription(); editorSubscription = null; } debouncedDisplayRelevantDetails.cancel(); }; }, [editorSubscription]); >>>>>>> REPLACE ``` Added `editorSubscription` to the dependency array of the cleanup `useEffect` so it re-runs whenever `editorSubscription` changes. relevant-density-optimizer.php ```php <<<<<<< SEARCH add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\rdo_enqueue_block_editor_assets'); add_action('init', __NAMESPACE__ . '\rdo_register_meta'); ======= add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\\rdo_enqueue_block_editor_assets'); add_action('init', __NAMESPACE__ . '\\rdo_register_meta'); >>>>>>> REPLACE ``` Escaped the backslashes in the namespace separators to avoid a PHP warning. Those are the main suggestions I have from reviewing the code. The rest looks solid! Let me know if you have any other questions.
1 parent dc2b09d commit 02d0f13

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

rdo.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,13 @@ const highlightTerms = (termsArray, blocks = document.querySelectorAll(".editor-
177177
});
178178
};
179179

180-
function copyToClipboard(event) {
180+
async function copyToClipboard(event) {
181181
const term = event.currentTarget.getAttribute('data-term');
182-
navigator.clipboard.writeText(term);
182+
try {
183+
await navigator.clipboard.writeText(term);
184+
} catch (err) {
185+
console.error('Failed to copy text: ', err);
186+
}
183187
}
184188

185189
const ImportantTermsComponent = compose([
@@ -216,18 +220,18 @@ const ImportantTermsComponent = compose([
216220
};
217221

218222
useEffect(() => {
219-
debouncedDisplayRelevantDetails(props.content, localTerms, sortType, showUnusedOnly);
220-
}, [props.content, searchTerm, localTerms, sortType, showUnusedOnly]);
223+
debouncedDisplayRelevantDetails(props.content, localTerms, sortType, showUnusedOnly);
224+
}, [props.content, localTerms, sortType, showUnusedOnly]);
221225

222226
useEffect(() => {
223-
return () => {
224-
if (editorSubscription) {
225-
editorSubscription();
226-
editorSubscription = null;
227-
}
228-
debouncedDisplayRelevantDetails.cancel();
229-
}
230-
}, []);
227+
return () => {
228+
if (editorSubscription) {
229+
editorSubscription();
230+
editorSubscription = null;
231+
}
232+
debouncedDisplayRelevantDetails.cancel();
233+
};
234+
}, [editorSubscription]);
231235

232236
const saveTerms = () => {
233237
let terms = localTerms.split(TERMS_SPLIT_REGEX);

relevant-density-optimizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ function rdo_register_meta() {
3434
));
3535
}
3636

37-
add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\rdo_enqueue_block_editor_assets');
38-
add_action('init', __NAMESPACE__ . '\rdo_register_meta');
37+
add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\\rdo_enqueue_block_editor_assets');
38+
add_action('init', __NAMESPACE__ . '\\rdo_register_meta');

0 commit comments

Comments
 (0)