Skip to content

Commit

Permalink
Fix navigating to all-patterns category
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Sep 20, 2023
1 parent 68ac77f commit 0dbb84b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import CreateTemplatePartModal from '../create-template-part-modal';
import SidebarButton from '../sidebar-button';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import { PATTERN_TYPES, PATTERN_DEFAULT_CATEGORY } from '../../utils/constants';

const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { CreatePatternModal } = unlock( editPatternsPrivateApis );

export default function AddNewPattern() {
const history = useHistory();
const { params } = useLocation();
const [ showPatternModal, setShowPatternModal ] = useState( false );
const [ showTemplatePartModal, setShowTemplatePartModal ] =
useState( false );
Expand Down Expand Up @@ -129,6 +131,18 @@ export default function AddNewPattern() {
try {
const pattern = await createPatternFromFile( file );

// Navigate to the All patterns category for the newly created pattern.
if (
params.categoryType !== PATTERN_TYPES.theme ||
params.categoryId !== PATTERN_DEFAULT_CATEGORY
) {
history.push( {
path: `/patterns`,
categoryType: PATTERN_TYPES.theme,
categoryId: PATTERN_DEFAULT_CATEGORY,
} );
}

createSuccessNotice(
sprintf(
// translators: %s: The imported pattern's title.
Expand Down

0 comments on commit 0dbb84b

Please sign in to comment.