fix: admin/logs: missing icons when wikipedia is unreachable #620
Massimo Melina committed
Jun 11, 2024 at 09:19 UTC
c8ce918eff3581cb80a82b7c8ec1a41a1cbf3b72
2 files changed
+17
-10
admin/src/HomePage.ts
+1
-1
@@ -138,7 +138,7 @@ export default function HomePage() {
138
)),
139
)),
140
)),
141
- h(SwitchThemeBtn, { variant: 'outlined' }),
141
+ h(SwitchThemeBtn, { variant: 'outlined' }),
142
)
143
}
144
admin/src/LogsPage.ts
+16
-9
@@ -303,27 +303,34 @@ export function agentIcons(agent: string | undefined) {
303
if (!agent) return
304
const UW = 'https://upload.wikimedia.org/wikipedia/commons/'
305
const short = shortenAgent(agent)
306
- const browserIcon = icon(short, {
306
+ const browserIcon = h(AgentIcon, { k: short, altText: true, map: {
307
Chrome: UW + 'e/e1/Google_Chrome_icon_%28February_2022%29.svg',
308
Chromium: UW + 'f/fe/Chromium_Material_Icon.svg',
309
Firefox: UW + 'a/a0/Firefox_logo%2C_2019.svg',
310
Safari: UW + '5/52/Safari_browser_logo.svg',
311
Edge: UW + '9/98/Microsoft_Edge_logo_%282019%29.svg',
312
Opera: UW + '4/49/Opera_2015_icon.svg',
313
- })
313
+ } })
314
const os = _.findKey(OSS, re => re.test(agent))
315
- const osIcon = os && icon(os, {
315
+ const osIcon = os && h(AgentIcon, { k: os, map: {
316
android: UW + 'd/d7/Android_robot.svg',
317
linux: UW + '0/0a/Tux-shaded.svg',
318
win: UW + '0/0a/Unofficial_Windows_logo_variant_-_2002%E2%80%932012_%28Multicolored%29.svg',
319
apple: UW + '7/74/Apple_logo_dark_grey.svg', // grey works for both themes
320
- })
321
- return hTooltip(agent, undefined, h('span', {}, browserIcon || short, ' ', osIcon) )
320
+ } })
321
+ return hTooltip(agent, undefined, h('span', {}, browserIcon, ' ', osIcon) )
322
+}
323
323
- function icon(k: string, map: Dict<string>) {
324
- const src = map[k]
325
- return src && h('img', { src, style: { height: '1.3em', verticalAlign: 'bottom', marginRight: '.2em' } })
326
- }
324
+const alreadyFailed: any = {}
325
+
326
+function AgentIcon({ k, map, altText }: { k: string, map: Dict<string>, altText?: boolean }) {
327
+ const src = map[k]
328
+ const [err, setErr] = useState(alreadyFailed[k])
329
+ return !src || err ? h(Fragment, {}, altText ? k : null) : h('img', {
330
+ src: err ? `/${k}.svg` : src,
331
+ style: { height: '1.3em', verticalAlign: 'bottom', marginRight: '.2em' },
332
+ onError() { setErr(alreadyFailed[k] = true) }
333
+ })
334
}
335
336
const OSS = {