Files
firegex-traffic-viewer/frontend/src/pages/HomePage.tsx

64 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-06-12 12:09:50 +02:00
import { Space, Title } from '@mantine/core';
import { showNotification } from '@mantine/notifications';
2022-06-11 21:57:50 +02:00
import React, { useEffect, useState } from 'react';
2022-06-12 12:09:50 +02:00
import { useNavigate } from 'react-router-dom';
2022-06-11 21:57:50 +02:00
import ServiceRow from '../components/ServiceRow';
2022-06-12 12:09:50 +02:00
import { notification_time, Service, update_freq } from '../js/models';
2022-06-11 21:57:50 +02:00
import { servicelist } from '../js/utils';
2022-06-12 12:09:50 +02:00
import { ImCross } from "react-icons/im"
2022-06-11 21:57:50 +02:00
function HomePage() {
const [services, setServices] = useState<Service[]>([
{
id:"ctfe",
internal_port:18080,
n_packets: 30,
n_regex: 40,
name:"CTFe",
public_port:80,
status:"pause"
},
{
id:"saas",
internal_port:18080,
n_packets: 30,
n_regex: 40,
name:"SaaS",
public_port:5000,
status:"active"
}
]);
const navigator = useNavigate()
const updateInfo = () => {
2022-06-12 12:09:50 +02:00
servicelist().then(res => {
setServices(res)
}).catch(
err =>{
showNotification({
autoClose: notification_time,
title: "Home Page Auto-Update failed!",
message: "[ "+err+" ]",
color: 'red',
icon: <ImCross />,
});
})
2022-06-11 21:57:50 +02:00
}
2022-06-12 12:09:50 +02:00
useEffect(()=>{
updateInfo()
const updater = setInterval(updateInfo, update_freq)
return () => { clearInterval(updater) }
}, []);
2022-06-11 21:57:50 +02:00
return <div id="service-list" className="center-flex-row">
2022-06-12 12:09:50 +02:00
{services.length > 0?services.map( srv => <ServiceRow service={srv} key={srv.id} onClick={()=>{
2022-06-11 21:57:50 +02:00
navigator("/"+srv.id)
2022-06-12 12:09:50 +02:00
}} />):<><Space h="xl" /> <Title className='center-flex' order={1}>No services found! Add one clicking the button above</Title></>}
2022-06-11 21:57:50 +02:00
</div>
}
export default HomePage;