| 1 |
import apiFetch from '@wordpress/api-fetch'; |
| 2 |
import { create } from 'zustand'; |
| 3 |
import { persist } from 'zustand/middleware'; |
| 4 |
|
| 5 |
export const useInstalledPluginsCache = create( |
| 6 |
persist( |
| 7 |
(set) => ({ |
| 8 |
installedPlugins: window.extSharedData?.activePlugins?.map( |
| 9 |
(plugin) => plugin.split('/')[0], |
| 10 |
), |
| 11 |
updateInstalledPlugins: async () => { |
| 12 |
const installedPlugins = ( |
| 13 |
await apiFetch({ |
| 14 |
path: '/wp/v2/plugins', |
| 15 |
method: 'GET', |
| 16 |
}) |
| 17 |
)?.map((plugin) => plugin.plugin.split('/')[0]); |
| 18 |
|
| 19 |
set({ installedPlugins }); |
| 20 |
}, |
| 21 |
}), |
| 22 |
{ |
| 23 |
name: `extendify-page-creator-page-installed-plugins-cache-${window.extSharedData.siteId}`, |
| 24 |
}, |
| 25 |
), |
| 26 |
); |
| 27 |
|