feat(dashboard): add news
This commit is contained in:
parent
ce323096e6
commit
92e7e1f1cb
5 changed files with 73 additions and 5 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||||
"@sveltestrap/sveltestrap": "^6.2.7",
|
"@sveltestrap/sveltestrap": "^6.2.7",
|
||||||
"@types/eslint": "^9.6.0",
|
"@types/eslint": "^9.6.0",
|
||||||
|
"@types/luxon": "^3.4.2",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
"eslint": "^9.0.0",
|
"eslint": "^9.0.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
|
@ -33,5 +34,8 @@
|
||||||
"vite": "^5.0.3",
|
"vite": "^5.0.3",
|
||||||
"vite-plugin-markdown": "^2.2.0"
|
"vite-plugin-markdown": "^2.2.0"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"luxon": "^3.5.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,3 +137,17 @@ export type GuildChannelConfig = {
|
||||||
message_delete: string;
|
message_delete: string;
|
||||||
message_delete_bulk: string;
|
message_delete_bulk: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Meta = {
|
||||||
|
guilds: number;
|
||||||
|
invite_url: string;
|
||||||
|
news: NewsMessage[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NewsMessage = {
|
||||||
|
author: string;
|
||||||
|
content: string;
|
||||||
|
attachment_urls: string[];
|
||||||
|
posted_at: string;
|
||||||
|
edited_at: string | null;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import apiFetch from "$lib/api";
|
import apiFetch, { type Meta, type NewsMessage } from "$lib/api";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
import { Button, ButtonGroup } from "@sveltestrap/sveltestrap";
|
import { Button, ButtonGroup } from "@sveltestrap/sveltestrap";
|
||||||
|
import Message from "./Message.svelte";
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
let guildCount: number | null = null;
|
let guildCount: number | null = null;
|
||||||
let inviteUrl: string | null = null;
|
let inviteUrl: string | null = null;
|
||||||
|
let news: NewsMessage[] = [];
|
||||||
type MetaResponse = { guilds: number; invite_url: string };
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const meta = await apiFetch<MetaResponse>("GET", "/api/meta");
|
const meta = await apiFetch<Meta>("GET", "/api/meta");
|
||||||
guildCount = meta.guilds;
|
guildCount = meta.guilds;
|
||||||
inviteUrl = meta.invite_url;
|
inviteUrl = meta.invite_url;
|
||||||
|
news = meta.news;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -59,3 +60,11 @@
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<h2>News</h2>
|
||||||
|
|
||||||
|
{#each news as message (message.posted_at)}
|
||||||
|
<Message {message} />
|
||||||
|
{:else}
|
||||||
|
<p>No news right now.</p>
|
||||||
|
{/each}
|
||||||
|
|
|
||||||
31
Catalogger.Frontend/src/routes/Message.svelte
Normal file
31
Catalogger.Frontend/src/routes/Message.svelte
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import type { NewsMessage } from "$lib/api";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardBody,
|
||||||
|
CardFooter,
|
||||||
|
CardText,
|
||||||
|
} from "@sveltestrap/sveltestrap";
|
||||||
|
import { DateTime } from "luxon";
|
||||||
|
|
||||||
|
export let message: NewsMessage;
|
||||||
|
|
||||||
|
$: postedAt = DateTime.fromISO(message.posted_at).toLocaleString(
|
||||||
|
DateTime.DATETIME_MED,
|
||||||
|
);
|
||||||
|
$: editedAt = message.edited_at
|
||||||
|
? DateTime.fromISO(message.edited_at).toLocaleString(DateTime.DATETIME_MED)
|
||||||
|
: null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardBody>
|
||||||
|
<CardText>{message.content}</CardText>
|
||||||
|
</CardBody>
|
||||||
|
<CardFooter>
|
||||||
|
From {message.author} • Posted {postedAt}
|
||||||
|
{#if editedAt}
|
||||||
|
<p class="text-muted">(edited {editedAt})</p>
|
||||||
|
{/if}
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
|
@ -505,6 +505,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
|
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
|
||||||
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
|
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
|
||||||
|
|
||||||
|
"@types/luxon@^3.4.2":
|
||||||
|
version "3.4.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.4.2.tgz#e4fc7214a420173cea47739c33cdf10874694db7"
|
||||||
|
integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==
|
||||||
|
|
||||||
"@typescript-eslint/eslint-plugin@8.9.0":
|
"@typescript-eslint/eslint-plugin@8.9.0":
|
||||||
version "8.9.0"
|
version "8.9.0"
|
||||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.9.0.tgz#bf0b25305b0bf014b4b194a6919103d7ac2a7907"
|
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.9.0.tgz#bf0b25305b0bf014b4b194a6919103d7ac2a7907"
|
||||||
|
|
@ -1278,6 +1283,11 @@ lodash.merge@^4.6.2:
|
||||||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
||||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||||
|
|
||||||
|
luxon@^3.5.0:
|
||||||
|
version "3.5.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.5.0.tgz#6b6f65c5cd1d61d1fd19dbf07ee87a50bf4b8e20"
|
||||||
|
integrity sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==
|
||||||
|
|
||||||
magic-string@^0.30.10, magic-string@^0.30.4, magic-string@^0.30.5:
|
magic-string@^0.30.10, magic-string@^0.30.4, magic-string@^0.30.5:
|
||||||
version "0.30.12"
|
version "0.30.12"
|
||||||
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.12.tgz#9eb11c9d072b9bcb4940a5b2c2e1a217e4ee1a60"
|
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.12.tgz#9eb11c9d072b9bcb4940a5b2c2e1a217e4ee1a60"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue