-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Like block: Add Reblog setting (#34514)
* Initial commit * Populate the toggle with fetched `disabled_reblogs` value * Add site type to data shared in block editor * Display the Reblog setting for Simple sites only * Update block description based on site type * Negate Reblog setting (as the setting is `disabled_reblogs`) * Remove unnecessary comment * Negate `reblogSetting` output of `useFetchReblogSetting`
- Loading branch information
1 parent
3a3575e
commit 5ad019a
Showing
5 changed files
with
101 additions
and
19 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-like-block-reblog-setting
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 | ||
|
||
Like block (beta): Add Reblog setting |
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
35 changes: 35 additions & 0 deletions
35
projects/plugins/jetpack/extensions/blocks/like/use-fetch-reblog-setting.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { useState, useCallback } from '@wordpress/element'; | ||
|
||
export default function useFetchReblogSetting( blogId ) { | ||
const [ isLoading, setIsLoading ] = useState( false ); | ||
const [ reblogSetting, setReblogSetting ] = useState( null ); | ||
const [ error, setError ] = useState( null ); | ||
|
||
const fetchReblogSetting = useCallback( async () => { | ||
const path = `https://public-api.wordpress.com/rest/v1.3/sites/${ blogId }/settings/`; | ||
|
||
setIsLoading( true ); | ||
await apiFetch( { url: path, method: 'GET' } ) | ||
.then( response => { | ||
setReblogSetting( ! response?.settings?.disabled_reblogs ); | ||
setError( null ); | ||
} ) | ||
.catch( err => { | ||
setError( err ); | ||
} ) | ||
.finally( () => { | ||
setIsLoading( false ); | ||
} ); | ||
}, [ blogId ] ); | ||
|
||
return { | ||
isLoading, | ||
reblogSetting, | ||
error, | ||
fetchReblogSetting, | ||
}; | ||
} |