Widget cleanup

This commit is contained in:
Sacha Weatherstone
2022-10-09 14:39:55 +10:30
parent 32401601a5
commit 10e20df814
3 changed files with 65 additions and 78 deletions
+14 -14
View File
@@ -45,38 +45,38 @@ export const BatteryWidget = ({
if (currentStat && previousStat) { if (currentStat && previousStat) {
const timeDiff = currentTime.getTime() - previousTime.getTime(); const timeDiff = currentTime.getTime() - previousTime.getTime();
const statDiff = Math.abs(currentStat - previousStat); const statDiff = Math.abs(currentStat - previousStat);
if (statDiff !== 0) {
//convert to ms/% //convert to ms/%
const msPerPercent = timeDiff / statDiff; const msPerPercent = timeDiff / statDiff;
const formatted = prettyMilliseconds( const formatted = prettyMilliseconds(
(100 - currentStat) * msPerPercent (100 - currentStat) * msPerPercent
); );
setTimeRemaining(formatted); setTimeRemaining(formatted);
}
} else setTimeRemaining("Unknown"); } else setTimeRemaining("Unknown");
} }
}, [hardware.myNodeNum, nodes]); }, [hardware.myNodeNum, nodes]);
return ( return (
<div className="relative overflow-hidden rounded-lg bg-white p-4 shadow"> <div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<dt> <div className="rounded-md bg-indigo-500 p-3">
<div className="absolute rounded-md bg-indigo-500 p-3"> <Battery100Icon className="h-6 text-white" />
<Battery100Icon className="h-6 text-white" aria-hidden="true" />
</div> </div>
<p className="ml-16 truncate text-sm font-medium text-gray-500"> <div>
<p className="truncate text-sm font-medium text-gray-500">
Battery State Battery State
</p> </p>
</dt> <div className="flex gap-1">
<dd className="ml-16 flex items-baseline"> <p className="text-xl font-semibold text-gray-900">{batteryLevel}%</p>
<p className="text-2xl font-semibold text-gray-900">{batteryLevel}%</p> <div className={`flex text-sm font-semibold text-orange-600`}>
<p
className={`ml-2 flex items-baseline text-sm font-semibold text-orange-600`}
>
<ClockIcon <ClockIcon
className="text-Orange-500 h-5 w-5 flex-shrink-0 self-center" className="text-Orange-500 h-5 w-5 flex-shrink-0 self-center"
aria-hidden="true" aria-hidden="true"
/> />
{timeRemaining} <span className="my-auto">{timeRemaining}</span>
</p> </div>
</dd> </div>
</div>
</div> </div>
); );
}; };
+29 -42
View File
@@ -1,16 +1,12 @@
import type React from "react"; import type React from "react";
import { base16 } from "rfc4648"; import { useDevice } from "@app/core/providers/useDevice.js";
import { Hashicon } from "@emeraldpay/hashicon-react";
import { import {
EllipsisHorizontalCircleIcon, EllipsisHorizontalIcon,
UserGroupIcon, UserGroupIcon,
} from "@heroicons/react/24/outline"; } from "@heroicons/react/24/outline";
import type { Protobuf } from "@meshtastic/meshtasticjs"; import type { Protobuf } from "@meshtastic/meshtasticjs";
import { Card } from "../Card.js";
import { Dropdown } from "../Dropdown.js";
import { IconButton } from "../IconButton.js"; import { IconButton } from "../IconButton.js";
import { Mono } from "../Mono.js"; import { Mono } from "../Mono.js";
@@ -19,45 +15,36 @@ export interface PeersWidgetProps {
} }
export const PeersWidget = ({ peers }: PeersWidgetProps): JSX.Element => { export const PeersWidget = ({ peers }: PeersWidgetProps): JSX.Element => {
const { setActivePage } = useDevice();
return ( return (
<Card className="flex-col"> <div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<Dropdown <div className="rounded-md bg-emerald-500 p-3">
title="Peers" <UserGroupIcon className="h-6 text-white" />
stat={peers.length}
icon={<UserGroupIcon className="h-4" />}
>
<div className="flex flex-col p-3">
{peers.map((peer) => (
<div
className="flex gap-2 rounded-md p-2 hover:bg-slate-100"
key={peer.num}
>
<span className="my-auto shrink-0">
<Hashicon value={peer.num.toString()} size={28} />
</span>
<div className="flex flex-col">
<span className="font-medium">{peer.user?.longName}</span>
<Mono>
{base16
.stringify(peer.user?.macaddr ?? [])
.match(/.{1,2}/g)
?.join(":") ?? ""}
</Mono>
</div> </div>
<div className="my-auto ml-auto"> <div>
<IconButton <p className="truncate text-sm font-medium text-gray-500">
variant="secondary" Connected Peers
size="sm" </p>
icon={<EllipsisHorizontalCircleIcon className="h-4" />} <div className="flex gap-1">
/> {peers.length > 0 ? (
</div> <p className="text-lg font-semibold text-gray-900">
</div> {`${peers.length} ${peers.length > 1 ? "Peers" : "Peer"}`}
))} </p>
{peers.length === 0 && ( ) : (
<Mono className="m-auto">No devices discovered yet.</Mono> <Mono className="m-auto">None Discovered.</Mono>
)} )}
</div> </div>
</Dropdown> </div>
</Card> <IconButton
className="my-auto ml-auto"
variant="secondary"
size="sm"
onClick={() => {
setActivePage("peers");
}}
icon={<EllipsisHorizontalIcon className="h-4" />}
/>
</div>
); );
}; };
+8 -8
View File
@@ -8,18 +8,18 @@ export interface PositionWidgetProps {
export const PositionWidget = ({ grid }: PositionWidgetProps): JSX.Element => { export const PositionWidget = ({ grid }: PositionWidgetProps): JSX.Element => {
return ( return (
<div className="relative overflow-hidden rounded-lg bg-white p-4 shadow"> <div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<dt> <div className="rounded-md bg-rose-500 p-3">
<div className="absolute rounded-md bg-rose-500 p-3"> <MapPinIcon className="h-6 text-white" />
<MapPinIcon className="h-6 text-white" aria-hidden="true" />
</div> </div>
<p className="ml-16 truncate text-sm font-medium text-gray-500"> <div>
<p className="truncate text-sm font-medium text-gray-500">
Current Location Current Location
</p> </p>
</dt> <div className="flex gap-1">
<dd className="ml-16 flex items-baseline">
<p className="text-lg font-semibold text-gray-900">{grid}</p> <p className="text-lg font-semibold text-gray-900">{grid}</p>
</dd> </div>
</div>
</div> </div>
); );
}; };