+
+ {
+ vertical ? (
+
{round ? Math.round(percent) : percent}%
+ ) : null
+ }
-
+
diff --git a/src/Components/Card/styles.ts b/src/Components/Card/styles.ts
index fa69b55..6511e0e 100644
--- a/src/Components/Card/styles.ts
+++ b/src/Components/Card/styles.ts
@@ -13,8 +13,6 @@ const styles = {
},
Section: {
boxSizing: 'border-box',
- width: '50%',
- height: '100%',
padding: '0 16px 32px 16px'
},
Default: {
@@ -60,7 +58,6 @@ const styles = {
Content: {
width: '100%',
display: 'flex',
- flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
boxSizing: 'border-box'
diff --git a/src/Components/Stats/TimeStat.tsx b/src/Components/Stats/TimeStat.tsx
index 7ed9711..b326141 100644
--- a/src/Components/Stats/TimeStat.tsx
+++ b/src/Components/Stats/TimeStat.tsx
@@ -56,16 +56,23 @@ type TimeStatProps = {
const TimeStat: React.FC
= ({timeEntity, condition, config, direction}) => {
const [ time, setTime ] = useState( timeEntity.state || 0);
+ const [ lastIntervalId, setLastIntervalId ] = useState(-1);
+
+ const incTime = () => setTime( time => time + direction );
useEffect(() => {
- setInterval(
- () => setTime(time => time + direction),
+
+ if (lastIntervalId !== -1) clearInterval(lastIntervalId);
+
+ setTime(timeEntity.state || 0);
+
+ const id = setInterval(
+ incTime,
1000
);
- }, [])
- useEffect(() => {
- setTime(timeEntity.state || 0);
+ setLastIntervalId(id);
+
}, [timeEntity])
return (
diff --git a/src/Components/Stats/index.tsx b/src/Components/Stats/index.tsx
index 0379082..a8a2eb5 100644
--- a/src/Components/Stats/index.tsx
+++ b/src/Components/Stats/index.tsx
@@ -2,10 +2,13 @@ import React, { useContext } from 'react';
import ThreedyContext from '../../Contexts/ThreedyContext';
import styles from './styles';
-import {renderStats} from "./utils";
+import {percentComplete, renderStats} from "./utils";
+type StatsProps = {
+ showPercent?: boolean
+};
-const Stats = () => {
+const Stats: React.FC = ({ showPercent = true }) => {
const {
hass,
@@ -13,13 +16,17 @@ const Stats = () => {
} = useContext(ThreedyContext);
const round = config.round === undefined ? true : config.round;
- const percentComplete = (hass.states[config.use_mqtt ? `${config.base_entity}_print_progress` : `${config.base_entity}_job_percentage`] || { state: -1.0 }).state;
+ const percent = percentComplete(hass, config);
return (
-
-
{round ? Math.round(percentComplete) : percentComplete}%
-
+ {
+ showPercent ? (
+
+
{round ? Math.round(percent) : percent}%
+
+ ) : (null)
+ }
{
config.monitored ? renderStats(hass, config) : null
diff --git a/src/Components/Stats/utils.tsx b/src/Components/Stats/utils.tsx
index b7403ba..51d6f59 100644
--- a/src/Components/Stats/utils.tsx
+++ b/src/Components/Stats/utils.tsx
@@ -129,6 +129,14 @@ const renderStats = (
}
+const percentComplete = (
+ hass: HomeAssistant,
+ config: ThreedyConfig
+) => {
+ return (hass.states[config.use_mqtt ? `${config.base_entity}_print_progress` : `${config.base_entity}_job_percentage`] || { state: -1.0 }).state;
+}
+
export {
- renderStats
+ renderStats,
+ percentComplete
}
diff --git a/tsconfig.json b/tsconfig.json
index 48fc7a4..7aad21a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,7 +8,8 @@
"removeComments": true,
"sourceMap": true,
"allowJs": true,
- "jsx": "react"
+ "jsx": "react",
+ "allowSyntheticDefaultImports": true
},
"exclude": ["build"]
}