Skip to content

Commit

Permalink
Get data from Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Nov 24, 2023
1 parent e482a63 commit e77dc31
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
18 changes: 18 additions & 0 deletions includes/RestApi/SiteGenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class SiteGenController {
* @return void
*/
public function register_routes() {
\register_rest_route(
$this->namespace,
$this->rest_base . '/get-identifiers',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_valid_identifiers' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/generate',
Expand Down Expand Up @@ -64,6 +73,15 @@ public function sitegen_meta_args() {
);
}

/**
* Gets all the valid Identifiers
*
* @return array
*/
public function get_valid_identifiers() {
return array_keys( array_filter( SiteGenService::get_identifiers() ) );
}

/**
* Generate Sitegen meta data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import ToggleDarkMode from '../../ToggleDarkMode';
import { ThemeProvider } from '../../ThemeContextProvider';
import { store as nfdOnboardingStore } from '../../../store';
import { setFlow } from '../../../utils/api/flow';
import { generateSiteGenMeta } from '../../../utils/api/siteGen';
import {
generateSiteGenMeta,
getSiteGenIdentifiers,
} from '../../../utils/api/siteGen';

// Wrapping the NewfoldInterfaceSkeleton with the HOC to make theme available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
Expand Down Expand Up @@ -39,7 +42,7 @@ const SiteGen = () => {
}
}

function generateSiteGenData() {
async function generateSiteGenData() {
// Start the API Requests when the loader is shown.
if (
! (
Expand All @@ -58,16 +61,8 @@ const SiteGen = () => {
return;
}

let identifiers = [
'siteclassification',
'targetaudience',
'contenttones',
'contentstructure',
'colorpalette',
'sitemap',
'pluginrecommendation',
'fontpair',
];
let identifiers = await getSiteGenIdentifiers();
identifiers = identifiers.body;

const midIndex = Math.floor( identifiers.length / 2 );
if ( location.pathname.includes( 'experience' ) ) {
Expand Down
8 changes: 8 additions & 0 deletions src/OnboardingSPA/utils/api/siteGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import apiFetch from '@wordpress/api-fetch';
import { resolve } from './resolve.js';
import { onboardingRestURL } from './common';

export async function getSiteGenIdentifiers() {
return await resolve(
apiFetch( {
url: onboardingRestURL( 'sitegen/get-identifiers' ),
} ).then()
);
}

export async function generateSiteGenMeta(
siteInfo,
identifier,
Expand Down

0 comments on commit e77dc31

Please sign in to comment.