-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use @wordpress/core-data to handle settings
- Loading branch information
1 parent
074ac99
commit 1339b0d
Showing
17 changed files
with
82 additions
and
74 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.
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
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
2 changes: 2 additions & 0 deletions
2
projects/js-packages/publicize-components/src/social-store/actions/index.js
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,13 +1,15 @@ | ||
import * as connectionData from './connection-data'; | ||
import siteSettingActions from './jetpack-settings'; | ||
import * as shareStatus from './share-status'; | ||
import * as sigActions from './social-image-generator'; | ||
import socialNotesSettings from './social-notes-settings'; | ||
|
||
const actions = { | ||
...shareStatus, | ||
...siteSettingActions, | ||
...connectionData, | ||
...socialNotesSettings, | ||
...sigActions, | ||
}; | ||
|
||
export default actions; |
18 changes: 18 additions & 0 deletions
18
projects/js-packages/publicize-components/src/social-store/actions/social-image-generator.ts
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,18 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { SIG_SETTINGS_KEY } from '../constants'; | ||
import { SocialImageGeneratorConfig } from '../types'; | ||
|
||
/** | ||
* Saves the Social Image Generator settings. | ||
* | ||
* @param {Partial< SocialImageGeneratorConfig >} data - The data to save. | ||
* | ||
* @return {Function} A thunk. | ||
*/ | ||
export function updateSocialImageGeneratorConfig( data: Partial< SocialImageGeneratorConfig > ) { | ||
return async function ( { registry } ) { | ||
const { saveSite } = registry.dispatch( coreStore ); | ||
|
||
await saveSite( { [ SIG_SETTINGS_KEY ]: data } ); | ||
}; | ||
} |
1 change: 1 addition & 0 deletions
1
projects/js-packages/publicize-components/src/social-store/constants.ts
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 @@ | ||
export const SIG_SETTINGS_KEY = 'jetpack_social_image_generator_settings'; |
14 changes: 14 additions & 0 deletions
14
projects/js-packages/publicize-components/src/social-store/selectors/index.js
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,13 +1,27 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { createRegistrySelector } from '@wordpress/data'; | ||
import * as connectionDataSelectors from './connection-data'; | ||
import jetpackSettingSelectors from './jetpack-settings'; | ||
import * as shareStatusSelectors from './share-status'; | ||
import siteDataSelectors from './site-data'; | ||
import * as sigSelectors from './social-image-generator'; | ||
|
||
/** | ||
* Returns whether the site settings are being saved. | ||
* | ||
* @type {() => boolean} Whether the site settings are being saved. | ||
*/ | ||
export const isSavingSiteSettings = createRegistrySelector( select => () => { | ||
return select( coreStore ).isSavingEntityRecord( 'root', 'site', undefined ); | ||
} ); | ||
|
||
const selectors = { | ||
...siteDataSelectors, | ||
...connectionDataSelectors, | ||
...jetpackSettingSelectors, | ||
...shareStatusSelectors, | ||
isSavingSiteSettings, | ||
...sigSelectors, | ||
}; | ||
|
||
export default selectors; |
17 changes: 17 additions & 0 deletions
17
...cts/js-packages/publicize-components/src/social-store/selectors/social-image-generator.ts
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,17 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { createRegistrySelector } from '@wordpress/data'; | ||
import { getSocialScriptData } from '../../utils'; | ||
import { SIG_SETTINGS_KEY } from '../constants'; | ||
import { SocialImageGeneratorConfig, SocialSettingsFields } from '../types'; | ||
|
||
/** | ||
* Returns the Social Image Generator settings for the current site. | ||
*/ | ||
export const getSocialImageGeneratorConfig = createRegistrySelector( select => () => { | ||
const { getSite } = select( coreStore ); | ||
|
||
const settings = getSite( undefined, { _fields: SIG_SETTINGS_KEY } ) as SocialSettingsFields; | ||
|
||
// If the settings are not available in the store yet, use the default settings. | ||
return settings?.[ SIG_SETTINGS_KEY ] ?? getSocialScriptData().settings.socialImageGenerator; | ||
} ) as ( state: object ) => SocialImageGeneratorConfig; |
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
23 changes: 0 additions & 23 deletions
23
projects/js-packages/publicize-components/src/store/index.ts
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
projects/js-packages/publicize-components/src/store/social-image-generator.ts
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
projects/js-packages/publicize-components/src/store/types.ts
This file was deleted.
Oops, something went wrong.
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