|
| 1 | +import * as DialogPrimitive from '@radix-ui/react-dialog'; |
| 2 | +import { PostFullFragment } from '../generated/graphql'; |
| 3 | +import { DEFAULT_AVATAR } from '../utils/const'; |
| 4 | +import { Button } from './button'; |
| 5 | +import { useAppContext } from './contexts/appContext'; |
| 6 | +import CloseSVG from './icons/svgs/CloseSVG'; |
| 7 | +import { ResizableImage } from './resizable-image'; |
| 8 | +import CustomScrollArea from './scroll-area'; |
| 9 | + |
| 10 | +type CoAuthorsModalProps = { |
| 11 | + closeModal: () => void; |
| 12 | +}; |
| 13 | + |
| 14 | +const AuthorCard = ({ author }: { author: PostFullFragment['author'] }) => { |
| 15 | + return ( |
| 16 | + <div className="flex flex-row items-center justify-between" key={author.id.toString()}> |
| 17 | + <div className="flex w-full flex-wrap items-center justify-between overflow-hidden px-0 py-2.5"> |
| 18 | + <div className="flex flex-wrap items-center overflow-hidden"> |
| 19 | + <a |
| 20 | + href={`https://hashnode.com/@${author.username}`} |
| 21 | + title={author.name} |
| 22 | + className="mr-2 w-8" |
| 23 | + > |
| 24 | + <ResizableImage |
| 25 | + src={author.profilePicture || DEFAULT_AVATAR} |
| 26 | + resize={{ w: 200, h: 200, c: 'face' }} |
| 27 | + className="mr-3 h-8 w-8 rounded-full" |
| 28 | + /> |
| 29 | + </a> |
| 30 | + <div className="flex flex-row items-center text-clip"> |
| 31 | + <a |
| 32 | + href={`https://hashnode.com/@${author.username}`} |
| 33 | + title={author.name} |
| 34 | + className="truncate font-sans text-sm font-medium text-slate-700 dark:text-slate-200" |
| 35 | + > |
| 36 | + {author.name} |
| 37 | + </a> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + ); |
| 43 | +}; |
| 44 | + |
| 45 | +export default function CoAuthorsModal({ closeModal }: CoAuthorsModalProps) { |
| 46 | + const { post } = useAppContext(); |
| 47 | + const authors = [post?.author, ...(post?.coAuthors || [])]; |
| 48 | + |
| 49 | + return ( |
| 50 | + <DialogPrimitive.Root open> |
| 51 | + <DialogPrimitive.Portal> |
| 52 | + <DialogPrimitive.Overlay |
| 53 | + onClick={closeModal} |
| 54 | + className="fixed inset-0 z-50 bg-slate-900 opacity-50 transition-opacity duration-300 ease-out dark:bg-slate-600" |
| 55 | + /> |
| 56 | + <DialogPrimitive.Content |
| 57 | + onEscapeKeyDown={closeModal} |
| 58 | + className="md:bottom-50 md:left-50 lg:w-108 xl:w-116 fixed bottom-0 left-0 right-0 z-50 flex w-full max-w-[1200px] flex-col items-center overflow-hidden rounded-b-none rounded-t-lg border-slate-200 bg-white text-slate-700 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-50 md:w-96 md:-translate-x-1/2 md:translate-y-1/2 md:rounded-xl" |
| 59 | + > |
| 60 | + <DialogPrimitive.DialogTitle className="w-full px-6 py-4 text-lg font-semibold"> |
| 61 | + Authors in this article |
| 62 | + </DialogPrimitive.DialogTitle> |
| 63 | + <DialogPrimitive.Close |
| 64 | + className="absolute right-2 top-4 text-slate-900 dark:text-slate-50" |
| 65 | + asChild |
| 66 | + > |
| 67 | + <Button |
| 68 | + type="outline" |
| 69 | + label="" |
| 70 | + icon={<CloseSVG className="h-5 w-5 fill-current" />} |
| 71 | + className="rounded-xl !border-transparent !px-3 !py-2 hover:bg-neutral-800 dark:text-white" |
| 72 | + onClick={closeModal} |
| 73 | + /> |
| 74 | + </DialogPrimitive.Close> |
| 75 | + <CustomScrollArea> |
| 76 | + <div className="px-6 pb-8"> |
| 77 | + {authors.map((author) => { |
| 78 | + if (!author) { |
| 79 | + return null; |
| 80 | + } |
| 81 | + return <AuthorCard author={author} key={author.id.toString()} />; |
| 82 | + })} |
| 83 | + </div> |
| 84 | + </CustomScrollArea> |
| 85 | + </DialogPrimitive.Content> |
| 86 | + </DialogPrimitive.Portal> |
| 87 | + </DialogPrimitive.Root> |
| 88 | + ); |
| 89 | +} |
0 commit comments