Skip to content

Commit

Permalink
frontend: Moving sensor sub-components to internal folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrings committed Apr 27, 2024
1 parent b48787b commit e939ed3
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 60 deletions.
5 changes: 5 additions & 0 deletions apps/rasptherm/src/components/sensor/internal/humidity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Humidity({ value }: { value: number }) {
return <span>{value.toFixed(1)}&#x202f;&#x25;</span>;
}

export default Humidity;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Skeleton } from '@mui/material';

interface SensorReadoutExecutedAtProps {
executedAt: string;
loading: boolean;
}

function SensorReadoutExecutedAt(props: SensorReadoutExecutedAtProps) {
return props.loading ? (
<Skeleton width="60%" />
) : (
<span>{new Date(props.executedAt).toLocaleString()}</span>
);
}

export default SensorReadoutExecutedAt;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SensorReadoutProps } from './sensor-readout';
import Humidity from './humidity';
import Slash from './slash';
import Temperature from './temperature';

function SensorReadoutWithoutLoading(
props: Omit<SensorReadoutProps, 'loading'>
) {
return (
<>
<Temperature value={props.temperature} />
<Slash />
<Humidity value={props.humidity} />
</>
);
}

export default SensorReadoutWithoutLoading;
25 changes: 25 additions & 0 deletions apps/rasptherm/src/components/sensor/internal/sensor-readout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Skeleton, Typography } from '@mui/material';
import SensorReadoutWithoutLoading from './sensor-readout-without-loading';

export interface SensorReadoutProps {
temperature: number;
humidity: number;
loading: boolean;
}

function SensorReadout(props: SensorReadoutProps) {
return (
<Typography variant="h4">
{props.loading ? (
<Skeleton width="80%" />
) : (
<SensorReadoutWithoutLoading
temperature={props.temperature}
humidity={props.humidity}
/>
)}
</Typography>
);
}

export default SensorReadout;
5 changes: 5 additions & 0 deletions apps/rasptherm/src/components/sensor/internal/slash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Slash() {
return <span> / </span>;
}

export default Slash;
5 changes: 5 additions & 0 deletions apps/rasptherm/src/components/sensor/internal/temperature.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Temperature({ value }: { value: number }) {
return <span>{value.toFixed(1)}&#x202f;&#x2103;</span>;
}

export default Temperature;
62 changes: 2 additions & 60 deletions apps/rasptherm/src/components/sensor/sensor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,16 @@ import {
CardActions,
CardContent,
CardHeader,
Skeleton,
Typography,
} from '@mui/material';
import { Refresh as RefreshIcon } from '@mui/icons-material';
import { useSensor } from '../../hooks/sensor';
import SensorReadout from './internal/sensor-readout';
import SensorReadoutExecutedAt from './internal/sensor-readout-executed-at';

interface SensorProps {
sensorLocation: string;
}

interface SensorReadoutExecutedAtProps {
executedAt: string;
loading: boolean;
}

interface SensorReadoutProps {
temperature: number;
humidity: number;
loading: boolean;
}

function SensorReadoutExecutedAt(props: SensorReadoutExecutedAtProps) {
return props.loading ? (
<Skeleton width="60%" />
) : (
<span>{new Date(props.executedAt).toLocaleString()}</span>
);
}

function Temperature({ value }: { value: number }) {
return <span>{value.toFixed(1)}&#x202f;&#x2103;</span>;
}

function Humidity({ value }: { value: number }) {
return <span>{value.toFixed(1)}&#x202f;&#x25;</span>;
}

function Slash() {
return <span> / </span>;
}

function SensorReadoutWithoutLoading(
props: Omit<SensorReadoutProps, 'loading'>
) {
return (
<>
<Temperature value={props.temperature} />
<Slash />
<Humidity value={props.humidity} />
</>
);
}

function SensorReadout(props: SensorReadoutProps) {
return (
<Typography variant="h4">
{props.loading ? (
<Skeleton width="80%" />
) : (
<SensorReadoutWithoutLoading
temperature={props.temperature}
humidity={props.humidity}
/>
)}
</Typography>
);
}

function Sensor(props: SensorProps) {
const {
sensorReadout,
Expand Down

0 comments on commit e939ed3

Please sign in to comment.