-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api integration preview home page #380
Merged
arunshenoy99
merged 85 commits into
enhance/ai-onboarding
from
api-integration-preview-home-page
Jan 15, 2024
Merged
Changes from 76 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
2ce0717
top bar header changes for editor screen
4308945
sitegenheader changes moved to step
2ae3769
sitegenheader changes moved to step
749584c
step editor drop down wip
8fb7dc0
changes for live preview wip
ff1f10c
screen design previws wip
8640b3c
design previews. respinsiveness remaining
ea4c1a1
added overlay for previews
d0436d0
minor fix
a6cfed2
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
9e48d8d
PRESS2-1262
1bacc06
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
64ef752
PRESS-1262 | fixed CSS
0d556b2
PRESS-1262 | note
323b0ea
PRESS-1262 | hide wp admin bar
07057cf
Merge branch 'Integrate-APIs-to-AI-Onboarding' of https://github.com/…
f2fa785
PRESS-1262
7a751ec
PRESS2-1262 | fixed changes
d9209c0
PRESS2-1262 | removed comments
43213d0
mobile changes
adb9303
Merge branch 'enhance/aio-design-previews' of github.com:newfold-labs…
492f947
have to change header background to dynamic
515fac7
have to change header background to dynamic
012ffd6
mobile responsiveness
238ae54
PRESS-1262 | updated controller
488e3d4
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
4c87a36
PRESS-1262 | fixed overlay button
a44e0a8
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ae3168b
PRESS-1262 | comments removed
67251eb
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
ba544fb
PRESS-1237 | fixed version dropdown
1e0dca7
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
929434b
PRESS-1237 | fixed linting
1b64c3e
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
fbf2c97
PRESS2-1237 | reverted to textInput and fixed linting
472a6ce
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ed469ec
PRESS2-1262 | added animation
e7a91c5
PRESS2-1237 | changed classname logic for editor header
0078d0d
Merge branch 'enhance/fix-dark-mode' of github.com:newfold-labs/wp-mo…
e947b40
Merge branch 'enhance/ai-onboarding' of github.com:newfold-labs/wp-mo…
3b7bd29
PRESS2-1262 | regenrating card
882ffe0
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
8263c55
PRESS2-1262 | add regenerating screen
1171b2d
PRESS2-1262 |
a497959
PRESS2-1262 | added to store
f84602b
PRESS2-1262 | added designs
18a2ada
Merge branch 'enhance/aio-preview' of https://github.com/newfold-labs…
efd85d0
PRESS2-1262 | added verion number in dropdown
2e6bf66
PRESS2-1262 | favorite toggle
4afc518
PRESS2-1262 | added on the sitegen object in store
f147fd9
PRESS2-1262 | integration home page
7c57bd3
PRESS-1262 | added home pages call
3163b56
PRESS2-1262 | created generating site loaders
39698d5
PRESS2-1465 | updated according to changes in option table
81c0168
PRESS2-1465
fa8ff4a
PRESS2-1465 | added regenerate changes
8d05642
PRESS2-1465 | regenerated api endpoint
be980c8
PRESS2-1465
4071e8f
Revert "PRESS2-1465 | regenerated api endpoint"
e49b0fe
PRESS2-1465
1008e48
PRESS2-1465 | regenerate functionality
f69ba4d
Merge branch 'enhance/ai-onboarding' into api-integration-preview-hom…
ajayadav09 c052920
updated preview
ajayadav09 7cc1db1
PRESS2-1465 | fixed linting issues
ajayadav09 91acf81
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 500eacd
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 bb4a753
Fixing PR comments | removed bg image
ajayadav09 9ab19d6
Press2-1465 | fixing PR comments
ajayadav09 976d931
Press2-1465 | updated get options from Option
ajayadav09 246bae9
PRESS2-1465 | changed favourite logic
ajayadav09 a390f20
PRESS2-1465 | fixed Option with get_option
ajayadav09 ae0be8b
PRESS2-1465 | fixed php linting
ajayadav09 5b00cf3
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 f62be25
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 3006c7e
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
arunshenoy99 a3ad4ef
PRESS2-1465 | added check
ajayadav09 953149e
PRESS2-1465 | handled error responses
ajayadav09 0d347b0
PRESS2-1465 | changed skeleton
ajayadav09 4b72509
Press2-1465 | updated preview
ajayadav09 8520596
Merge branch 'enhance/ai-onboarding' of https://github.com/newfold-la…
ajayadav09 50ee515
Press2-1465 | hiding darkmode toggle from editor step
ajayadav09 0413114
Some Changes
officiallygod 75e89b9
Update index.js
officiallygod 09914b3
Update index.js
officiallygod 00afc88
Delete sitegen-ai-animation.45cdf3b3.gif
ajayadav09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
namespace NewfoldLabs\WP\Module\Onboarding\RestApi; | ||
|
||
use NewfoldLabs\WP\Module\Onboarding\Permissions; | ||
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen; | ||
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService; | ||
use NewfoldLabs\WP\Module\Onboarding\Data\Options; | ||
|
||
/** | ||
* Class SiteGenController | ||
|
@@ -49,6 +51,35 @@ public function register_routes() { | |
'args' => $this->sitegen_meta_args(), | ||
) | ||
); | ||
\register_rest_route( | ||
$this->namespace, | ||
$this->rest_base . '/get-homepages', | ||
array( | ||
'methods' => \WP_REST_Server::CREATABLE, | ||
'callback' => array( $this, 'get_homepages' ), | ||
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), | ||
'args' => $this->get_homepages_args(), | ||
) | ||
); | ||
\register_rest_route( | ||
$this->namespace, | ||
$this->rest_base . '/get-homepages-regenerate', | ||
array( | ||
'methods' => \WP_REST_Server::CREATABLE, | ||
'callback' => array( $this, 'get_regenerated_homepages' ), | ||
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), | ||
'args' => $this->get_homepages_regenerate_args(), | ||
) | ||
); | ||
\register_rest_route( | ||
$this->namespace, | ||
$this->rest_base . '/favourites', | ||
array( | ||
'methods' => \WP_REST_Server::CREATABLE, | ||
'callback' => array( $this, 'toggle_favourite_homepage' ), | ||
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -73,6 +104,53 @@ public function sitegen_meta_args() { | |
); | ||
} | ||
|
||
/** | ||
* Gets the arguments for the 'get-homepages' endpoint. | ||
* | ||
* @return array The array of arguments. | ||
*/ | ||
public function get_homepages_args() { | ||
return array( | ||
'site_description' => array( | ||
'required' => true, | ||
'validate_callback' => function ( $param ) { | ||
return is_string( $param ); | ||
}, | ||
'sanitize_callback' => 'sanitize_text_field', | ||
), | ||
'regenerate' => array( | ||
'required' => false, | ||
), | ||
// Add other parameters here as needed. | ||
); | ||
} | ||
|
||
/** | ||
* Gets the arguments for the 'get-homepages' endpoint. | ||
* | ||
* @return array The array of arguments. | ||
*/ | ||
public function get_homepages_regenerate_args() { | ||
return array( | ||
'site_description' => array( | ||
'required' => true, | ||
'validate_callback' => function ( $param ) { | ||
return is_string( $param ); | ||
}, | ||
'sanitize_callback' => 'sanitize_text_field', | ||
), | ||
'regenerate' => array( | ||
'required' => false, | ||
), | ||
'slug' => array( | ||
'required' => false, | ||
), | ||
'colorPalettes' => array( | ||
'required' => false, | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Gets all the valid Identifiers | ||
* | ||
|
@@ -105,4 +183,117 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) { | |
// TODO Implement the main function and do computations if required. | ||
return SiteGenService::instantiate_site_meta( $site_info, $identifier, $skip_cache ); | ||
} | ||
|
||
/** | ||
* Gets the preview homepages | ||
* | ||
* @param \WP_REST_Request $request parameter. | ||
* @return array | ||
*/ | ||
public function get_homepages( \WP_REST_Request $request ) { | ||
|
||
$site_description = $request->get_param( 'site_description' ); | ||
$regenerate = $request->get_param( 'regenerate' ); | ||
$site_info = array( 'site_info' => array( 'site_description' => $site_description ) ); | ||
|
||
// If the option exists and is not empty, return it. | ||
$existing_homepages = get_option( Options::get_option_name( 'sitegen_homepages' ), array() ); | ||
if ( ! empty( $existing_homepages ) && ! $regenerate ) { | ||
return new \WP_REST_Response( $existing_homepages, 200 ); | ||
} | ||
|
||
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'targetaudience', true ); | ||
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'contenttones', true ); | ||
|
||
if ( ! $target_audience || ! $content_style ) { | ||
return new \WP_Error( | ||
'nfd_onboarding_error', | ||
__( 'Required data is missing.', 'wp-module-onboarding' ), | ||
array( | ||
'status' => 400, | ||
) | ||
); | ||
} | ||
|
||
$processed_home_pages = SiteGenService::generate_homepages( | ||
$site_description, | ||
$content_style, | ||
$target_audience, | ||
$regenerate | ||
); | ||
|
||
if ( is_wp_error( $processed_home_pages ) ) { | ||
return $processed_home_pages; | ||
} | ||
|
||
return new \WP_REST_Response( $processed_home_pages, 200 ); | ||
} | ||
|
||
/** | ||
* Gets the regenerated preview homepages | ||
* | ||
* @param \WP_REST_Request $request parameter. | ||
* @return array | ||
*/ | ||
public function get_regenerated_homepages( \WP_REST_Request $request ) { | ||
$site_description = $request->get_param( 'site_description' ); | ||
$regenerate_slug = $request->get_param( 'slug' ); | ||
$regenerate_color_palattes = $request->get_param( 'colorPalettes' ); | ||
$is_favourite = $request->get_param( 'isFavourited' ); | ||
$site_info = array( 'site_info' => array( 'site_description' => $site_description ) ); | ||
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'targetaudience', true ); | ||
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'contenttones', true ); | ||
|
||
if ( ! $target_audience || ! $content_style ) { | ||
return new \WP_Error( | ||
'nfd_onboarding_error', | ||
__( 'Required data is missing.', 'wp-module-onboarding' ), | ||
array( | ||
'status' => 400, | ||
) | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
if ( $is_favourite ) { | ||
$result = SiteGenService::handle_favorite_regeneration( $regenerate_slug, $regenerate_color_palattes ); | ||
} else { | ||
$result = SiteGenService::handle_regular_regeneration( $site_description, $content_style, $target_audience ); | ||
} | ||
|
||
if ( null === $result ) { | ||
return new \WP_Error( | ||
'nfd_onboarding_error', | ||
__( 'Error processing request.', 'wp-module-onboarding' ), | ||
array( | ||
'status' => 500, | ||
) | ||
); | ||
} | ||
|
||
return new \WP_REST_Response( $result, 200 ); | ||
} | ||
|
||
/** | ||
* Updates favourite status | ||
* | ||
* @param \WP_REST_Request $request parameter. | ||
* @return array | ||
*/ | ||
public function toggle_favourite_homepage( \WP_REST_Request $request ) { | ||
$slug = $request->get_param( 'slug' ); | ||
|
||
$response = SiteGenService::toggle_favourite_homepage( $slug ); | ||
|
||
if ( is_wp_error( $response ) ) { | ||
$error_message = $response->get_error_message(); | ||
return new \WP_Error( | ||
'nfd_onboarding_error', | ||
__( 'Failed at updating Favourite status', 'wp-module-onboarding' ), | ||
array( | ||
'status' => 404, | ||
) | ||
); | ||
} | ||
return new \WP_REST_Response( $response, 200 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Slot } from '@wordpress/components'; | ||
import { Fragment, Suspense } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
import classNames from 'classnames'; | ||
|
||
import { store as nfdOnboardingStore } from '../../store'; | ||
import { | ||
|
@@ -9,18 +10,17 @@ import { | |
HEADER_START, | ||
HEADER_TOP, | ||
} from '../../../constants'; | ||
import classNames from 'classnames'; | ||
import { stepSiteGenEditor } from '../../steps/SiteGen/Editor/step'; | ||
|
||
const Header = () => { | ||
const { headers, headerActiveView, isHeaderEnabled, currentStep } = | ||
useSelect( ( select ) => { | ||
return { | ||
currentStep: select( nfdOnboardingStore ).getCurrentStep(), | ||
Comment on lines
17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can keep it in the same order i.e. var names and functions. |
||
headers: select( nfdOnboardingStore ).getHeaders(), | ||
headerActiveView: | ||
select( nfdOnboardingStore ).getHeaderActiveView(), | ||
isHeaderEnabled: select( nfdOnboardingStore ).isHeaderEnabled(), | ||
currentStep: select( nfdOnboardingStore ).getCurrentStep(), | ||
}; | ||
} ); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we add a code to send Error from our Service and catch it here, cause I believe here what if it gives an error from Press 3 API, that won't be null but still have an error and going forward will break things.