Browse Source

Widget cleanup

pull/43/head
Sacha Weatherstone 4 years ago
parent
commit
10e20df814
  1. 50
      src/components/Widgets/BatteryWidget.tsx
  2. 73
      src/components/Widgets/PeersWidget.tsx
  3. 20
      src/components/Widgets/PositionWidget.tsx

50
src/components/Widgets/BatteryWidget.tsx

@ -45,38 +45,38 @@ export const BatteryWidget = ({
if (currentStat && previousStat) {
const timeDiff = currentTime.getTime() - previousTime.getTime();
const statDiff = Math.abs(currentStat - previousStat);
//convert to ms/%
const msPerPercent = timeDiff / statDiff;
const formatted = prettyMilliseconds(
(100 - currentStat) * msPerPercent
);
setTimeRemaining(formatted);
if (statDiff !== 0) {
//convert to ms/%
const msPerPercent = timeDiff / statDiff;
const formatted = prettyMilliseconds(
(100 - currentStat) * msPerPercent
);
setTimeRemaining(formatted);
}
} else setTimeRemaining("Unknown");
}
}, [hardware.myNodeNum, nodes]);
return (
<div className="relative overflow-hidden rounded-lg bg-white p-4 shadow">
<dt>
<div className="absolute rounded-md bg-indigo-500 p-3">
<Battery100Icon className="h-6 text-white" aria-hidden="true" />
</div>
<p className="ml-16 truncate text-sm font-medium text-gray-500">
<div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<div className="rounded-md bg-indigo-500 p-3">
<Battery100Icon className="h-6 text-white" />
</div>
<div>
<p className="truncate text-sm font-medium text-gray-500">
Battery State
</p>
</dt>
<dd className="ml-16 flex items-baseline">
<p className="text-2xl font-semibold text-gray-900">{batteryLevel}%</p>
<p
className={`ml-2 flex items-baseline text-sm font-semibold text-orange-600`}
>
<ClockIcon
className="text-Orange-500 h-5 w-5 flex-shrink-0 self-center"
aria-hidden="true"
/>
{timeRemaining}
</p>
</dd>
<div className="flex gap-1">
<p className="text-xl font-semibold text-gray-900">{batteryLevel}%</p>
<div className={`flex text-sm font-semibold text-orange-600`}>
<ClockIcon
className="text-Orange-500 h-5 w-5 flex-shrink-0 self-center"
aria-hidden="true"
/>
<span className="my-auto">{timeRemaining}</span>
</div>
</div>
</div>
</div>
);
};

73
src/components/Widgets/PeersWidget.tsx

@ -1,16 +1,12 @@
import type React from "react";
import { base16 } from "rfc4648";
import { Hashicon } from "@emeraldpay/hashicon-react";
import { useDevice } from "@app/core/providers/useDevice.js";
import {
EllipsisHorizontalCircleIcon,
EllipsisHorizontalIcon,
UserGroupIcon,
} from "@heroicons/react/24/outline";
import type { Protobuf } from "@meshtastic/meshtasticjs";
import { Card } from "../Card.js";
import { Dropdown } from "../Dropdown.js";
import { IconButton } from "../IconButton.js";
import { Mono } from "../Mono.js";
@ -19,45 +15,36 @@ export interface PeersWidgetProps {
}
export const PeersWidget = ({ peers }: PeersWidgetProps): JSX.Element => {
const { setActivePage } = useDevice();
return (
<Card className="flex-col">
<Dropdown
title="Peers"
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 className="my-auto ml-auto">
<IconButton
variant="secondary"
size="sm"
icon={<EllipsisHorizontalCircleIcon className="h-4" />}
/>
</div>
</div>
))}
{peers.length === 0 && (
<Mono className="m-auto">No devices discovered yet.</Mono>
<div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<div className="rounded-md bg-emerald-500 p-3">
<UserGroupIcon className="h-6 text-white" />
</div>
<div>
<p className="truncate text-sm font-medium text-gray-500">
Connected Peers
</p>
<div className="flex gap-1">
{peers.length > 0 ? (
<p className="text-lg font-semibold text-gray-900">
{`${peers.length} ${peers.length > 1 ? "Peers" : "Peer"}`}
</p>
) : (
<Mono className="m-auto">None Discovered.</Mono>
)}
</div>
</Dropdown>
</Card>
</div>
<IconButton
className="my-auto ml-auto"
variant="secondary"
size="sm"
onClick={() => {
setActivePage("peers");
}}
icon={<EllipsisHorizontalIcon className="h-4" />}
/>
</div>
);
};

20
src/components/Widgets/PositionWidget.tsx

@ -8,18 +8,18 @@ export interface PositionWidgetProps {
export const PositionWidget = ({ grid }: PositionWidgetProps): JSX.Element => {
return (
<div className="relative overflow-hidden rounded-lg bg-white p-4 shadow">
<dt>
<div className="absolute rounded-md bg-rose-500 p-3">
<MapPinIcon className="h-6 text-white" aria-hidden="true" />
</div>
<p className="ml-16 truncate text-sm font-medium text-gray-500">
<div className="flex gap-3 overflow-hidden rounded-lg bg-white p-3 shadow">
<div className="rounded-md bg-rose-500 p-3">
<MapPinIcon className="h-6 text-white" />
</div>
<div>
<p className="truncate text-sm font-medium text-gray-500">
Current Location
</p>
</dt>
<dd className="ml-16 flex items-baseline">
<p className="text-lg font-semibold text-gray-900">{grid}</p>
</dd>
<div className="flex gap-1">
<p className="text-lg font-semibold text-gray-900">{grid}</p>
</div>
</div>
</div>
);
};

Loading…
Cancel
Save