mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-10 10:02:36 +01:00
* refactor: HoverButtons and Fork components to use explicit props * refactor: improve typing for Fork Component * fix: memoize SpecIcon to avoid unnecessary re-renders * feat: introduce URLIcon component and update SpecIcon for improved icon handling * WIP: optimizing icons * refactor: simplify modelLabel assignment in Message components * refactor: memoize ConvoOptions component to optimize rendering performance
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import React, { memo } from 'react';
|
|
import type { TModelSpec, TEndpointsConfig } from 'librechat-data-provider';
|
|
import type { IconMapProps } from '~/common';
|
|
import { getModelSpecIconURL, getIconKey, getEndpointField } from '~/utils';
|
|
import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
|
|
import { URLIcon } from '~/components/Endpoints/URLIcon';
|
|
|
|
interface SpecIconProps {
|
|
currentSpec: TModelSpec;
|
|
endpointsConfig: TEndpointsConfig;
|
|
}
|
|
|
|
const SpecIcon: React.FC<SpecIconProps> = ({ currentSpec, endpointsConfig }) => {
|
|
const iconURL = getModelSpecIconURL(currentSpec);
|
|
const { endpoint } = currentSpec.preset;
|
|
const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
|
|
const iconKey = getIconKey({ endpoint, endpointsConfig, endpointIconURL });
|
|
let Icon: (props: IconMapProps) => React.JSX.Element;
|
|
|
|
if (!iconURL.includes('http')) {
|
|
Icon = icons[iconKey] ?? icons.unknown;
|
|
} else if (iconURL) {
|
|
return <URLIcon iconURL={iconURL} altName={currentSpec.name} />;
|
|
} else {
|
|
Icon = icons[endpoint ?? ''] ?? icons.unknown;
|
|
}
|
|
|
|
return (
|
|
<Icon
|
|
size={20}
|
|
endpoint={endpoint}
|
|
context="menu-item"
|
|
iconURL={endpointIconURL}
|
|
className="icon-lg mr-1 shrink-0 text-text-primary"
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default memo(SpecIcon);
|