feat: refine widget interactions
This commit is contained in:
1 parent
a8a7545f40
commit
842e86012d
107 files changed
+3144
-1233
No files matched your search
@@ -1,8 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { Flex, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { Center, Flex, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { VpnIntegrationCard } from "./vpn-card";
|
||||
@@ -11,12 +12,26 @@ export default function VpnWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
height,
|
||||
displayMode = "compact",
|
||||
}: WidgetComponentProps<"vpn">) {
|
||||
const { data: integrations = [] } = clientApi.widget.vpn.getSummaries.useQuery({
|
||||
const { data: integrations = [], isPending } = clientApi.widget.vpn.getSummaries.useQuery({
|
||||
...options,
|
||||
integrationIds,
|
||||
});
|
||||
const t = useScopedI18n("widget.vpn");
|
||||
const tCommon = useScopedI18n("common");
|
||||
const dense = displayMode === "compact" && (width < 240 || height < 120);
|
||||
|
||||
if (isPending || integrations.length === 0) {
|
||||
return (
|
||||
<Center h="100%" p="sm">
|
||||
<Text c="dimmed" size="sm" ta="center">
|
||||
{isPending ? tCommon("action.loading") : t("serviceUnavailable")}
|
||||
</Text>
|
||||
</Center>
|
||||
);
|
||||
}
|
||||
|
||||
const [vpn] = integrations;
|
||||
if (displayMode === "compact" && integrations.length === 1 && vpn) {
|
||||
@@ -26,6 +41,7 @@ export default function VpnWidget({
|
||||
vpn={vpn.summary}
|
||||
integrationName={vpn.integration.name}
|
||||
variant={width < 240 ? "list" : "single"}
|
||||
dense={dense}
|
||||
/>
|
||||
</Flex>
|
||||
);
|
||||
@@ -59,6 +75,7 @@ export default function VpnWidget({
|
||||
vpn={result.summary}
|
||||
integrationName={result.integration.name}
|
||||
variant="list"
|
||||
dense={dense}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Badge, Box, Card, Flex, Group, Text } from "@mantine/core";
|
||||
import { IconArrowsExchange, IconMapPin, IconShieldCheck, IconShieldX } from "@tabler/icons-react";
|
||||
import { Badge, Box, Card, Flex, Group, Text, VisuallyHidden } from "@mantine/core";
|
||||
import {
|
||||
IconArrowsExchange,
|
||||
IconCircleCheckFilled,
|
||||
IconCircleXFilled,
|
||||
IconMapPin,
|
||||
IconShieldCheck,
|
||||
IconShieldX,
|
||||
} from "@tabler/icons-react";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
@@ -16,17 +23,19 @@ export function VpnIntegrationCard({
|
||||
vpn,
|
||||
integrationName,
|
||||
variant = "single",
|
||||
dense = false,
|
||||
}: {
|
||||
vpn: VpnInfo;
|
||||
integrationName?: string;
|
||||
variant?: "single" | "list";
|
||||
dense?: boolean;
|
||||
}) {
|
||||
const board = useRequiredBoard();
|
||||
const compact = variant === "list";
|
||||
|
||||
const content = vpn ? (
|
||||
<Flex direction="row" w="100%" align="center" gap="xs">
|
||||
<VpnStatusColumn vpnStatus={vpn.vpnStatus} dnsStatus={vpn.dnsStatus} compact={compact} />
|
||||
<VpnStatusColumn vpnStatus={vpn.vpnStatus} dnsStatus={vpn.dnsStatus} compact={compact} dense={dense} />
|
||||
<VpnInfoColumn
|
||||
integrationName={compact ? integrationName : undefined}
|
||||
publicIp={vpn.publicIp}
|
||||
@@ -35,15 +44,16 @@ export function VpnIntegrationCard({
|
||||
provider={vpn.vpnProvider.provider}
|
||||
protocol={vpn.vpnProvider.protocol}
|
||||
compact={compact}
|
||||
dense={dense}
|
||||
/>
|
||||
</Flex>
|
||||
) : (
|
||||
<VpnUnavailableContent compact={compact} integrationName={compact ? integrationName : undefined} />
|
||||
<VpnUnavailableContent compact={compact} dense={dense} integrationName={compact ? integrationName : undefined} />
|
||||
);
|
||||
|
||||
if (compact) {
|
||||
return (
|
||||
<Card withBorder radius={board.itemRadius} p="xs" w="100%">
|
||||
<Card withBorder radius={board.itemRadius} p={dense ? 6 : "xs"} w="100%">
|
||||
{content}
|
||||
</Card>
|
||||
);
|
||||
@@ -52,20 +62,28 @@ export function VpnIntegrationCard({
|
||||
return <Box w="100%">{content}</Box>;
|
||||
}
|
||||
|
||||
function VpnUnavailableContent({ compact, integrationName }: { compact: boolean; integrationName?: string }) {
|
||||
function VpnUnavailableContent({
|
||||
compact,
|
||||
dense,
|
||||
integrationName,
|
||||
}: {
|
||||
compact: boolean;
|
||||
dense: boolean;
|
||||
integrationName?: string;
|
||||
}) {
|
||||
const t = useScopedI18n("widget.vpn");
|
||||
|
||||
return (
|
||||
<Flex direction="row" w="100%" align="center" gap="xs">
|
||||
{/* Empty statuses render the shield and DNS badge in red (see getStatusColor). */}
|
||||
<VpnStatusColumn vpnStatus="" dnsStatus="" compact={compact} />
|
||||
<VpnStatusColumn vpnStatus="" dnsStatus="" compact={compact} dense={dense} />
|
||||
<Flex gap={2} direction="column" w="100%" align="flex-start" style={{ minWidth: 0 }}>
|
||||
{integrationName ? (
|
||||
<Text fw={600} size="xs" lh={1.2} c="dimmed" lineClamp={1}>
|
||||
{integrationName}
|
||||
</Text>
|
||||
) : null}
|
||||
<Text fw={700} size={compact ? "md" : "lg"} lh={1.2} c="red" lineClamp={2}>
|
||||
<Text fw={700} size={dense ? "sm" : compact ? "md" : "lg"} lh={1.2} c="red" lineClamp={2}>
|
||||
{t("serviceUnavailable")}
|
||||
</Text>
|
||||
</Flex>
|
||||
@@ -77,17 +95,30 @@ function VpnStatusColumn({
|
||||
vpnStatus,
|
||||
dnsStatus,
|
||||
compact,
|
||||
dense,
|
||||
}: {
|
||||
vpnStatus: string;
|
||||
dnsStatus: string;
|
||||
compact: boolean;
|
||||
dense: boolean;
|
||||
}) {
|
||||
// Connected shows a shield with a check; anything else (stopped or unavailable) shows a shield with a cross.
|
||||
const ShieldIcon = vpnStatus === RUNNING_STATUS ? IconShieldCheck : IconShieldX;
|
||||
|
||||
return (
|
||||
<Flex gap={4} direction="column" w={compact ? "28%" : "30%"} miw={compact ? 56 : undefined} align="center">
|
||||
<ShieldIcon stroke={2} color={getStatusColor(vpnStatus)} size={compact ? 44 : 52} />
|
||||
<Flex
|
||||
gap={4}
|
||||
direction="column"
|
||||
w={compact ? "28%" : "30%"}
|
||||
miw={dense ? 44 : compact ? 56 : undefined}
|
||||
align="center"
|
||||
>
|
||||
<ShieldIcon
|
||||
aria-label={vpnStatus || "unavailable"}
|
||||
stroke={2}
|
||||
color={getStatusColor(vpnStatus)}
|
||||
size={dense ? 32 : compact ? 44 : 52}
|
||||
/>
|
||||
<DnsStatusBadge status={dnsStatus} />
|
||||
</Flex>
|
||||
);
|
||||
@@ -101,6 +132,7 @@ function VpnInfoColumn({
|
||||
provider,
|
||||
protocol,
|
||||
compact,
|
||||
dense,
|
||||
}: {
|
||||
integrationName?: string;
|
||||
publicIp: string;
|
||||
@@ -109,6 +141,7 @@ function VpnInfoColumn({
|
||||
provider: string;
|
||||
protocol: string;
|
||||
compact: boolean;
|
||||
dense: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Flex gap={2} direction="column" w="100%" align="flex-start" style={{ minWidth: 0 }}>
|
||||
@@ -117,16 +150,18 @@ function VpnInfoColumn({
|
||||
{integrationName}
|
||||
</Text>
|
||||
) : null}
|
||||
<Text fw={700} size={compact ? "xl" : "2xl"} lh={1.1} lineClamp={1}>
|
||||
{publicIp}
|
||||
<Text fw={700} size={dense ? "md" : compact ? "xl" : "2xl"} lh={1.1} lineClamp={1}>
|
||||
{publicIp || "—"}
|
||||
</Text>
|
||||
<Group gap={4} justify="flex-start" wrap="nowrap">
|
||||
<IconMapPin size={10} />
|
||||
<Text fs="italic" fw={500} size="sm" lh={1.2} lineClamp={1}>
|
||||
{city}, {country}
|
||||
</Text>
|
||||
</Group>
|
||||
<VpnProviderDetails provider={provider} protocol={protocol} />
|
||||
{!dense && (city || country) && (
|
||||
<Group gap={4} justify="flex-start" wrap="nowrap">
|
||||
<IconMapPin aria-hidden size={10} />
|
||||
<Text fs="italic" fw={500} size="sm" lh={1.2} lineClamp={1}>
|
||||
{[city, country].filter(Boolean).join(", ")}
|
||||
</Text>
|
||||
</Group>
|
||||
)}
|
||||
{!dense && (provider || protocol) && <VpnProviderDetails provider={provider} protocol={protocol} />}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -145,20 +180,18 @@ function VpnProviderDetails({ provider, protocol }: { provider: string; protocol
|
||||
);
|
||||
}
|
||||
|
||||
function StatusDot({ status, size = 10 }: { status: string; size?: number }) {
|
||||
return <Box bg={getStatusColor(status)} h={size} w={size} style={{ borderRadius: 999 }} />;
|
||||
}
|
||||
|
||||
function DnsStatusBadge({ status }: { status: string }) {
|
||||
const StatusIcon = status === RUNNING_STATUS ? IconCircleCheckFilled : IconCircleXFilled;
|
||||
return (
|
||||
<Badge
|
||||
variant="outline"
|
||||
color={getStatusColor(status)}
|
||||
size="xs"
|
||||
radius="xl"
|
||||
leftSection={<StatusDot status={status} size={5} />}
|
||||
leftSection={<StatusIcon aria-hidden size={9} />}
|
||||
>
|
||||
DNS
|
||||
<VisuallyHidden> {status || "unavailable"}</VisuallyHidden>
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user