Skip to content

Commit

Permalink
Site Editor: useLocation instead of window.location.href
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Apr 30, 2024
1 parent e2142c3 commit 419804d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { downloadZip } from 'client-zip';
/**
* WordPress dependencies
*/
import { getQueryArgs } from '@wordpress/url';
import { downloadBlob } from '@wordpress/blob';
import { __, _x, sprintf } from '@wordpress/i18n';
import {
Expand Down Expand Up @@ -39,7 +38,7 @@ import {
} from '../../utils/constants';
import { CreateTemplatePartModalContents } from '../create-template-part-modal';

const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { CreatePatternModalContents, useDuplicatePatternProps } =
unlock( patternsPrivateApis );

Expand Down Expand Up @@ -365,9 +364,9 @@ export const duplicatePatternAction = {
modalHeader: _x( 'Duplicate pattern', 'action label' ),
RenderModal: ( { items, closeModal } ) => {
const [ item ] = items;
const { categoryId = PATTERN_DEFAULT_CATEGORY } = getQueryArgs(
window.location.href
);
const {
params: { categoryId = PATTERN_DEFAULT_CATEGORY },
} = useLocation();
const isThemePattern = item.type === PATTERN_TYPES.theme;
const history = useHistory();
function onPatternSuccess( { pattern } ) {
Expand Down Expand Up @@ -401,11 +400,11 @@ export const duplicateTemplatePartAction = {
RenderModal: ( { items, closeModal } ) => {
const [ item ] = items;
const { createSuccessNotice } = useDispatch( noticesStore );
const { categoryId = PATTERN_DEFAULT_CATEGORY } = getQueryArgs(
window.location.href
);
const {
params: { categoryId = PATTERN_DEFAULT_CATEGORY },
} = useLocation();
const history = useHistory();
async function onTemplatePartSuccess( templatePart ) {
function onTemplatePartSuccess( templatePart ) {
createSuccessNotice(
sprintf(
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
Expand Down
9 changes: 3 additions & 6 deletions packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Tooltip,
Flex,
} from '@wordpress/components';
import { getQueryArgs } from '@wordpress/url';
import { __, _x } from '@wordpress/i18n';
import {
useState,
Expand Down Expand Up @@ -67,7 +66,7 @@ const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
blockEditorPrivateApis
);
const { usePostActions } = unlock( editorPrivateApis );
const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );

const EMPTY_ARRAY = [];
const defaultConfigPerViewType = {
Expand Down Expand Up @@ -253,10 +252,8 @@ function Title( { item, categoryId } ) {

export default function DataviewsPatterns() {
const {
categoryType,
categoryId: categoryIdFromURL,
path,
} = getQueryArgs( window.location.href );
params: { categoryType, categoryId: categoryIdFromURL, path },
} = useLocation();
const type =
categoryType ||
( path === '/wp_template_part/all'
Expand Down
7 changes: 4 additions & 3 deletions packages/edit-site/src/components/pattern-modal/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { useDispatch, useSelect } from '@wordpress/data';
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { getQueryArgs } from '@wordpress/url';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
Expand All @@ -16,12 +15,14 @@ import { unlock } from '../../lock-unlock';
import useEditedEntityRecord from '../use-edited-entity-record';

const { DuplicatePatternModal } = unlock( patternsPrivateApis );
const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { interfaceStore } = unlock( editorPrivateApis );

export default function PatternDuplicateModal() {
const { record } = useEditedEntityRecord();
const { categoryType, categoryId } = getQueryArgs( window.location.href );
const {
params: { categoryType, categoryId },
} = useLocation();
const { closeModal } = useDispatch( interfaceStore );
const history = useHistory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
} from '@wordpress/components';
import { getTemplatePartIcon } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { getQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { file } from '@wordpress/icons';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
Expand All @@ -26,6 +26,9 @@ import {
} from '../../utils/constants';
import usePatternCategories from './use-pattern-categories';
import useTemplatePartAreas from './use-template-part-areas';
import { unlock } from '../../lock-unlock';

const { useLocation } = unlock( routerPrivateApis );

function CategoriesGroup( {
path,
Expand Down Expand Up @@ -109,9 +112,9 @@ function CategoriesGroup( {

const EMPTY_ARRAY = [];
export default function SidebarNavigationScreenPatterns() {
const { categoryType, categoryId, path } = getQueryArgs(
window.location.href
);
const {
params: { categoryType, categoryId, path },
} = useLocation();
const isTemplatePartsPath = path === '/wp_template_part/all';
const currentCategory =
categoryId ||
Expand Down

0 comments on commit 419804d

Please sign in to comment.