2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Handle error when loading icon pack (#8753) (#8755)

* Handle error when loading icon pack

* Update

(cherry picked from commit 8fcebefa0b26deb8c9d63b68d4f4a1b1b10e65fe)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-12-24 10:29:24 +11:00 committed by GitHub
parent 8f1bf95463
commit 3cb806d20a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,7 @@
import { create } from 'zustand'; import { create } from 'zustand';
import { t } from '@lingui/macro';
import { showNotification } from '@mantine/notifications';
import { api } from '../App'; import { api } from '../App';
import { ApiEndpoints } from '../enums/ApiEndpoints'; import { ApiEndpoints } from '../enums/ApiEndpoints';
import { generateUrl } from '../functions/urls'; import { generateUrl } from '../functions/urls';
@ -38,6 +40,7 @@ export const useIconState = create<IconState>()((set, get) => ({
await Promise.all( await Promise.all(
packs.data.map(async (pack: any) => { packs.data.map(async (pack: any) => {
if (pack.prefix && pack.fonts) {
const fontName = `inventree-icon-font-${pack.prefix}`; const fontName = `inventree-icon-font-${pack.prefix}`;
const src = Object.entries(pack.fonts as Record<string, string>) const src = Object.entries(pack.fonts as Record<string, string>)
.map( .map(
@ -47,8 +50,19 @@ export const useIconState = create<IconState>()((set, get) => ({
const font = new FontFace(fontName, `${src};`); const font = new FontFace(fontName, `${src};`);
await font.load(); await font.load();
document.fonts.add(font); document.fonts.add(font);
return font; return font;
} else {
console.error(
"ERR: Icon package is missing 'prefix' or 'fonts' field"
);
showNotification({
title: t`Error`,
message: t`Error loading icon package from server`,
color: 'red'
});
return null;
}
}) })
); );
@ -56,7 +70,7 @@ export const useIconState = create<IconState>()((set, get) => ({
hasLoaded: true, hasLoaded: true,
packages: packs.data, packages: packs.data,
packagesMap: Object.fromEntries( packagesMap: Object.fromEntries(
packs.data.map((pack: any) => [pack.prefix, pack]) packs.data?.map((pack: any) => [pack.prefix, pack])
) )
}); });
} }