Skip to content

Commit

Permalink
AI Assistant: Fix flickering when adding word to Breve dictionary (#3…
Browse files Browse the repository at this point in the history
…9087)

* reload the highlights without using the loading flag

* changelog
  • Loading branch information
dhasilva authored Aug 27, 2024
1 parent 9a9838f commit 1673ba1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Assistant: Fix flickering when adding word to Breve dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const addTextToDictionary = (
// Recompute the spell checker on the next call
delete spellCheckers[ language ];

reloadDictionary( SPELLING_MISTAKES.name );
reloadDictionary();

debug( 'Added text to the dictionary', text );
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ export function invalidateSingleSuggestion( feature: string, blockId: string, id
};
}

export function reloadDictionary( feature: string ) {
return ( { dispatch } ) => {
dispatch( setDictionaryLoading( feature, true ) );

setTimeout( () => {
dispatch( setDictionaryLoading( feature, false ) );
}, 100 );
export function reloadDictionary() {
return {
type: 'RELOAD_DICTIONARY',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export function configuration(
loading,
};
}

case 'RELOAD_DICTIONARY': {
return {
...state,
reload: ! state.reload,
};
}
}

return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export function getDisabledFeatures( state: BreveState ) {
return state.configuration?.disabled;
}

export function getReloadFlag( state: BreveState ) {
return state.configuration?.reload;
}

// Suggestions

export function getBlockMd5( state: BreveState, blockId: string ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type BreveState = {
enabled?: boolean;
disabled?: Array< string >;
loading?: Array< string >;
reload?: boolean;
};
suggestions?: {
[ key: string ]: {
Expand Down Expand Up @@ -67,6 +68,7 @@ export type BreveSelect = {
suggestion: string;
};
getIgnoredSuggestions: ( { blockId }: { blockId: string } ) => Array< string >;
getReloadFlag: () => boolean;
};

export type BreveDispatch = {
Expand All @@ -78,7 +80,7 @@ export type BreveDispatch = {
setDictionaryLoading( feature: string, loading: boolean ): void;
invalidateSuggestions: ( blockId: string ) => void;
invalidateSingleSuggestion: ( feature: string, blockId: string, id: string ) => void;
reloadDictionary: ( feature: string ) => void;
reloadDictionary: () => void;
ignoreSuggestion: ( blockId: string, id: string ) => void;
setBlockMd5: ( blockId: string, md5: string ) => void;
setSuggestions: ( suggestions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function registerBreveHighlight( feature: BreveFeature ) {
isFeatureEnabled,
isProofreadEnabled,
isFeatureDictionaryLoading,
getReloadFlag,
} = select( 'jetpack/ai-breve' ) as BreveSelect;

const { getAiAssistantFeature } = select( 'wordpress-com/plans' );
Expand All @@ -60,6 +61,7 @@ export function registerBreveHighlight( feature: BreveFeature ) {
isFeatureEnabled: isFeatureEnabled( config.name ),
ignored: getIgnoredSuggestions( { blockId: blockClientId } ),
isFeatureDictionaryLoading: isFeatureDictionaryLoading( config.name ),
reloadFlag: getReloadFlag(), // Used to force a reload of the highlights
};
},

Expand Down

0 comments on commit 1673ba1

Please sign in to comment.