mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
add functionality to pin page && refactoring
This commit is contained in:
@@ -14,12 +14,12 @@ export default async function CustomPageComponent(params: { customPage: CustomPa
|
||||
order: "asc"
|
||||
},
|
||||
include: {
|
||||
redirect_page: { include: { page: true } }
|
||||
redirectPage: { include: { page: true } }
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<div className="flex flex-col items-center justify-center min-h-screen">
|
||||
<Image
|
||||
src={`data:image/png;base64,${customPage.image}`}
|
||||
alt=" "
|
||||
@@ -29,13 +29,13 @@ export default async function CustomPageComponent(params: { customPage: CustomPa
|
||||
/>
|
||||
|
||||
<h1 className="mt-5 text-center">{customPage.title}</h1>
|
||||
<div className="w-full max-w-96">
|
||||
<div className="w-full max-w-96 mb-40 p-2">
|
||||
|
||||
{linkBlocks.map((block) => (
|
||||
<button key={block.uuid} className="bg-slate-600 hover:bg-slate-500 w-full m-2">
|
||||
<a href={`/${block.redirect_page.page.shortcode}`}>
|
||||
<button key={block.uuid} className="bg-slate-600 hover:bg-slate-500 w-full my-2">
|
||||
<a href={`/${block.redirectPage.page.shortcode}`}>
|
||||
<div className="relative flex items-center">
|
||||
<div className="flex-shrink-0"><LinkFavicon url={block.redirect_page.dest} /></div>
|
||||
<div className="flex-shrink-0"><LinkFavicon url={block.redirectPage.dest} /></div>
|
||||
<div className="absolute left-1/2 transform -translate-x-1/2 text-center font-bold">{block.title}</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
@@ -17,25 +17,25 @@ export default async function CustomPageDashboard(params: { customPage: CustomPa
|
||||
order: "asc"
|
||||
},
|
||||
include: {
|
||||
redirect_page: { include: { page: true } }
|
||||
redirectPage: { include: { page: true } }
|
||||
}
|
||||
});
|
||||
|
||||
return (<>
|
||||
{linkBlocks.map((block) => (
|
||||
|
||||
<div key={block.uuid} className="flex items-center justify-center mb-2 odd:bg-slate-800 p-2">
|
||||
<div key={block.uuid} className="flex items-center justify-center mb-2 zebra">
|
||||
<div className="mr-5">order: {block.order}</div>
|
||||
<div className="mr-5">title: <span className="font-bold">{block.title}</span></div>
|
||||
<div>connected link page: <span className="font-bold">{block.redirect_page.page.shortcode}</span></div>
|
||||
<div>connected link page: <span className="font-bold">{block.redirectPage.page.shortcode}</span></div>
|
||||
<div className="ml-auto">
|
||||
<button>
|
||||
<a href={`/${block.redirect_page.page.shortcode}`} className="btn btn-primary">Visit</a>
|
||||
<a href={`/${block.redirectPage.page.shortcode}`} className="btn btn-primary">Visit</a>
|
||||
</button>
|
||||
</div>
|
||||
<div className="ml-5">
|
||||
<button>
|
||||
<a href={`/~/dash/${block.redirect_page.page.uuid}`} className="btn btn-primary">Details</a>
|
||||
<a href={`/~/dash/${block.redirectPage.page.uuid}`} className="btn btn-primary">Details</a>
|
||||
</button>
|
||||
</div>
|
||||
<div className="ml-5">
|
||||
|
||||
@@ -3,7 +3,6 @@ import Image from "next/image";
|
||||
export default function LinkFavicon({ url }: { url: string }) {
|
||||
|
||||
const hostname = new URL(url).hostname;
|
||||
console.log(hostname);
|
||||
|
||||
return (<div className=" h-10 w-10">
|
||||
<Image
|
||||
@@ -11,6 +10,7 @@ export default function LinkFavicon({ url }: { url: string }) {
|
||||
width={100}
|
||||
height={100}
|
||||
alt=" "
|
||||
className="rounded-full"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
import React from 'react';
|
||||
import type { Prisma } from '@prisma/client';
|
||||
import DeletePageForm from './forms/deletePageForm';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
import prisma from '../../prisma/prisma';
|
||||
import LinkFavicon from './LinkFavicon';
|
||||
import PinPageToRootForm from './forms/pinPageToRootForm';
|
||||
|
||||
type PageWithRelations = Prisma.PageGetPayload<{
|
||||
include: {
|
||||
RedirectPage: true;
|
||||
CustomPage: true;
|
||||
pinnedPage: true;
|
||||
redirectPage: true;
|
||||
customPage: true;
|
||||
_count: {
|
||||
select: { Stat: true }
|
||||
select: { stat: true }
|
||||
}
|
||||
}
|
||||
}>
|
||||
|
||||
export default async function PageListComponent({ page }: { page: PageWithRelations }) {
|
||||
|
||||
const redirectPage = page.RedirectPage[0];
|
||||
const customPage = page.CustomPage[0];
|
||||
const redirectPage = page.redirectPage[0];
|
||||
const customPage = page.customPage[0];
|
||||
|
||||
|
||||
return (
|
||||
<Link href={`/~/dash/${page.uuid}`}>
|
||||
@@ -32,6 +33,7 @@ export default async function PageListComponent({ page }: { page: PageWithRelati
|
||||
height={100}
|
||||
src={`data:image/png;base64,${customPage.image}`}
|
||||
alt="icon"
|
||||
className="rounded-full"
|
||||
/>}
|
||||
</div>
|
||||
<div>
|
||||
@@ -39,8 +41,11 @@ export default async function PageListComponent({ page }: { page: PageWithRelati
|
||||
<p className="text-sm text-gray-400">{redirectPage ? redirectPage.dest : customPage.title}</p>
|
||||
|
||||
</div>
|
||||
<div className="ml-5">
|
||||
{page.pinnedPage ? <p className="text-red-500">Pinned to root</p> : ""}
|
||||
</div>
|
||||
<div className="ml-auto">
|
||||
{page._count.Stat ? <p className="text-gray-400 font-bold">{page._count.Stat} visits</p> : ""}
|
||||
{page._count.stat ? <p className="text-gray-400 font-bold">{page._count.stat} visits</p> : ""}
|
||||
{//<DeletePageForm uuid={page.uuid} />
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
"use client"
|
||||
import { pinPageToRoot } from "@/actions/page_actions";
|
||||
import { BookmarkIcon } from "@heroicons/react/24/solid";
|
||||
import { useActionState, useState } from "react";
|
||||
|
||||
export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: string, disabled: boolean }) {
|
||||
|
||||
const initialState = {
|
||||
message: "",
|
||||
error: {}
|
||||
};
|
||||
|
||||
const [state, formAction] = useActionState(pinPageToRoot, initialState);
|
||||
|
||||
|
||||
return ( <form action={formAction}>
|
||||
<input type="hidden" name="uuid" value={pageUuid} />
|
||||
{/* <p>{state.message}</p> */}
|
||||
<button type="submit" className="btn btn-primary" disabled={disabled}><BookmarkIcon className="h-5 w-5 inline-block align-middle"/></button>
|
||||
</form>)
|
||||
}
|
||||
Reference in New Issue
Block a user