-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jetpack Social: Add toggle to Social admin page to enable or disable …
…SIG and pick a default template (#29722) * [not verified] Add SIG toggle with template picker to admin page * [not verified] changelog * [not verified] Only show toggle when SIG is available * [not verified] Actually use default template * [not verified] changelog * [not verified] Do not load SIG when it is not enabled * [not verified] changelog * Fix PHP tests * Fix JS tests
- Loading branch information
Daniel Post
authored
Mar 28, 2023
1 parent
98e0eec
commit dc2797f
Showing
26 changed files
with
340 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
...ges/publicize-components/changelog/add-jetpack-social-add-sig-settings-to-publicize-store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Added toggle to Social admin page to enable or disable Social Image Generator as well as an option to pick a default template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/packages/publicize/changelog/add-jetpack-social-add-sig-settings-to-publicize-store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Use picked default template for Social Image Generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-jetpack-social-add-sig-settings-to-publicize-store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: enhancement | ||
|
||
Prevent SIG from running when it is disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/social/changelog/add-jetpack-social-add-sig-settings-to-publicize-store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Added toggle to Social admin page to enable or disable Social Image Generator as well as an option to pick a default template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
projects/plugins/social/src/js/components/social-image-generator-toggle/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Button, Text, useBreakpointMatch } from '@automattic/jetpack-components'; | ||
import { SocialImageGeneratorTemplatePicker as TemplatePicker } from '@automattic/jetpack-publicize-components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useState, useCallback, useEffect } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import React from 'react'; | ||
import { STORE_ID } from '../../store'; | ||
import ToggleSection from '../toggle-section'; | ||
import { SocialStoreSelectors } from '../types/types'; | ||
import styles from './styles.module.scss'; | ||
|
||
const SocialImageGeneratorToggle: React.FC = () => { | ||
const [ currentTemplate, setCurrentTemplate ] = useState( null ); | ||
const { isEnabled, isUpdating, defaultTemplate } = useSelect( select => { | ||
const store = select( STORE_ID ) as SocialStoreSelectors; | ||
return { | ||
isEnabled: store.isSocialImageGeneratorEnabled(), | ||
isUpdating: store.isUpdatingSocialImageGeneratorSettings(), | ||
defaultTemplate: store.getSocialImageGeneratorDefaultTemplate(), | ||
}; | ||
}, [] ); | ||
|
||
const updateOptions = useDispatch( STORE_ID ).updateSocialImageGeneratorSettings; | ||
|
||
const toggleStatus = useCallback( () => { | ||
const newOption = { | ||
enabled: ! isEnabled, | ||
}; | ||
updateOptions( newOption ); | ||
}, [ isEnabled, updateOptions ] ); | ||
|
||
useEffect( () => { | ||
if ( currentTemplate ) { | ||
const newOption = { defaults: { template: currentTemplate } }; | ||
updateOptions( newOption ); | ||
} | ||
}, [ currentTemplate, updateOptions ] ); | ||
|
||
const [ isSmall ] = useBreakpointMatch( 'sm' ); | ||
|
||
const renderTemplatePicker = useCallback( | ||
( { open } ) => ( | ||
<Button | ||
fullWidth={ isSmall } | ||
className={ styles.button } | ||
variant="secondary" | ||
disabled={ isUpdating || ! isEnabled } | ||
onClick={ open } | ||
> | ||
{ __( 'Change default template', 'jetpack-social' ) } | ||
</Button> | ||
), | ||
[ isEnabled, isSmall, isUpdating ] | ||
); | ||
|
||
return ( | ||
<ToggleSection | ||
title={ __( 'Enable Social Image Generator', 'jetpack-social' ) } | ||
disabled={ isUpdating } | ||
checked={ isEnabled } | ||
onChange={ toggleStatus } | ||
> | ||
<Text className={ styles.text }> | ||
{ __( | ||
'When enabled, Social Image Generator will automatically generate social images for your posts. You can use the button below to choose a default template for new posts.', | ||
'jetpack-social' | ||
) } | ||
</Text> | ||
<TemplatePicker | ||
value={ currentTemplate || defaultTemplate } | ||
onSelect={ setCurrentTemplate } | ||
render={ renderTemplatePicker } | ||
/> | ||
</ToggleSection> | ||
); | ||
}; | ||
|
||
export default SocialImageGeneratorToggle; |
21 changes: 21 additions & 0 deletions
21
projects/plugins/social/src/js/components/social-image-generator-toggle/styles.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.text { | ||
grid-column: span 2; | ||
|
||
a { | ||
color: inherit; | ||
} | ||
|
||
@media ( min-width: 600px ) { | ||
grid-column: 2; | ||
} | ||
} | ||
|
||
.button { | ||
margin-top: calc( var( --spacing-base ) * 2 ); | ||
grid-column: span 2; | ||
justify-self: flex-start; | ||
|
||
@media ( min-width: 600px ) { | ||
grid-column: 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import siteSettingActions from './jetpack-settings'; | ||
import socialImageGeneratorSettingActions from './social-image-generator-settings'; | ||
|
||
const actions = { | ||
...siteSettingActions, | ||
...socialImageGeneratorSettingActions, | ||
}; | ||
|
||
export default actions; |
Oops, something went wrong.