|
1 |
| -import { Dialog, Transition } from '@headlessui/react'; |
| 1 | +import { Dialog } from '@headlessui/react'; |
2 | 2 | import prettier from 'prettier';
|
3 | 3 | import babelParser from 'prettier/parser-babel';
|
4 | 4 | import React, { useRef, useState } from 'react';
|
| 5 | +import Modal from '../Modal'; |
5 | 6 | import CopyButton from './CopyButton';
|
6 | 7 | import parse, { parsers } from './parsers/parse';
|
7 | 8 | async function getHtml(url: string): Promise<string> {
|
@@ -52,77 +53,52 @@ ${Object.keys(parsers)
|
52 | 53 | setStatus('Get Metadata');
|
53 | 54 | }
|
54 | 55 | }
|
55 |
| -export default function AddProblemModal({ isOpen, onClose }) { |
| 56 | +export default function AddProblemModal(props: { |
| 57 | + isOpen: boolean; |
| 58 | + onClose: () => void; |
| 59 | +}) { |
56 | 60 | const linkRef = useRef<HTMLInputElement>(null);
|
57 | 61 | const [metadata, setMetadata] = useState('// metadata will appear here');
|
58 | 62 | const [status, setStatus] = useState('Get Metadata');
|
59 | 63 | return (
|
60 |
| - <Transition appear show={isOpen} as={React.Fragment}> |
61 |
| - <Dialog as="div" className="relative z-10" onClose={onClose}> |
62 |
| - <Transition.Child |
63 |
| - as={React.Fragment} |
64 |
| - enter="ease-out duration-300" |
65 |
| - enterFrom="opacity-0" |
66 |
| - enterTo="opacity-100" |
67 |
| - leave="ease-in duration-200" |
68 |
| - leaveFrom="opacity-100" |
69 |
| - leaveTo="opacity-0" |
70 |
| - > |
71 |
| - <div className="fixed inset-0 bg-black/25" /> |
72 |
| - </Transition.Child> |
73 |
| - |
74 |
| - <div className="fixed inset-0 overflow-y-auto"> |
75 |
| - <div className="flex min-h-full items-center justify-center p-4 text-center"> |
76 |
| - <Transition.Child |
77 |
| - as={React.Fragment} |
78 |
| - enter="ease-out duration-300" |
79 |
| - enterFrom="opacity-0 scale-95" |
80 |
| - enterTo="opacity-100 scale-100" |
81 |
| - leave="ease-in duration-200" |
82 |
| - leaveFrom="opacity-100 scale-100" |
83 |
| - leaveTo="opacity-0 scale-95" |
84 |
| - > |
85 |
| - <Dialog.Panel className="w-full max-w-md transform overflow-hidden rounded-2xl bg-black text-white p-6 text-left align-middle shadow-xl transition-all"> |
86 |
| - <Dialog.Title as="h3" className="text-lg font-medium leading-6"> |
87 |
| - Add Problem |
88 |
| - </Dialog.Title> |
89 |
| - <div className="mt-2 relative rounded-md shadow-sm"> |
90 |
| - <input |
91 |
| - type="text" |
92 |
| - className="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md dark:bg-gray-900 dark:border-gray-700" |
93 |
| - placeholder="Enter Problem URL" |
94 |
| - onChange={e => console.log(e.target.value)} |
95 |
| - ref={linkRef} |
96 |
| - /> |
97 |
| - </div> |
| 64 | + <Modal {...props}> |
| 65 | + <Dialog.Panel className="w-full max-w-2xl transform overflow-hidden rounded-2xl bg-black text-white p-6 text-left align-middle shadow-xl transition-all"> |
| 66 | + <Dialog.Title as="h3" className="text-lg font-medium leading-6"> |
| 67 | + Add Problem |
| 68 | + </Dialog.Title> |
| 69 | + <div className="mt-2 relative rounded-md shadow-sm"> |
| 70 | + <input |
| 71 | + type="text" |
| 72 | + className="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md dark:bg-gray-900 dark:border-gray-700" |
| 73 | + placeholder="Enter Problem URL" |
| 74 | + onChange={e => console.log(e.target.value)} |
| 75 | + ref={linkRef} |
| 76 | + /> |
| 77 | + </div> |
98 | 78 |
|
99 |
| - <div className="mt-4"> |
100 |
| - <button |
101 |
| - className="btn" |
102 |
| - onClick={() => |
103 |
| - linkRef.current && |
104 |
| - addProblem(linkRef.current.value, setMetadata, setStatus) |
105 |
| - } |
106 |
| - > |
107 |
| - {status} |
108 |
| - </button> |
109 |
| - </div> |
110 |
| - <div className="mt-4 relative"> |
111 |
| - <pre className="bg-gray-900 p-4 rounded-md text-white text-xs whitespace-pre-wrap"> |
112 |
| - {metadata} |
113 |
| - </pre> |
114 |
| - <CopyButton |
115 |
| - className="btn absolute top-2 right-2" |
116 |
| - onClick={() => { |
117 |
| - navigator.clipboard.writeText(metadata); |
118 |
| - }} |
119 |
| - /> |
120 |
| - </div> |
121 |
| - </Dialog.Panel> |
122 |
| - </Transition.Child> |
123 |
| - </div> |
| 79 | + <div className="mt-4"> |
| 80 | + <button |
| 81 | + className="btn" |
| 82 | + onClick={() => |
| 83 | + linkRef.current && |
| 84 | + addProblem(linkRef.current.value, setMetadata, setStatus) |
| 85 | + } |
| 86 | + > |
| 87 | + {status} |
| 88 | + </button> |
| 89 | + </div> |
| 90 | + <div className="mt-4 relative"> |
| 91 | + <pre className="bg-gray-900 p-4 rounded-md text-white text-sm whitespace-pre-wrap"> |
| 92 | + {metadata} |
| 93 | + </pre> |
| 94 | + <CopyButton |
| 95 | + className="btn absolute top-2 right-2" |
| 96 | + onClick={() => { |
| 97 | + navigator.clipboard.writeText(metadata); |
| 98 | + }} |
| 99 | + /> |
124 | 100 | </div>
|
125 |
| - </Dialog> |
126 |
| - </Transition> |
| 101 | + </Dialog.Panel> |
| 102 | + </Modal> |
127 | 103 | );
|
128 | 104 | }
|
0 commit comments