Skip to content

Commit 84904df

Browse files
integrate iconscout with jsonLottie comp
1 parent f507d56 commit 84904df

File tree

5 files changed

+84
-250
lines changed

5 files changed

+84
-250
lines changed

client/packages/lowcoder/src/api/iconscoutApi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export type ResponseType = {
1717
};
1818

1919
const apiUrl = "https://api.iconscout.com";
20-
const clientID = ""; //"91870410585071";
21-
const clientSecret = ""; // "GV5aCWpwdLWTxVXFBjMKSoyDPUyjzXLR";
20+
const clientID = "";
21+
const clientSecret = "";
2222
const currentPage = 1;
2323
const currentQuery = '';
2424
const currentData = [];
@@ -75,6 +75,11 @@ class IconscoutApi extends Api {
7575
});
7676
return response?.data.response.download;
7777
}
78+
79+
static async downloadJSON(url: string): Promise<any> {
80+
const response = await axios.get(url)
81+
return response?.data;
82+
}
7883
}
7984

8085
export default IconscoutApi;

client/packages/lowcoder/src/comps/comps/imageComp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const ContainerImg = (props: RecordConstructorToView<typeof childrenMap>) => {
202202
<AntImage
203203
src={
204204
props.sourceMode === 'advanced'
205-
? (props.srcIconScout as ReactElement)?.props.value
205+
? props.srcIconScout?.value
206206
: props.src.value
207207
}
208208
referrerPolicy="same-origin"
@@ -253,7 +253,7 @@ let ImageBasicComp = new UICompBuilder(childrenMap, (props) => {
253253
{children.sourceMode.getView() === 'standard' && children.src.propertyView({
254254
label: trans("image.src"),
255255
})}
256-
{children.sourceMode.getView() === 'advanced' &&children.srcIconScout.propertyView({
256+
{children.sourceMode.getView() === 'advanced' && children.srcIconScout.propertyView({
257257
label: trans("image.src"),
258258
})}
259259
</Section>

client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps
22
import {
33
ArrayOrJSONObjectControl,
44
NumberControl,
5+
StringControl,
56
} from "comps/controls/codeControl";
67
import { dropdownControl } from "comps/controls/dropdownControl";
78
import { BoolControl } from "comps/controls/boolControl";
@@ -19,6 +20,9 @@ import {
1920
import { defaultLottie } from "./jsonConstants";
2021
import { EditorContext } from "comps/editorState";
2122
import { IconScoutAssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl";
23+
import { isEmpty } from "lodash";
24+
import IconscoutApi from "@lowcoder-ee/api/iconscoutApi";
25+
import { changeValueAction, multiChangeAction } from "lowcoder-core";
2226

2327
const Player = lazy(
2428
() => import('@lottiefiles/react-lottie-player')
@@ -98,7 +102,8 @@ let JsonLottieTmpComp = (function () {
98102
JSON.stringify(defaultLottie, null, 2)
99103
),
100104
srcIconScout: IconscoutControl(IconScoutAssetType.LOTTIE),
101-
valueIconScout: ArrayOrJSONObjectControl,
105+
uuidIconScout: StringControl,
106+
valueIconScout: withDefault(ArrayOrJSONObjectControl, JSON.stringify({})),
102107
speed: dropdownControl(speedOptions, "1"),
103108
width: withDefault(NumberControl, 100),
104109
height: withDefault(NumberControl, 100),
@@ -108,11 +113,38 @@ let JsonLottieTmpComp = (function () {
108113
loop: dropdownControl(loopOptions, "single"),
109114
keepLastFrame: BoolControl.DEFAULT_TRUE,
110115
};
111-
return new UICompBuilder(childrenMap, (props) => {
112-
console.log(props.srcIconScout);
116+
return new UICompBuilder(childrenMap, (props, dispatch) => {
117+
118+
const downloadAsset = async (uuid: string) => {
119+
try {
120+
const result = await IconscoutApi.download(uuid, {
121+
format: 'ai',
122+
});
123+
if (result && result.download_url) {
124+
const json = await IconscoutApi.downloadJSON(result.download_url);
125+
dispatch(
126+
multiChangeAction({
127+
uuidIconScout: changeValueAction(uuid, true),
128+
valueIconScout: changeValueAction(JSON.stringify(json, null, 2), true)
129+
})
130+
)
131+
}
132+
} catch(error) {
133+
console.error(error);
134+
}
135+
136+
}
137+
useEffect(() => {
138+
if(props.srcIconScout?.uuid && props.srcIconScout?.uuid !== props.uuidIconScout) {
139+
// get asset download link
140+
downloadAsset(props.srcIconScout?.uuid);
141+
}
142+
}, [props.srcIconScout]);
143+
113144
return (
114145
<div
115146
style={{
147+
height: '100%',
116148
padding: `${props.container.margin}`,
117149
animation: props.animationStyle.animation,
118150
animationDelay: props.animationStyle.animationDelay,
@@ -139,7 +171,11 @@ let JsonLottieTmpComp = (function () {
139171
hover={props.animationStart === "on hover" && true}
140172
loop={props.loop === "single" ? false : true}
141173
speed={Number(props.speed)}
142-
src={props.value}
174+
src={
175+
props.sourceMode === 'advanced'
176+
? (isEmpty(props.valueIconScout) ? '' : props.valueIconScout)
177+
: props.value
178+
}
143179
style={{
144180
height: "100%",
145181
width: "100%",

client/packages/lowcoder/src/comps/comps/meetingComp/controlButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ let ButtonTmpComp = (function () {
296296
<IconScoutWrapper
297297
$style={{ ...props.style, size: props.iconSize }}
298298
>
299-
{props.prefixIconScout}
299+
<img src={props.prefixIconScout.value} />
300300
</IconScoutWrapper>
301301
)}
302302
</Button100>

0 commit comments

Comments
 (0)