From a80fb381474cb8b255db494c23d3433f00374c69 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 16 Jun 2024 08:35:15 -0400 Subject: [PATCH] fix theme preview with no themes --- javascript/ui.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index a3ff22542..8b4a5ce4a 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -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() {