This repository has been archived on 2024-06-01. You can view files and clone it, but cannot push or open issues or pull requests.

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-24 17:46:47 +01:00
import React, { ReactElement } from "react";
2024-04-23 03:22:31 +01:00
import { ActionMenu } from "@/app/components/action-menu";
2024-04-23 03:39:17 +01:00
import { Metadata } from "next";
import moment from "moment";
2024-04-23 03:49:14 +01:00
import { notFound } from "next/navigation";
import { CodeBlock } from "@/app/components/code-block";
import { Button } from "@/app/components/ui/button";
import Link from "next/link";
2024-04-24 17:46:47 +01:00
import {
generatePasteMetadata,
getPaste,
type Paste,
} from "@/app/common/pastes";
import { PastePageProps } from "@/app/types/paste-page";
2024-04-23 17:22:29 +01:00
export async function generateMetadata({
params: { id },
2024-04-24 17:46:47 +01:00
}: PastePageProps): Promise<Metadata> {
return generatePasteMetadata(id);
2024-04-23 03:22:31 +01:00
}
export default async function Paste({
params: { id },
2024-04-24 17:46:47 +01:00
}: PastePageProps): Promise<ReactElement> {
2024-04-23 17:22:29 +01:00
const data: Paste | undefined = await getPaste(id);
2024-04-23 03:22:31 +01:00
2024-04-23 03:49:14 +01:00
if (data == undefined) {
return notFound();
2024-04-23 03:22:31 +01:00
}
2024-04-23 21:59:22 +01:00
const created = moment(data.created)
.format("MMMM Do YYYY, h:mm:ss a")
.toString();
2024-04-23 03:22:31 +01:00
return (
2024-04-23 21:59:22 +01:00
<div className="relative h-full">
<ActionMenu>
<Link href={"/"}>
<Button>New</Button>
</Link>
2024-04-24 17:46:47 +01:00
<Link href={`/raw/${id}`}>
<Button>Raw</Button>
</Link>
</ActionMenu>
2024-04-23 21:59:22 +01:00
<div className="absolute right-0 bottom-0 text-right p-1.5">
2024-04-23 17:22:29 +01:00
<p>{data.language}</p>
2024-04-23 21:59:22 +01:00
<p>{created}</p>
2024-04-23 17:22:29 +01:00
</div>
2024-04-23 03:22:31 +01:00
<div className="p-1 hljs !bg-transparent text-sm">
<CodeBlock code={data.content} language={data.language} />
</div>
2024-04-23 03:22:31 +01:00
</div>
);
}