Skip to content

Commit

Permalink
Add queryclientprovider to the dynamic tags modal
Browse files Browse the repository at this point in the history
  • Loading branch information
iansvo committed Dec 28, 2024
1 parent 2853188 commit ee29cc9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
45 changes: 29 additions & 16 deletions src/dynamic-tags/components/DynamicTagModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { useState, createInterpolateElement, useEffect } from '@wordpress/elemen
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';

import getIcon from '../../utils/get-icon';
import '../editor.scss';
import { DynamicTagSelect } from './DynamicTagSelect';
import { closeSmall } from '@wordpress/icons';
import '../editor.scss';

import {
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';

const queryClient = new QueryClient();

export function DynamicTagModal( {
onInsert,
Expand Down Expand Up @@ -94,6 +102,8 @@ export function DynamicTagModal( {
};
}, [ isOpen ] );

console.log( queryClient );

return (
<>
<Toggle />
Expand Down Expand Up @@ -138,20 +148,23 @@ export function DynamicTagModal( {
</ul>
</>
) : (
<DynamicTagSelect
onInsert={ ( newValue ) => {
onInsert( newValue, { tagToReplace: tagToEdit } );
setTagToEdit( null );
onToggle();
} }
tagName={ tagName }
value={ value }
selectedText={ tagToEdit || selectedText }
tagToReplace={ tagToEdit }
currentPost={ currentPost }
currentUser={ currentUser }
context={ context }
/>
<QueryClientProvider client={ queryClient }>
<DynamicTagSelect
onInsert={ ( newValue ) => {
onInsert( newValue, { tagToReplace: tagToEdit } );
setTagToEdit( null );
onToggle();
} }
tagName={ tagName }
value={ value }
selectedText={ tagToEdit || selectedText }
tagToReplace={ tagToEdit }
currentPost={ currentPost }
currentUser={ currentUser }
context={ context }
queryClient={ queryClient }
/>
</QueryClientProvider>
) }
</div>
</Modal>
Expand Down
12 changes: 11 additions & 1 deletion src/dynamic-tags/components/DynamicTagSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ function tagSupports( tagData, support ) {
return tagSupport[ support ] || false;
}

export function DynamicTagSelect( { onInsert, tagName, selectedText, currentPost, currentUser, context } ) {
export function DynamicTagSelect( {
onInsert,
tagName,
selectedText,
currentPost,
currentUser,
context,
queryClient,
} ) {
const currentLoopItem = context?.[ 'generateblocks/loopItem' ] ?? {};
const queryType = context?.[ 'generateblocks/queryType' ] ?? 'WP_Query';
const allTags = generateBlocksEditor?.dynamicTags;
Expand Down Expand Up @@ -706,6 +714,7 @@ export function DynamicTagSelect( { onInsert, tagName, selectedText, currentPost
} }
currentPostId={ currentPostId }
includeCurrent={ false }
queryClient={ queryClient }
/>
</>
) }
Expand Down Expand Up @@ -760,6 +769,7 @@ export function DynamicTagSelect( { onInsert, tagName, selectedText, currentPost
includeCurrent={ false }
postStatus={ [ 'inherit' ] }
postType={ [ 'attachment' ] }
queryClient={ queryClient }
/>
</>
) }
Expand Down

0 comments on commit ee29cc9

Please sign in to comment.