add QRCode

This commit is contained in:
Philipp Traber
2024-10-20 18:42:53 +02:00
parent 34b1d33ffb
commit c49e1b6020
8 changed files with 358 additions and 25 deletions
+3 -3
View File
@@ -7,11 +7,11 @@ body {
}
h1 {
@apply text-5xl font-bold mb-6;
@apply text-5xl font-bold;
}
h2 {
@apply text-2xl font-bold mb-4;
@apply text-2xl font-bold;
}
.form-group {
@@ -51,7 +51,7 @@ button {
}
.zebra {
@apply odd:bg-slate-800 p-2 rounded;
@apply even:bg-slate-800 p-2 rounded;
}
.common-red {
+18 -10
View File
@@ -8,6 +8,7 @@ import LinkFavicon from "@/components/LinkFavicon";
import { hashToColor } from "@/utils";
import PinPageToRootForm from "@/components/forms/pinPageToRootForm";
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/solid";
import QRCode from "@/components/QRCode";
interface PageProps {
params: Promise<{
@@ -68,7 +69,8 @@ export default async function DetailedStats({ params }: PageProps) {
return (
<div>
<div className="flex items-center">
<div className="flex justify-between max-sm:flex-col mb-10">
<div className="flex">
{redirectPage || customPage.image ?
<div className=" h-10 w-10 mr-4 ">
{redirectPage ? <LinkFavicon url={redirectPage.dest} /> :
@@ -90,8 +92,12 @@ export default async function DetailedStats({ params }: PageProps) {
<div className="ml-5">
{page.pinnedPage ? <p className="common-red">Pinned to root</p> : ""}
</div>
<div className="ml-auto">
<Link href={`/${page.shortcode}`}><button><ArrowTopRightOnSquareIcon className="button-icon" /></button></Link>
</div>
<div className="flex max-sm:mt-5">
<div className="">
<Link href={`/${page.shortcode}`} target="blank"><button><ArrowTopRightOnSquareIcon className="button-icon" /></button></Link>
</div>
<div className="ml-5">
<PinPageToRootForm pageUuid={page.uuid} pinned={!!page.pinnedPage} />
@@ -99,18 +105,20 @@ export default async function DetailedStats({ params }: PageProps) {
<div className="ml-5">
<DeletePageForm uuid={page.uuid} />
</div>
</div>
</div>
<div className="mb-10">
<QRCode url={page.shortcode} />
</div>
<br className="mt-2"></br>
{customPage ? <CustomPageDashboard customPage={customPage} /> : ""}
<h2 className="mt-5">Stats</h2>
<p className="mt-5">All visits (not unique): {page._count.stat}</p>
<br></br>
<h2>Visitors</h2>
<h2 className="mt-10">Visitors</h2>
<p className="my-2">All visits (not unique): {page._count.stat}</p>
{stats.map((stat) => (<div className="zebra" key={stat.hash}>
<p>{stat.userAgent}</p>
<p style={{ color: hashToColor(stat.hash) }}>{stat.hash}</p>
<p style={{ color: hashToColor(stat.hash) }}>{stat.userAgent}</p>
<p>Visits: {"" + stat._count.uuid}</p>
<p>Last Visit: {stat._max.accessedAt?.toDateString()}</p>
</div>))}
+3 -2
View File
@@ -20,12 +20,13 @@ export default async function Dashboard({ children }: { children: ReactNode }) {
return (
<div className='p-10 max-w-7xl mx-auto'>
<div className='flex justify-top'>
<div className='flex justify-between max-sm:flex-col mb-10'>
<Link href="/~/dash/">
<h1>Dashboard</h1>
</Link>
<div className="ml-auto flex flex-col">
<div className="flex flex-col max-sm:mt-5 justify-start">
{user?.name ? <>
<div>{user?.name || user.email}</div>
<SignOutButton /></> : ""}
+2 -1
View File
@@ -23,6 +23,7 @@ export default async function CustomPageDashboard(params: { customPage: CustomPa
});
return (<>
<h2>Links on Page</h2>
{linkBlocks.map((block) => (
<div key={block.uuid} className="flex items-center justify-center mb-2 zebra">
@@ -44,7 +45,7 @@ export default async function CustomPageDashboard(params: { customPage: CustomPa
</div>
</div>
))}
<h2>Add new link page connection</h2>
<h2 className="mt-10">Add new link page connection</h2>
<CreateLinkBlockForm customPage={customPage.uuid} shortcodes={shortcodes || []} />
</>
+59
View File
@@ -0,0 +1,59 @@
"use client"
import { useQRCode } from "next-qrcode"
import { useState } from "react";
export default function QRCode({ url }: { url: string }) {
const { Canvas } = useQRCode();
const values = ['L', 'M', 'Q', 'H'];
const [errorCorrectionLevel, setErrorCorrectionLevel] = useState(2);
const [dark, setDark] = useState('#000000');
const [light, setLight] = useState('#FFFFFF');
return (<>
<div className="flex justify-between max-sm:flex-col">
<div className="flex justify-between flex-col">
<h2>QR Code</h2>
<span className="flex items-center justify-between"> Error Correction Level:
<div className="flex justify-between">
{values.map((value, index) => (
<span
key={index}
className={`mx-2 ${errorCorrectionLevel === index ? 'text-white' : 'text-gray-400'}`}
onClick={() => setErrorCorrectionLevel(index)}>
{value}
</span>
))}
</div>
</span>
<span className="flex items-center justify-between">
Dark:
<input type="color" className="ml-3 w-5 h-5 p-0" value={dark} onChange={(e) => setDark(e.target.value)} />
</span>
<span className="flex items-center justify-between">
Light:
<input type="color" className="ml-3 w-5 h-5 p-0" value={light} onChange={(e) => setLight(e.target.value)} />
</span>
</div>
<div className="max-sm:mt-5">
<Canvas
text={"https://"+ window.location.host + "/" + url}
options={{
errorCorrectionLevel: values[errorCorrectionLevel],
width: 150,
color: {
dark: dark,
light: light
}
}}
/>
</div>
</div>
</>
)
}
+2 -2
View File
@@ -3,13 +3,13 @@ import { signOut } from "@/auth"
export default function SignOutButton() {
return (
<form
className="flex"
className="flex m-0 p-0"
action={async () => {
"use server"
await signOut()
}}
>
<button className='ml-auto bg-transparent p-1 hover:underline hover:bg-transparent' type="submit">logout</button>
<button className='max-sm:ml-0 ml-auto bg-transparent p-0 hover:underline hover:bg-transparent' type="submit">logout</button>
</form>
)
}