Skip to content

Commit 07a6ca1

Browse files
authored
Merge pull request #9 from anwen/feat/editor
feat: use tiptap editor
2 parents 0f41d4a + 95a204c commit 07a6ca1

30 files changed

+1246
-695
lines changed

.eslintrc.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"space-before-blocks": "error",
66
"space-before-function-paren": [2, "never"],
77
"object-curly-spacing": ["error", "always"],
8-
"indent": ["error", 2]
8+
"indent": ["error", 2],
9+
"max-len": ["error", {
10+
"code": 120,
11+
"ignorePattern": "className"
12+
}]
913
}
1014
}

components/AddLinkDialog.tsx

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Fragment, useState } from 'react'
2+
import { Dialog, Transition } from '@headlessui/react'
3+
4+
interface AddLinkDialogProps {
5+
open: boolean
6+
close(): void
7+
save(url: string): void
8+
}
9+
10+
export function AddLinkDialog({ open, close, save }: AddLinkDialogProps) {
11+
const [url, setUrl] = useState<string>()
12+
13+
return (
14+
<>
15+
<Transition
16+
show={open}
17+
enter="transition duration-100 ease-out"
18+
enterFrom="transform scale-95 opacity-0"
19+
enterTo="transform scale-100 opacity-100"
20+
leave="transition duration-75 ease-out"
21+
leaveFrom="transform scale-100 opacity-100"
22+
leaveTo="transform scale-95 opacity-0"
23+
>
24+
<Dialog
25+
as="div"
26+
className="fixed inset-0 z-10 overflow-y-auto"
27+
onClose={close}
28+
>
29+
<div className="min-h-screen px-4 text-center">
30+
<Transition.Child
31+
as={Fragment}
32+
enter="ease-out duration-300"
33+
enterFrom="opacity-0"
34+
enterTo="opacity-100"
35+
leave="ease-in duration-200"
36+
leaveFrom="opacity-100"
37+
leaveTo="opacity-0"
38+
>
39+
<Dialog.Overlay className="fixed inset-0 bg-grey-100" />
40+
</Transition.Child>
41+
42+
{/* This element is to trick the browser into centering the modal contents. */}
43+
<span
44+
className="inline-block h-screen align-middle"
45+
aria-hidden="true"
46+
>
47+
&#8203;
48+
</span>
49+
<Transition.Child
50+
as={Fragment}
51+
enter="ease-out duration-300"
52+
enterFrom="opacity-0 scale-95"
53+
enterTo="opacity-100 scale-100"
54+
leave="ease-in duration-200"
55+
leaveFrom="opacity-100 scale-100"
56+
leaveTo="opacity-0 scale-95"
57+
>
58+
<div className="inline-block w-full max-w-md p-6 my-8 overflow-hidden text-left align-middle transition-all transform bg-white shadow-xl rounded-2xl">
59+
<Dialog.Title
60+
as="h3"
61+
className="text-lg font-medium leading-6 text-gray-900"
62+
>
63+
Provider a Link
64+
</Dialog.Title>
65+
<div className="mt-2">
66+
<input
67+
onChange={e => setUrl(e.target.value)}
68+
type='text'
69+
placeholder="Link"
70+
className="w-full bg-white rounded border border-gray-300 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out"
71+
/>
72+
</div>
73+
<div className="mt-4">
74+
<button
75+
type="button"
76+
className="inline-flex justify-center px-4 py-2 text-sm font-medium text-blue-900 bg-blue-100 border border-transparent rounded-md hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500"
77+
onClick={() => save(url)}
78+
>
79+
Save
80+
</button>
81+
</div>
82+
</div>
83+
</Transition.Child>
84+
</div>
85+
</Dialog>
86+
</Transition>
87+
</>
88+
)
89+
}

components/ArticleItem.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { memo } from "react"
2+
3+
interface ArticleItemProps {
4+
imageURL: string,
5+
name: string
6+
tags: string
7+
authors: string
8+
path: string
9+
}
10+
11+
export const ArticleItem = memo<ArticleItemProps>(({ imageURL, tags, authors, name, path }) => {
12+
return (
13+
<div className="p-4 md:w-1/3">
14+
<div className="h-full border-2 border-gray-200 border-opacity-60 rounded-lg overflow-hidden">
15+
<img className="lg:h-48 md:h-36 w-full object-cover object-center" src={imageURL} alt={name} />
16+
<div className="p-6">
17+
<h2 className="tracking-widest text-xs title-font font-medium text-gray-400 mb-1">{ tags }</h2>
18+
<h1 className="title-font text-lg font-medium text-gray-900 mb-3">{ name }</h1>
19+
<p className="leading-relaxed mb-3">{ authors }</p>
20+
<div className="flex items-center flex-wrap ">
21+
<a className="text-indigo-500 inline-flex items-center md:mb-2 lg:mb-0" href={"/article?cid=" + path}>Goto
22+
<svg className="w-4 h-4 ml-2" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2"
23+
fill="none" strokeLinecap="round" strokeLinejoin="round">
24+
<path d="M5 12h14"/>
25+
<path d="M12 5l7 7-7 7"/>
26+
</svg>
27+
</a>
28+
</div>
29+
</div>
30+
</div>
31+
</div>
32+
)
33+
})
34+
35+
ArticleItem.displayName = 'ArticleItem'

0 commit comments

Comments
 (0)