0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added a basic theme install API call in AdminX settings

refs https://github.com/TryGhost/Team/issues/3432
This commit is contained in:
Jono Mingard 2023-06-14 15:52:41 +12:00
parent 7832f5c685
commit ae0989ebea
2 changed files with 25 additions and 2 deletions

View file

@ -63,7 +63,22 @@ const ThemeToolbar: React.FC<ThemeToolbarProps> = ({
{icon: 'mobile', iconColorClass: 'text-grey-500', link: true, size: 'sm'}
]}
/>
<Button color='green' label={`Install ${selectedTheme?.name}`} />
<Button
color='green'
label={`Install ${selectedTheme?.name}`}
onClick={async () => {
const data = await api.themes.install(selectedTheme.ref);
const installedTheme = data.themes[0];
setThemes([
...themes.map(theme => ({...theme, active: false})),
installedTheme
]);
showToast({
message: `Theme installed - ${installedTheme.name}`
});
setCurrentTab('installed');
}}
/>
</div>
</div>
);
@ -174,4 +189,4 @@ const ChangeThemeModal = NiceModal.create(() => {
);
});
export default ChangeThemeModal;
export default ChangeThemeModal;

View file

@ -168,6 +168,7 @@ export interface API {
browse: () => Promise<ThemesResponseType>;
activate: (themeName: string) => Promise<ThemesResponseType>;
delete: (themeName: string) => Promise<void>;
install: (repo: string) => Promise<ThemesResponseType>;
upload: ({file}: {file: File}) => Promise<ThemesResponseType>;
};
}
@ -416,6 +417,13 @@ function setupGhostApi({ghostVersion}: GhostApiOptions): API {
});
return;
},
install: async (repo) => {
const response = await fetcher(`/themes/install/?source=github&ref=${encodeURIComponent(repo)}`, {
method: 'POST'
});
const data: ThemesResponseType = await response.json();
return data;
},
upload: async ({file}: {file: File}) => {
const formData = new FormData();
formData.append('file', file);