-
Notifications
You must be signed in to change notification settings - Fork 5
Don't handle the theme anymore, only the theme's patterns #3
Conversation
template_part = 'template_parts', | ||
} | ||
|
||
export type PatternType = keyof typeof ThemePatternType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such a nice one, it's hard to delete 😄
'type' => 'object', | ||
'description' => __( 'The patterns', 'pattern-manager' ), | ||
'validate_callback' => function( $to_validate ) { | ||
return is_array( $to_validate ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have been nice, but it didn't work:
'validate_callback' => 'is_array',
It doesn't have to be so specific
It only needs patterns from the active theme, not any theme.
@@ -0,0 +1,140 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed from api-theme-data.php
, as this is for patterns, not themes.
return array( | ||
'patterns' => \PatternManager\PatternDataHandlers\get_patterns(), | ||
'theme' => \PatternManager\ThemeDataHandlers\get_theme( $current_theme_data['id'] ?? null ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the whole theme anymore, just the patterns.
data is not an optional property, so we shouldn't need the ? operator.
} ); | ||
} | ||
|
||
function savePatternsData() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed from saveThemeData()
return new Promise( ( resolve ) => { | ||
setIsSaving( true ); | ||
|
||
fetch( patternmanager.apiEndpoints.savePatternsEndpoint, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO for another PR: rename patternmanager
to patternManager
template_parts?: string[]; | ||
tested_up_to: string; | ||
text_domain: string; | ||
theme_json_file?: { [ key: string ]: unknown }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Michael, sorry to delete the nice typing you did.
// Try to prevent populating an empty title by only updating if the type is a pattern. | ||
// Doing it this way should still catch an empty title if the user somehow passes one. | ||
if ( postMeta?.type === 'pattern' ) { | ||
if ( postMeta.title ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no postMeta.type
anymore, as this editor only handles patterns, not templates.
{ postMeta?.type === 'template' ? ( | ||
<TemplateDetails postMeta={ postMeta } /> | ||
) : ( | ||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ternary isn't needed, as there's no postMeta.type
anymore.
I just removed the ternary, without changing anything other than formatting.
You were probably hoping for a PR before the 3-day weekend 🤣 Of course, no rush. |
@@ -8,12 +8,11 @@ import React from 'react'; | |||
import { patternmanager } from '../../globals'; | |||
|
|||
import PatternManagerContext from '../../contexts/PatternManagerContext'; | |||
import PatternManagerSnackbarContext from '../../contexts/PatternManagerNoticeContext'; | |||
import NoticeContext from '../../contexts/NoticeContext'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a renaming. The new name is more generic.
@@ -42,15 +42,12 @@ export default function TitlePanel( { | |||
); | |||
}, [] ); | |||
|
|||
/** | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: this isn't a JSDoc, just a comment.
@@ -3,43 +3,20 @@ import { PostMeta } from '../types'; | |||
export default function useChangeWords( postMeta: PostMeta ) { | |||
// Change the word "Publish" to "Save Pattern" | |||
function changeWords( translation: string, text: string ) { | |||
if ( postMeta?.type === 'pattern' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no postMeta.type
anymore, as we're not editing templates. Only patterns.
} from '../types'; | ||
import { ThemePatternType } from '../enums'; | ||
|
||
export default function useThemeData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly moved to usePatterns()
, and removed theme-only logic.
@@ -15,7 +15,7 @@ export default function PatternPreview( { url, scale }: Props ) { | |||
const [ iframeRef, setIframeRef ] = useState< | |||
HTMLIFrameElement | undefined | |||
>( undefined ); | |||
patterns?.addRef( url, iframeRef ); | |||
patterns.addRef( url, iframeRef ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice thing about your TS typing is that we know which properties are guaranteed to be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, @kienstra!
This is a really nice cleanup. The model focuses specifically on patterns now, and it's much easier to find what's needed without the extraneous data.
Also, you resolved conflicts with the UI rough-in super fast!
Hi @mike-day,
Thanks so much for your kind words and review! |
What does this do?
.included_patterns
).wp-modules/string-fixer/
and other modules that were FSE-specific.get-theme
endpoint toget-patterns
, and their associated functions, likeget_theme()
useThemeData()
to be for patterns, not themes.What doesn't this do
Testing steps
rm -rf pattern-manager && git clone -b update/get-theme https://github.com/studiopress/pattern-manager
nvm use 14 && npm i && npm run dev