mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
commit
f0eb66c1cd
@ -7,18 +7,25 @@ import useSWR from "swr";
|
|||||||
|
|
||||||
export default function ServerListClient() {
|
export default function ServerListClient() {
|
||||||
const { data } = useSWR<ServerApi>("/api/server", nezhaFetcher, {
|
const { data } = useSWR<ServerApi>("/api/server", nezhaFetcher, {
|
||||||
refreshInterval: process.env.NEXT_PUBLIC_NezhaFetchInterval
|
refreshInterval: Number(process.env.NEXT_PUBLIC_NezhaFetchInterval) || 2000,
|
||||||
? Number(process.env.NEXT_PUBLIC_NezhaFetchInterval)
|
|
||||||
: 2000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data) return null;
|
if (!data) return null;
|
||||||
const sortedResult = data.result.sort((a, b) => a.id - b.id);
|
|
||||||
|
const sortedServers = data.result.sort((a, b) => {
|
||||||
|
if (a.display_index && b.display_index) {
|
||||||
|
return b.display_index - a.display_index;
|
||||||
|
}
|
||||||
|
if (a.display_index) return -1;
|
||||||
|
if (b.display_index) return 1;
|
||||||
|
return a.id - b.id;
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={"grid grid-cols-1 gap-2 md:grid-cols-2"}>
|
<section className="grid grid-cols-1 gap-2 md:grid-cols-2">
|
||||||
{sortedResult.map((serverInfo) => (
|
{sortedServers.map((serverInfo) => (
|
||||||
<ServerCard key={serverInfo.id} serverInfo={serverInfo} />
|
<ServerCard key={serverInfo.id} serverInfo={serverInfo} />
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -16,6 +16,7 @@ export interface NezhaAPI {
|
|||||||
ipv4: string;
|
ipv4: string;
|
||||||
ipv6: string;
|
ipv6: string;
|
||||||
valid_ip: string;
|
valid_ip: string;
|
||||||
|
display_index: number;
|
||||||
host: NezhaAPIHost;
|
host: NezhaAPIHost;
|
||||||
status: NezhaAPIStatus;
|
status: NezhaAPIStatus;
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,9 @@ export default function ServerCard({
|
|||||||
{getUnicodeFlagIcon(country_code)}
|
{getUnicodeFlagIcon(country_code)}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-[12px] text-muted-foreground">🏴☠️</span>
|
<span className="text-[12px] text-muted-foreground">🏁</span>
|
||||||
)
|
)
|
||||||
) : null}
|
) : null}
|
||||||
<span className="h-2 w-2 shrink-0 rounded-full bg-green-500"></span>
|
|
||||||
<p
|
<p
|
||||||
className={cn(
|
className={cn(
|
||||||
"break-all font-bold tracking-tight",
|
"break-all font-bold tracking-tight",
|
||||||
@ -47,6 +46,7 @@ export default function ServerCard({
|
|||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</p>
|
</p>
|
||||||
|
<span className="h-2 w-2 shrink-0 rounded-full bg-green-500"></span>
|
||||||
</section>
|
</section>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent side="top">
|
<PopoverContent side="top">
|
||||||
@ -94,10 +94,9 @@ export default function ServerCard({
|
|||||||
{getUnicodeFlagIcon(country_code)}
|
{getUnicodeFlagIcon(country_code)}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-[12px] text-muted-foreground">🏴☠️</span>
|
<span className="text-[12px] text-muted-foreground">🏁</span>
|
||||||
)
|
)
|
||||||
) : null}
|
) : null}
|
||||||
<span className="h-2 w-2 shrink-0 rounded-full bg-red-500"></span>
|
|
||||||
<p
|
<p
|
||||||
className={cn(
|
className={cn(
|
||||||
"break-all font-bold tracking-tight",
|
"break-all font-bold tracking-tight",
|
||||||
@ -106,6 +105,7 @@ export default function ServerCard({
|
|||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</p>
|
</p>
|
||||||
|
<span className="h-2 w-2 shrink-0 rounded-full bg-red-500"></span>
|
||||||
</section>
|
</section>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-fit p-2" side="top">
|
<PopoverContent className="w-fit p-2" side="top">
|
||||||
|
Loading…
Reference in New Issue
Block a user