Connect, collaborate, and grow with a community of TypeScript developers
Feat/add sharing modal (#21)
Sean Boultcf71c3514e03
diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/description-panel.tsxindex ad666183..12ebbadd 100644--- a/src/components/challenge/description-panel.tsx+++ b/src/components/challenge/description-panel.tsx@@ -15,6 +15,8 @@ import { incrementOrDecrementUpvote } from './increment.action';import { TypographyH3 } from '../ui/typography/h3';import { DifficultyBadge } from '../explore/difficulty-badge';import { Button } from '../ui/button';+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '../ui/dialog';+import { ShareForm } from './share-form';interface Props {challenge: Challenge & {@@ -38,11 +40,15 @@ export function DescriptionPanel({ challenge }: Props) {).current;return (- <div className="flex-1 rounded-md bg-white dark:bg-zinc-800 overflow-y-auto">+ <div className="flex-1 overflow-y-auto rounded-md bg-white dark:bg-zinc-800"><Tabs defaultValue="description" className="w-full"><TabsList className="grid w-full grid-cols-2">- <TabsTrigger value="description" className="hover:bg-zinc-200 dark:hover:bg-zinc-700">Description</TabsTrigger>- <TabsTrigger value="solutions" className="hover:bg-zinc-200 dark:hover:bg-zinc-700" >Solutions</TabsTrigger>+ <TabsTrigger value="description" className="hover:bg-zinc-200 dark:hover:bg-zinc-700">+ Description+ </TabsTrigger>+ <TabsTrigger value="solutions" className="hover:bg-zinc-200 dark:hover:bg-zinc-700">+ Solutions+ </TabsTrigger></TabsList><TabsContent value="description" className="mt-0"><div className="h-full p-5">@@ -84,9 +90,22 @@ export function DescriptionPanel({ challenge }: Props) {<Button variant="ghost" className="p-1"><Bookmark size={20} className="stroke-gray-500 hover:stroke-gray-400" /></Button>- <Button variant="ghost" className="p-1">- <Share size={20} className="stroke-gray-500 hover:stroke-gray-400" />- </Button>+ <Dialog>+ <DialogTrigger>+ <Share+ size={20}+ className="stroke-gray-500 hover:stroke-gray-400"+ />+ </DialogTrigger>+ <DialogContent className="w-[200px]">+ <DialogHeader>+ <DialogTitle>Share this challenege</DialogTitle>+ <div className="py-4">+ <ShareForm />+ </div>+ </DialogHeader>+ </DialogContent>+ </Dialog></div><div className="prose-invert prose-h3:text-xl">{/* @ts-ignore */}diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsxindex 87b6739a..9863cfce 100644--- a/src/components/challenge/editor/index.tsx+++ b/src/components/challenge/editor/index.tsx@@ -11,10 +11,10 @@ import {DialogTitle,DialogTrigger,} from '~/components/ui/dialog';-import { SettingsForm } from '../settings-form';import { useEditorSettingsStore } from '../settings-store';import { createTwoslashInlayProvider } from './twoslash';import { VimStatusBar, loadVim } from './vimMode';+import { ShareForm } from '../settings-form';declare global {// eslint-disable-next-line no-var@@ -171,9 +171,9 @@ export const CodePanel = ({ prompt }: Props) => {</DialogTrigger><DialogContent className="w-[200px]"><DialogHeader>- <DialogTitle>Settings</DialogTitle>+ <DialogTitle>Share</DialogTitle><div className="py-4">- <SettingsForm />+ <ShareForm /></div></DialogHeader></DialogContent>diff --git a/src/components/challenge/share-form.tsx b/src/components/challenge/share-form.tsxnew file mode 100644index 00000000..1abef49a--- /dev/null+++ b/src/components/challenge/share-form.tsx@@ -0,0 +1,21 @@+'use client';++import { Button } from '../ui/button';+export function ShareForm() {+ const url = window.location.href;++ const copyToClipboard = () => {+ if (navigator.clipboard) {+ navigator.clipboard.writeText(url);+ }+ };++ return (+ <div>+ <p>Copy this challenge url so to share with your friends!</p>+ <Button className="block ml-auto mt-4" onClick={copyToClipboard}>+ Copy to Clipboard+ </Button>+ </div>+ );+}