/** @jsx jsx */ import { jsx, css } from '@emotion/react' import React, { useState, useEffect } from "react"; import { HttpClient } from "../lib/http_client"; import { PbmStats } from "../types/pbm_stats"; type Prop = { }; const httpClient = new HttpClient(); export const BpmPage= ({}:Prop) => { const [pbmStats, setPbmStats] = useState(""); const handlePbmStats = (e: React.MouseEvent) => { httpClient.getPbmStats() .then(function (response) { setPbmStats(`${response.data.stats}(${response.data.pid})`); }) } const handleStartPbm = (e: React.MouseEvent) => { httpClient.startPbm() .then(function (response) { if(response.data.result === "ok") { setPbmStats("waiting" as PbmStats); } else { setPbmStats("error" as PbmStats); } }) .catch(function (error) { console.log(error); }) } const handleStopPbm = (e: React.MouseEvent) => { httpClient.stopPbm() .then(function (response) { if(response.data.result === "ok") { setPbmStats("waiting" as PbmStats); } else { setPbmStats("error" as PbmStats); } }) .catch(function (error) { console.log(error); }) } const handleReloadPbmSetting = (e: React.MouseEvent) => { httpClient.reloadPbmSetting() .then(function (response) { if(response.data.result === "ok") { setPbmStats("stopped" as PbmStats); } else { setPbmStats("error" as PbmStats); } }) .catch(function (error) { console.log(error); }) } const isShowRestartButton = () => { return pbmStats == "running"; } const isShowStartButton = () => { return pbmStats == "stopped"; } const isShowStopButton = () => { return pbmStats == "running"; } useEffect(() => { httpClient.getPbmStats() .then(function (response) { setPbmStats(`${response.data.stats}(${response.data.pid})`); }) }, []) return ( <>

PBMのステータス: {pbmStats}

{isShowStopButton() && } {isShowStartButton() && } {pbmStats === "running" && } ) }