feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -1,23 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import { Box, Flex, Group, Text, Tooltip } from "@mantine/core";
|
||||
import { Badge, Box, Flex, Group, Progress, Stack, Text, Tooltip, VisuallyHidden } from "@mantine/core";
|
||||
import { IconCube, IconUsersGroup } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { formatNumber } from "@homarr/common";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { zoomCompensatedSize } from "@homarr/ui";
|
||||
|
||||
import { WidgetEmptyState } from "../../common/empty-state";
|
||||
import type { WidgetComponentProps } from "../../definition";
|
||||
|
||||
export default function MinecraftServerStatusWidget({ options }: WidgetComponentProps<"minecraftServerStatus">) {
|
||||
const { data: result } = clientApi.widget.minecraft.getServerStatus.useQuery(options);
|
||||
const tStatus = useScopedI18n("widget.minecraftServerStatus.status");
|
||||
export default function MinecraftServerStatusWidget({
|
||||
options,
|
||||
width,
|
||||
height,
|
||||
displayMode,
|
||||
}: WidgetComponentProps<"minecraftServerStatus">) {
|
||||
const { data: result, isPending, error } = clientApi.widget.minecraft.getServerStatus.useQuery(options);
|
||||
const t = useI18n("widget.minecraftServerStatus");
|
||||
const tCommon = useI18n("common");
|
||||
|
||||
if (isPending) {
|
||||
return (
|
||||
<Flex align="center" justify="center" h="100%">
|
||||
<Text c="dimmed" size="sm">
|
||||
{tCommon("action.loading")}
|
||||
</Text>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
if (error && !result) throw error;
|
||||
if (!result) return <WidgetEmptyState />;
|
||||
const { data } = result;
|
||||
|
||||
const title = options.title.trim().length > 0 ? options.title : options.domain;
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
const isDense = isAdvanced && (width < 220 || height < 120);
|
||||
const showServerIcon = !isAdvanced || (!isDense && height >= 144);
|
||||
const showMetadata = isAdvanced && width >= 260 && height >= 180;
|
||||
const showCapacity = isAdvanced && width >= 180 && height >= 140;
|
||||
const iconSize = Math.max(40, Math.min(80, width * 0.45, height * 0.45));
|
||||
const playerPercent = data.online && data.players.max > 0 ? (data.players.online / data.players.max) * 100 : 0;
|
||||
|
||||
return (
|
||||
<Flex
|
||||
@@ -25,24 +49,37 @@ export default function MinecraftServerStatusWidget({ options }: WidgetComponent
|
||||
h="100%"
|
||||
w="100%"
|
||||
direction="column"
|
||||
p="sm"
|
||||
p={isDense ? "xs" : "sm"}
|
||||
justify="center"
|
||||
align="center"
|
||||
>
|
||||
<Group gap="xs" wrap="nowrap" align="center">
|
||||
<Tooltip label={data.online ? tStatus("online") : tStatus("offline")}>
|
||||
<Box miw="md" h="md" bg={data.online ? "teal" : "red"} style={{ borderRadius: "100%" }}></Box>
|
||||
<Group gap="xs" wrap="nowrap" align="center" maw="100%">
|
||||
<Tooltip label={data.online ? t("status.online") : t("status.offline")}>
|
||||
<Box aria-hidden miw="md" h="md" bg={data.online ? "teal" : "red"} style={{ borderRadius: "100%" }} />
|
||||
</Tooltip>
|
||||
<Text size="md" fw="bold">
|
||||
<VisuallyHidden>{data.online ? t("status.online") : t("status.offline")}</VisuallyHidden>
|
||||
<Text size={showMetadata ? "lg" : "md"} fw="bold" truncate="end">
|
||||
{title}
|
||||
</Text>
|
||||
</Group>
|
||||
{showMetadata && (
|
||||
<Group gap="xs" mt="xs" wrap="wrap" justify="center">
|
||||
<Badge variant="light">{options.domain}</Badge>
|
||||
{options.isBedrockServer && <Badge variant="outline">{t("option.isBedrockServer.label")}</Badge>}
|
||||
</Group>
|
||||
)}
|
||||
{data.online && (
|
||||
<>
|
||||
{!options.isBedrockServer &&
|
||||
showServerIcon &&
|
||||
(data.icon ? (
|
||||
<img
|
||||
style={{ flex: 1, transform: "scale(0.8)", objectFit: "contain" }}
|
||||
style={{
|
||||
flex: 1,
|
||||
width: `calc(${iconSize}px * var(--board-canvas-ui-scale, 1))`,
|
||||
maxHeight: `calc(${iconSize}px * var(--board-canvas-ui-scale, 1))`,
|
||||
objectFit: "contain",
|
||||
}}
|
||||
alt={`minecraft icon ${options.domain}`}
|
||||
src={data.icon}
|
||||
/>
|
||||
@@ -55,17 +92,25 @@ export default function MinecraftServerStatusWidget({ options }: WidgetComponent
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<IconCube size="3rem" color="var(--mantine-color-gray-5)" />
|
||||
<IconCube style={zoomCompensatedSize(iconSize)} color="var(--mantine-color-gray-5)" />
|
||||
</Box>
|
||||
))}
|
||||
<Group gap={5} c="gray.6" align="center">
|
||||
<IconUsersGroup size="1rem" />
|
||||
<Text size="md">
|
||||
{formatNumber(data.players.online, 1)} / {formatNumber(data.players.max, 1)}
|
||||
</Text>
|
||||
</Group>
|
||||
<Stack gap={4} w={showCapacity ? "min(100%, 420px)" : "auto"} align="stretch">
|
||||
<Group gap={5} c="dimmed" align="center" justify="center">
|
||||
<IconUsersGroup style={zoomCompensatedSize(showMetadata ? 20 : 16)} />
|
||||
<Text size={showMetadata ? "lg" : isDense ? "sm" : "md"}>
|
||||
{formatNumber(data.players.online, 1)} / {formatNumber(data.players.max, 1)}
|
||||
</Text>
|
||||
</Group>
|
||||
{showCapacity && <Progress value={playerPercent} color={playerPercent >= 90 ? "orange" : "teal"} />}
|
||||
</Stack>
|
||||
</>
|
||||
)}
|
||||
{showMetadata && !data.online && (
|
||||
<Text mt="md" c="dimmed" size="sm">
|
||||
{options.domain}
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
import { IconBrandMinecraft } from "@tabler/icons-react";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { createWidgetDefinition } from "../../definition";
|
||||
import { createWidgetDefinition, widgetQueryInputMatches } from "../../definition";
|
||||
import { optionsBuilder } from "../../options";
|
||||
|
||||
export const { componentLoader, definition } = createWidgetDefinition("minecraftServerStatus", {
|
||||
supportsAdvancedFocus: false,
|
||||
icon: IconBrandMinecraft,
|
||||
queryKey: [["widget", "minecraft"]],
|
||||
queryKey: [["widget", "minecraft", "getServerStatus"]],
|
||||
queryMatcher: ({ input }, scope) =>
|
||||
widgetQueryInputMatches(input, {
|
||||
title: scope.options.title,
|
||||
domain: scope.options.domain,
|
||||
isBedrockServer: scope.options.isBedrockServer,
|
||||
}),
|
||||
refetchInterval: null,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
|
||||
Reference in new issue
Block a user