diff --git a/src/app/common/hastebin.ts b/src/app/common/hastebin.ts new file mode 100644 index 0000000..221a9d6 --- /dev/null +++ b/src/app/common/hastebin.ts @@ -0,0 +1,17 @@ +const HASTE_URL: string = "https://haste.fascinated.cc"; + +/** + * Creates a new haste with the given content. + * + * @param content the content to create the haste with + * @returns the URL of the created haste + */ +export async function createHaste(content: string): Promise { + const response = await fetch(`${HASTE_URL}/documents`, { + method: "POST", + body: content, + }); + + const { key } = await response.json(); + return `${HASTE_URL}/${key}`; +} diff --git a/src/app/components/code-dialog.tsx b/src/app/components/code-dialog.tsx index 83e13ff..fb83043 100644 --- a/src/app/components/code-dialog.tsx +++ b/src/app/components/code-dialog.tsx @@ -1,6 +1,15 @@ import { ReactElement } from "react"; import { CodeHighlighter } from "./code-highlighter"; -import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "./ui/dialog"; +import { CreateHasteButton } from "@/app/components/create-haste-button"; type CodeDialogProps = { /** @@ -28,12 +37,15 @@ export function CodeDialog({ title, description, code, children }: CodeDialogPro return ( {children} - + {title} {description} + + + ); diff --git a/src/app/components/create-haste-button.tsx b/src/app/components/create-haste-button.tsx new file mode 100644 index 0000000..57f527f --- /dev/null +++ b/src/app/components/create-haste-button.tsx @@ -0,0 +1,21 @@ +"use client"; + +import { ReactElement } from "react"; +import { Button } from "@/app/components/ui/button"; +import { CreateHasteButtonProps } from "@/app/types/create-haste-button"; +import { createHaste } from "@/app/common/hastebin"; + +export function CreateHasteButton({ content }: CreateHasteButtonProps): ReactElement { + /** + * Uploads the content to Haste and opens the URL in a new tab. + */ + async function upload(): Promise { + const url = await createHaste(content); + console.log(url); + + // Open the URL in a new tab. + window.open(url, "_blank", "noopener,noreferrer"); + } + + return ; +} diff --git a/src/app/components/player/player-view.tsx b/src/app/components/player/player-view.tsx index 0d1dc8c..a0b724f 100644 --- a/src/app/components/player/player-view.tsx +++ b/src/app/components/player/player-view.tsx @@ -8,6 +8,7 @@ import { Separator } from "../ui/separator"; import { SkinPartImage } from "./skin-part-image"; import { CacheInformation } from "@/app/components/cache-information"; import { PlayerSkin } from "@/app/components/player/player-skin"; +import { ReloadPageButton } from "@/app/components/reload-page-button"; type PlayerViewProps = { /** @@ -38,6 +39,7 @@ export function PlayerView({ player }: PlayerViewProps): ReactElement {
+ + + + + +

Reload the page

+
+ + ); +} diff --git a/src/app/components/server/server-view.tsx b/src/app/components/server/server-view.tsx index af7bd20..b7f58a4 100644 --- a/src/app/components/server/server-view.tsx +++ b/src/app/components/server/server-view.tsx @@ -4,6 +4,7 @@ import { ReactElement } from "react"; import { CodeDialog } from "../code-dialog"; import { Button } from "../ui/button"; import { CacheInformation } from "@/app/components/cache-information"; +import { ReloadPageButton } from "@/app/components/reload-page-button"; type ServerViewProps = { /** @@ -30,6 +31,7 @@ export function ServerView({ server, favicon }: ServerViewProps): ReactElement { />
+