Skip to content

Commit

Permalink
Merge pull request #66 from newfold-labs/release/2.2.2
Browse files Browse the repository at this point in the history
Changes for Release/2.2.2
  • Loading branch information
ajayadav09 authored Dec 5, 2024
2 parents b13d4e7 + 292d657 commit 9ea76ef
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '868ae9d5607045463515');
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'cbd602aa372baa7bb416');
2 changes: 1 addition & 1 deletion build/index.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions includes/HelpCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public function register_assets() {
\wp_enqueue_script( self::$slug );

\wp_enqueue_style(
'stylesheet',
self::$slug,
NFD_HELPCENTER_PLUGIN_URL . 'vendor/newfold-labs/wp-module-help-center/build/index.css',
array(),
'1',
$asset['version'],
'screen'
);

Expand Down
15 changes: 8 additions & 7 deletions src/components/Feedback.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState, useRef } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Analytics, InteractionAPIs } from '../utils';
import { Analytics, InteractionAPIs, LocalStorageUtils } from '../utils';

const Feedback = ( { postId, source } ) => {
const [ status, setStatus ] = useState( '' );
Expand Down Expand Up @@ -43,6 +43,11 @@ const Feedback = ( { postId, source } ) => {
}
}, [ status ] );

const handleFeedback = (feedback) => {
setStatus( feedback );
LocalStorageUtils.updateFeedbackStatus( postId );
}

return (
<div className="feedback-container">
{ /* Conditionally render the question and buttons */ }
Expand All @@ -59,17 +64,13 @@ const Feedback = ( { postId, source } ) => {
<div className="icon">
<button
ref={ yesButtonRef }
onClick={ () => {
setStatus( 'helpful' );
} }
onClick={ () => handleFeedback( 'helpful' ) }
className="feedback-button yes"
>
{ __( 'Yes', 'wp-module-help-center' ) }
</button>
<button
onClick={ () => {
setStatus( 'notHelpful' );
} }
onClick={ () => handleFeedback( 'notHelpful' ) }
ref={ noButtonRef }
className="feedback-button no"
>
Expand Down
18 changes: 14 additions & 4 deletions src/components/HelpCenter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useEffect, useState } from '@wordpress/element';
import { useEffect, useState, useRef } from '@wordpress/element';
import SearchResults from './SearchResults';
import { CapabilityAPI, LocalStorageUtils } from '../utils';
import HelpCenterIntro from './HelpCenterIntro';

const HelpCenter = ( props ) => {
const [ visible, setVisible ] = useState( false );
const [ helpEnabled, setHelpEnabled ] = useState( false );
const wrapper = useRef();
const introRef = useRef();

const getHelpStatus = async () => {
try {
Expand Down Expand Up @@ -38,9 +40,17 @@ const HelpCenter = ( props ) => {
}

return (
<div className="nfd-help-center" id="helpcenterResultsWrapper">
<HelpCenterIntro />
<SearchResults refresh={ props.refresh } />
<div
className="nfd-help-center"
id="helpcenterResultsWrapper"
ref={ wrapper }
>
<HelpCenterIntro introRef={ introRef } />
<SearchResults
wrapper={ wrapper }
introRef={ introRef }
{ ...props }
/>
</div>
);
};
Expand Down
26 changes: 12 additions & 14 deletions src/components/HelpCenterIntro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@ import { __ } from '@wordpress/i18n';
import { ReactComponent as AIStars } from '../icons/ai-stars.svg';
import { useRevealText, LocalStorageUtils } from '../utils';

const HelpCenterIntro = () => {
const HelpCenterIntro = ( { introRef } ) => {
const [ startReveal, setStartReveal ] = useState( false );

useEffect( () => {
// Get the stored results from localStorage using LocalStorageUtils
const storedResults = LocalStorageUtils.getResultInfo();

// Check if the length of the stored results is <= 0
if ( storedResults.length <= 0 ) {
// If true, enable reveal effect
setStartReveal( true );
} else {
// Always ensure startReveal is set, even if it's false
setStartReveal( false );
}
setStartReveal( LocalStorageUtils.getResultInfo().length <= 0 );
}, [] );

const introText = __(
'Hi! I’m your WordPress AI assistant. </br></br> Ask me how to do things in WordPress and I’ll provide step by step instructions.</br></br> I’m still learning so I don’t have all the answers just yet.',
'wp-module-help-center'
);

// const revealedIntro = useRevealText( introText, 50, startReveal );
const { displayedText: revealedIntro } = useRevealText(
introText || '',
50,
startReveal
);
return (
<div className="helpcenter-intro">
<div
className="helpcenter-intro"
ref={ introRef }
style={ {
visibility:
LocalStorageUtils.getResultInfo().length > 0
? 'hidden'
: 'visible',
} }
>
<div>
<AIStars />
</div>
Expand Down
11 changes: 5 additions & 6 deletions src/components/ResultContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const ResultContent = ( {
index,
isNewResult,
searchInput,
wrapper,
feedbackSubmitted,
} ) => {
const isNewEntry =
isNewResult && index === LocalStorageUtils.getResultInfo().length - 1;
Expand All @@ -35,12 +37,8 @@ export const ResultContent = ( {
const viewportHeight = window.innerHeight;
const minHeight = viewportHeight - 332;
responseRef.current.style.minHeight = `${ minHeight }px`;

const helpcenterResultsWrapper = document.getElementById(
'helpcenterResultsWrapper'
);
const scrollDistance = helpcenterResultsWrapper.scrollHeight;
helpcenterResultsWrapper.scrollBy( {
const scrollDistance = wrapper.current.scrollHeight;
wrapper.current.scrollBy( {
top: scrollDistance,
left: 0,
behavior: 'smooth',
Expand Down Expand Up @@ -115,6 +113,7 @@ export const ResultContent = ( {
function shouldShowFeedback() {
return (
! noResult &&
! feedbackSubmitted &&
showFeedbackSection &&
content &&
revealComplete &&
Expand Down
Loading

0 comments on commit 9ea76ef

Please sign in to comment.