Updates and more
This commit is contained in:
11
src/components/PlayerCount.svelte
Normal file
11
src/components/PlayerCount.svelte
Normal file
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
|
||||
import {server} from "./stores/server.ts";
|
||||
</script>
|
||||
|
||||
{#await $server}
|
||||
{:then data}
|
||||
{data.players.online}
|
||||
{:catch error}
|
||||
Error
|
||||
{/await}
|
||||
19
src/components/ServerStatus.svelte
Normal file
19
src/components/ServerStatus.svelte
Normal file
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
import { t } from "astro-i18n"
|
||||
import {server} from "./stores/server.ts";
|
||||
|
||||
function generateVersionString(version: string): string {
|
||||
let versions = version.split(" ").slice(1)
|
||||
return `${versions[0].replace(",", "")} - ${versions[versions.length - 1]}`
|
||||
}
|
||||
</script>
|
||||
|
||||
{#await $server}
|
||||
<p>{t("status.loading")}</p>
|
||||
{:then data}
|
||||
<h2>{t("status.status")}: <span class="text-green-500">{t("status.online")}</span></h2>
|
||||
<h2>{t("status.players", { count: `${data.players.online}/${data.players.max}`})}</h2>
|
||||
<h2>{t("status.version", { version: generateVersionString(data.version.name)})}</h2>
|
||||
{:catch error}
|
||||
<h1>{t("status.status")}: <span class="text-red-500">{t("status.offline")}</span></h1>
|
||||
{/await}
|
||||
@@ -33,7 +33,7 @@ export function cachedFamily<T, K>(normal: K, init: (arg0: T) => Promise<K>): (a
|
||||
const stores: Map<T, Cached<K>> = new Map();
|
||||
return (arg: T) => {
|
||||
if(stores.has(arg)) {
|
||||
return stores.get(arg);
|
||||
return stores.get(arg)!!;
|
||||
} else {
|
||||
const store = writable<K>(normal);
|
||||
let first = true;
|
||||
|
||||
4
src/components/stores/server.ts
Normal file
4
src/components/stores/server.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import {readable} from "svelte/store";
|
||||
import type {Readable} from "svelte/store";
|
||||
|
||||
export const server = readable(fetch(import.meta.env.PUBLIC_API_SERVER + "/data/server").then(res => res.json()))
|
||||
Reference in New Issue
Block a user