From 949f26912542611311afe4f8aa9079995fc7c478 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Mon, 16 Dec 2024 14:54:15 +0200 Subject: [PATCH] adds comments and refactor semrush request control --- .../js/src/redux/controls/SEMrushRequest.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/js/src/redux/controls/SEMrushRequest.js b/packages/js/src/redux/controls/SEMrushRequest.js index 0f43f9047c9..c2aae3c1e6b 100644 --- a/packages/js/src/redux/controls/SEMrushRequest.js +++ b/packages/js/src/redux/controls/SEMrushRequest.js @@ -2,23 +2,24 @@ import apiFetch from "@wordpress/api-fetch"; import { addQueryArgs } from "@wordpress/url"; /** - * Control for handling SEMrush related keyphrases request. + * Control for handling SEMrush related keyphrases request nd saved the country code to the database. * - * @param {Object} action The action object. + * @param {string} countryCode The country code to use. + * @param {string} keyphrase The keyphrase to use. * - * @returns {Promise} The API fetch promise. + * @returns {Promise} The API fetch promise, when resolved, + * contains a list of related keyphrses with their search volumne, trends in recent year, search intent, and difficulty index. */ -export const NEW_REQUEST = async( action ) => { - const { countryCode, keyphrase } = action; - - await apiFetch( { +export const NEW_REQUEST = async( { countryCode, keyphrase } ) => { + // Saves the country code in the database. + apiFetch( { path: "yoast/v1/semrush/country_code", method: "POST", // eslint-disable-next-line camelcase data: { country_code: countryCode }, } ); - const response = await apiFetch( { + return apiFetch( { path: addQueryArgs( "/yoast/v1/semrush/related_keyphrases", { @@ -28,6 +29,4 @@ export const NEW_REQUEST = async( action ) => { } ), } ); - - return response; };