fix theme preview with no themes

This commit is contained in:
Vladimir Mandic
2024-06-16 08:35:15 -04:00
parent 5587280b55
commit a80fb38147
+17 -13
View File
@@ -471,19 +471,23 @@ function toggleCompact(val, old) {
function previewTheme() {
let name = gradioApp().getElementById('setting_gradio_theme').querySelectorAll('input')?.[0].value || '';
fetch('/file=html/themes.json').then((res) => {
res.json().then((themes) => {
const theme = themes.find((t) => t.id === name);
if (theme) {
window.open(theme.subdomain, '_blank');
} else {
const el = document.getElementById('theme-preview') || createThemeElement();
el.style.display = el.style.display === 'block' ? 'none' : 'block';
name = name.replace('/', '-');
el.src = `/file=html/${name}.jpg`;
}
});
});
fetch('/file=html/themes.json')
.then((res) => {
res.json()
.then((themes) => {
const theme = Array.isArray(themes) ? themes.find((t) => t.id === name) : null;
if (theme) {
window.open(theme.subdomain, '_blank');
} else {
const el = document.getElementById('theme-preview') || createThemeElement();
el.style.display = el.style.display === 'block' ? 'none' : 'block';
name = name.replace('/', '-');
el.src = `/file=html/${name}.jpg`;
}
})
.catch((e) => console.error('previewTheme:', e));
})
.catch((e) => console.error('previewTheme:', e));
}
async function browseFolder() {