Skip to content

Commit fc4f9a8

Browse files
added icon dictionary to avoid downloading icons again
1 parent 72a7b26 commit fc4f9a8

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

client/packages/lowcoder/src/comps/controls/iconControl.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import {
2626
useIcon,
2727
wrapperToControlItem,
2828
} from "lowcoder-design";
29-
import { ReactNode, useCallback, useState } from "react";
29+
import { memo, ReactNode, useCallback, useMemo, useState } from "react";
3030
import styled from "styled-components";
3131
import { setFieldsNoTypeCheck } from "util/objectUtils";
3232
import { StringControl } from "./codeControl";
3333
import { ControlParams } from "./controlParams";
34+
import { IconDictionary } from "@lowcoder-ee/constants/iconConstants";
3435

3536
const ButtonWrapper = styled.div`
3637
width: 100%;
@@ -208,14 +209,24 @@ type ChangeModeAction = {
208209
useCodeEditor: boolean;
209210
};
210211

211-
export function IconControlView(props: { value: string }) {
212+
export const IconControlView = memo((props: { value: string }) => {
212213
const { value } = props;
213214
const icon = useIcon(value);
214-
if (icon) {
215-
return icon.getView();
216-
}
217-
return <StyledImage src={value} alt="" />;
218-
}
215+
216+
return useMemo(() => {
217+
if (value && IconDictionary[value] && IconDictionary[value]?.title === icon?.title) {
218+
return IconDictionary[value];
219+
}
220+
221+
if (value && icon) {
222+
const renderIcon = icon.getView();
223+
IconDictionary[value] = renderIcon;
224+
return renderIcon;
225+
}
226+
227+
return <StyledImage src={value} alt="" />;
228+
}, [icon, value, IconDictionary[value]])
229+
});
219230

220231
export class IconControl extends AbstractComp<ReactNode, string, Node<ValueAndMsg<string>>> {
221232
private readonly useCodeEditor: boolean;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export let IconDictionary: Record<string, any> = {};
2+
3+
export const resetIconDictionary = () => {
4+
IconDictionary = {};
5+
}

client/packages/lowcoder/src/pages/editor/AppEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import dayjs from "dayjs";
3636
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
3737
import { notificationInstance } from "components/GlobalInstances";
3838
import { AppState } from "@lowcoder-ee/redux/reducers";
39+
import { resetIconDictionary } from "@lowcoder-ee/constants/iconConstants";
3940

4041
const AppSnapshot = lazy(() => {
4142
return import("pages/editor/appSnapshot")
@@ -188,6 +189,7 @@ const AppEditor = React.memo(() => {
188189
useEffect(() => {
189190
if(!isLowcoderCompLoading) {
190191
fetchApplication();
192+
resetIconDictionary();
191193
}
192194
}, [isLowcoderCompLoading, fetchApplication]);
193195

0 commit comments

Comments
 (0)