1- import { Card , CardBody , CardHeader , CardProps , Divider , mergeClasses , Skeleton , Snippet } from "@heroui/react"
21import React from "react"
3- import { PasteResponse } from "../../shared/interfaces.js"
2+
3+ import { Card , CardBody , CardHeader , CardProps , CircularProgress , Divider , Input , mergeClasses } from "@heroui/react"
4+
5+ import type { PasteResponse } from "../../shared/interfaces.js"
46import { tst } from "../utils/overrides.js"
7+ import { CopyWidget } from "./CopyWidget.js"
58
69interface UploadedPanelProps extends CardProps {
710 isLoading : boolean
8- pasteResponse : PasteResponse | null
9- encryptionKey : string | null
11+ loadingProgress ?: number
12+ pasteResponse ?: PasteResponse
13+ encryptionKey ?: string
1014}
1115
1216const makeDecryptionUrl = ( url : string , key : string ) => {
@@ -15,62 +19,79 @@ const makeDecryptionUrl = (url: string, key: string) => {
1519 return urlParsed . toString ( ) + "#" + key
1620}
1721
18- export function UploadedPanel ( { isLoading, pasteResponse, className, encryptionKey, ...rest } : UploadedPanelProps ) {
19- const snippetClassNames = {
20- pre : `overflow-scroll leading-[2.5] font-sans ${ tst } ` ,
21- base : `w-full py-1/3 ${ tst } ` ,
22- copyButton : `relative ml-[-12pt] left-[5pt] ${ tst } ` ,
22+ export function UploadedPanel ( {
23+ isLoading,
24+ loadingProgress,
25+ pasteResponse,
26+ className,
27+ encryptionKey,
28+ ...rest
29+ } : UploadedPanelProps ) {
30+ const copyWidgetClassNames = `bg-transparent ${ tst } translate-y-[10%]`
31+ const inputProps = {
32+ "aria-labelledby" : "" ,
33+ readOnly : true ,
34+ className : "mb-2" ,
2335 }
24- const firstColClassNames = "w-[8rem] mr-4 whitespace-nowrap"
36+
2537 return (
2638 < Card classNames = { mergeClasses ( { base : tst } , { base : className } ) } { ...rest } >
27- < CardHeader className = "text-2xl" > Uploaded Paste</ CardHeader >
39+ < CardHeader className = "text-2xl pl-4 pb-2 " > Uploaded Paste</ CardHeader >
2840 < Divider />
2941 < CardBody >
30- < table className = "border-spacing-2 border-separate table-fixed w-full" >
31- < tbody >
32- < tr >
33- < td className = { firstColClassNames } > Paste URL</ td >
34- < td className = "w-full" >
35- < Skeleton isLoaded = { ! isLoading } className = "rounded-2xl grow" >
36- < Snippet hideSymbol variant = "bordered" classNames = { snippetClassNames } >
37- { pasteResponse ?. url }
38- </ Snippet >
39- </ Skeleton >
40- </ td >
41- </ tr >
42- < tr >
43- < td className = { firstColClassNames } > Manage URL</ td >
44- < td className = "w-full" >
45- < Skeleton isLoaded = { ! isLoading } className = "rounded-2xl grow" >
46- < Snippet hideSymbol variant = "bordered" classNames = { snippetClassNames } >
47- { pasteResponse ?. manageUrl }
48- </ Snippet >
49- </ Skeleton >
50- </ td >
51- </ tr >
52- { encryptionKey ? (
53- < tr >
54- < td className = { firstColClassNames } > Decryption URL</ td >
55- < td className = "w-full" >
56- < Skeleton isLoaded = { ! isLoading } className = "rounded-2xl grow" >
57- < Snippet hideSymbol variant = "bordered" classNames = { snippetClassNames } >
58- { pasteResponse && makeDecryptionUrl ( pasteResponse . url , encryptionKey ) }
59- </ Snippet >
60- </ Skeleton >
61- </ td >
62- </ tr >
63- ) : null }
64- < tr >
65- < td className = { firstColClassNames } > Expire At</ td >
66- < td className = "w-full py-2" >
67- < Skeleton isLoaded = { ! isLoading } className = "rounded-2xl" >
68- { pasteResponse && new Date ( pasteResponse . expireAt ) . toLocaleString ( ) }
69- </ Skeleton >
70- </ td >
71- </ tr >
72- </ tbody >
73- </ table >
42+ { isLoading ? (
43+ < div className = { "min-h-[5rem] w-full relative" } >
44+ < CircularProgress
45+ aria-label = { "Loading..." }
46+ value = { loadingProgress }
47+ className = { "absolute top-[50%] left-[50%] translate-[-50%]" }
48+ />
49+ </ div >
50+ ) : (
51+ pasteResponse && (
52+ < >
53+ { encryptionKey && (
54+ < Input
55+ { ...inputProps }
56+ label = { "Decryption URL" }
57+ color = { "success" }
58+ value = { makeDecryptionUrl ( pasteResponse . url , encryptionKey ) }
59+ endContent = {
60+ < CopyWidget
61+ className = { copyWidgetClassNames }
62+ getCopyContent = { ( ) => makeDecryptionUrl ( pasteResponse . url , encryptionKey ) }
63+ />
64+ }
65+ />
66+ ) }
67+ < Input
68+ { ...inputProps }
69+ label = { "Paste URL" }
70+ value = { pasteResponse . url }
71+ endContent = { < CopyWidget className = { copyWidgetClassNames } getCopyContent = { ( ) => pasteResponse . url } /> }
72+ />
73+ < Input
74+ { ...inputProps }
75+ label = { "Manage URL" }
76+ value = { pasteResponse . manageUrl }
77+ endContent = {
78+ < CopyWidget className = { copyWidgetClassNames } getCopyContent = { ( ) => pasteResponse . manageUrl } />
79+ }
80+ />
81+ { pasteResponse . suggestedUrl && (
82+ < Input
83+ { ...inputProps }
84+ label = { "Suggest URL" }
85+ value = { pasteResponse . suggestedUrl }
86+ endContent = {
87+ < CopyWidget className = { copyWidgetClassNames } getCopyContent = { ( ) => pasteResponse . suggestedUrl ! } />
88+ }
89+ />
90+ ) }
91+ < Input { ...inputProps } label = { "Expiration" } value = { new Date ( pasteResponse . expireAt ) . toLocaleString ( ) } />
92+ </ >
93+ )
94+ ) }
7495 </ CardBody >
7596 </ Card >
7697 )
0 commit comments