mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Handle error when loading icon pack (#8753)
* Handle error when loading icon pack * Update
This commit is contained in:
		@@ -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,17 +40,29 @@ 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) => {
 | 
				
			||||||
        const fontName = `inventree-icon-font-${pack.prefix}`;
 | 
					        if (pack.prefix && pack.fonts) {
 | 
				
			||||||
        const src = Object.entries(pack.fonts as Record<string, string>)
 | 
					          const fontName = `inventree-icon-font-${pack.prefix}`;
 | 
				
			||||||
          .map(
 | 
					          const src = Object.entries(pack.fonts as Record<string, string>)
 | 
				
			||||||
            ([format, url]) => `url(${generateUrl(url)}) format("${format}")`
 | 
					            .map(
 | 
				
			||||||
          )
 | 
					              ([format, url]) => `url(${generateUrl(url)}) format("${format}")`
 | 
				
			||||||
          .join(',\n');
 | 
					            )
 | 
				
			||||||
        const font = new FontFace(fontName, `${src};`);
 | 
					            .join(',\n');
 | 
				
			||||||
        await font.load();
 | 
					          const font = new FontFace(fontName, `${src};`);
 | 
				
			||||||
        document.fonts.add(font);
 | 
					          await font.load();
 | 
				
			||||||
 | 
					          document.fonts.add(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 font;
 | 
					          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])
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user