36 lines
863 B
TypeScript
36 lines
863 B
TypeScript
import { Component, h } from "preact";
|
|
import { Link } from "preact-router/match";
|
|
import * as style from "./style.css";
|
|
|
|
export interface HomeProps {
|
|
|
|
}
|
|
|
|
export interface HomeState {
|
|
devices: string[],
|
|
}
|
|
|
|
class Home extends Component<HomeProps, HomeState> {
|
|
constructor(){
|
|
super();
|
|
this.state = { devices: [] };
|
|
}
|
|
|
|
async componentDidMount() {
|
|
var devicesResponse = await fetch('/api/devices');
|
|
this.setState({ devices: await devicesResponse.json() as string[] })
|
|
}
|
|
|
|
// Lifecycle: Called just before our component will be destroyed
|
|
componentWillUnmount() {
|
|
// stop when not renderable
|
|
}
|
|
|
|
render() {
|
|
var deviceLinks = this.state.devices.map((d) => <div><Link href={`/view/${d}`}>{d}</Link></div>)
|
|
return <div class={style.home}><span>{deviceLinks}</span></div>;
|
|
}
|
|
}
|
|
|
|
export default Home;
|