-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
54 deletions.
There are no files selected for viewing
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
5 changes: 4 additions & 1 deletion
5
components/drag-handle/index.js → components/drag-handle/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
24 changes: 17 additions & 7 deletions
24
components/is-admin/index.js → components/is-admin/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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import type { Plugin } from '@wordpress/core-data'; | ||
|
||
const ACTIVE_STATUSES = ['active', 'network-active'] as const; | ||
|
||
/** | ||
* Custom hook to check if a plugin is active and whether its resolution has finished. | ||
* | ||
* @param pluginName The name of the plugin to check. | ||
* @returns A tuple containing two boolean values: the first indicating whether the plugin is active, | ||
* and the second indicating whether the resolution for the plugin has finished. | ||
*/ | ||
export const useIsPluginActive = (pluginName: string) => { | ||
return useSelect( | ||
(select) => { | ||
const storeSelectors = select(coreStore); | ||
const plugin: Plugin = (storeSelectors as any).getPlugin(pluginName); | ||
const hasResolvedPlugins: boolean = (storeSelectors as any).hasFinishedResolution('getPlugin', [ | ||
pluginName, | ||
]); | ||
|
||
const isPluginActive: boolean = ACTIVE_STATUSES.includes(plugin?.status); | ||
|
||
return [isPluginActive, hasResolvedPlugins]; | ||
}, | ||
[pluginName], | ||
) as [boolean, boolean]; | ||
}; |
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