-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
MarketAgent.js
70 lines (65 loc) · 2.9 KB
/
MarketAgent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, {useEffect, useState} from "react";
import Image from "next/image";
import {fetchAgentTemplateList} from "@/pages/api/DashboardService";
import {EventBus} from "@/utils/eventBus";
import {loadingTextEffect} from "@/utils/utils";
import axios from 'axios';
export default function MarketAgent() {
const [agentTemplates, setAgentTemplates] = useState([])
const [showMarketplace, setShowMarketplace] = useState(false);
const [isLoading, setIsLoading] = useState(true)
const [loadingText, setLoadingText] = useState("Loading Agent Templates");
useEffect(() => {
loadingTextEffect('Loading Agent Templates', setLoadingText, 500);
if (window.location.href.toLowerCase().includes('marketplace')) {
setShowMarketplace(true);
axios.get('https://app.superagi.com/api/agent_templates/marketplace/list')
.then((response) => {
const data = response.data || [];
setAgentTemplates(data);
setIsLoading(false);
})
.catch((error) => {
console.error('Error fetching agent templates:', error);
});
} else {
fetchAgentTemplateList()
.then((response) => {
const data = response.data || [];
setAgentTemplates(data);
setIsLoading(false);
})
.catch((error) => {
console.error('Error fetching agent templates:', error);
});
}
}, []);
function handleTemplateClick(item) {
const contentType = 'agent_template';
EventBus.emit('openTemplateDetails', {item, contentType});
}
return (
<div className={showMarketplace ? 'ml_8' : 'ml_3'}>
<div className="w_100 overflowY_auto mxh_78vh">
{!isLoading ? <div>
{agentTemplates.length > 0 ? <div className="marketplaceGrid3">{agentTemplates.map((item, index) => (
<div className="market_containers cursor_pointer" key={item.id} onClick={() => handleTemplateClick(item)}>
<div className="vertical_containers overflow_auto">
<div>{item.name}</div>
<div className="color_gray lh_16">by SuperAgi <Image width={14} height={14}
src="/images/is_verified.svg"
alt="is_verified"/></div>
<div className="text_ellipsis mt_8 color_gray">{item.description}</div>
</div>
</div>
))}</div> : <div className="center_container mt_40">
<Image width={150} height={60} src="/images/no_permissions.svg" alt="no-permissions"/>
<span className="feed_title mt_8">No Agent Templates found!</span>
</div>}
</div> : <div className="horizontal_container_center h_75vh">
<div className="signInInfo text_16 ff_sourceCode">{loadingText}</div>
</div>}
</div>
</div>
)
};