Connect, collaborate, and grow with a community of TypeScript developers
move WYSIWYG under solutions tab (#132)
PickleNik25af432cde66
diff --git a/src/app/create/page.tsx b/src/app/create/page.tsxindex 658a3bbb..ab21c5d3 100644--- a/src/app/create/page.tsx+++ b/src/app/create/page.tsx@@ -22,6 +22,10 @@ import {} from '../../components/ui/select';import { type Difficulty } from '@prisma/client';+import { useTheme } from 'next-themes';++import MDEditor from '@uiw/react-md-editor';+export default function CreateChallenge() {const createChallengeStore = useCreateChallengeStore();const [isPreviewing, setIsPreviewing] = useState({@@ -86,6 +90,11 @@ export default function CreateChallenge() {router.push('/create/preview');}+ const { theme } = useTheme();+ theme == 'dark'+ ? document.documentElement.setAttribute('data-color-mode', 'dark')+ : document.documentElement.setAttribute('data-color-mode', 'light');+return (<ChallengeLayoutleft={@@ -185,7 +194,7 @@ export default function CreateChallenge() {value="long-description"className="relative mt-0 flex flex-1 flex-col dark:bg-muted [&[hidden]]:hidden">- <div className="absolute right-4 top-4 flex items-center justify-end">+ <div className="absolute bottom-4 right-4 z-10 flex items-center justify-end"><LabelhtmlFor="previewLong"className="flex cursor-pointer gap-2 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"@@ -206,11 +215,43 @@ export default function CreateChallenge() {<Markdown>{description}</Markdown></div>) : (- <Textarea- className="flex-1 resize-none border-none bg-zinc-100 dark:bg-zinc-900"- value={description}- onChange={(ev) => setDescription(ev.currentTarget.value)}- />+ <>+ <MDEditor+ height="100%"+ className="flex-1"+ value={description}+ // non-split-screen by default+ preview="edit"+ // removes resize handle on bottom right+ visibleDragbar={false}+ // @ts-ignore+ onChange={(ev) => setDescription(ev)}+ // TODO: customize toolbar GH #131+ // components={{+ // toolbar: (command, disabled, executeCommand) => {+ // if (command.keyCommand === 'code') {+ // return (+ // <button+ // aria-label="Insert code"+ // disabled={disabled}+ // onClick={(evn) => {+ // evn.stopPropagation();+ // executeCommand(command, command.groupName);+ // }}+ // >+ // Code+ // </button>+ // );+ // }+ // },+ // }}+ />+ {/* <Textarea+ className="flex-1 resize-none border-none bg-zinc-100 dark:bg-zinc-900"+ value={description}+ onChange={(ev) => setDescription(ev.currentTarget.value)}+ /> */}+ </>)}</TabsContent></Tabs>diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/description-panel.tsxindex 03b4f83b..0a638f50 100644--- a/src/components/challenge/description-panel.tsx+++ b/src/components/challenge/description-panel.tsx@@ -124,7 +124,7 @@ export function DescriptionPanel({ challenge }: Props) {return (<>- <Tabs defaultValue="description" className="w-full">+ <Tabs defaultValue="description" className="flex h-full w-full flex-col"><TabsList className="sticky top-0 z-10 grid h-auto w-full grid-cols-3 rounded-none border-b border-zinc-300 bg-background/90 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90"><TabsTriggervalue="description"@@ -145,7 +145,7 @@ export function DescriptionPanel({ challenge }: Props) {Submissions</TabsTrigger></TabsList>- <TabsContent value="description" className="mt-0 dark:bg-muted">+ <TabsContent value="description" className="mt-0 flex-1 dark:bg-muted"><div className="h-full px-4 py-3"><div className="flex items-baseline justify-between"><TypographyH3 className="mb-2 font-medium">{challenge.name}</TypographyH3>@@ -375,10 +375,10 @@ export function DescriptionPanel({ challenge }: Props) {</div></div></TabsContent>- <TabsContent value="solutions" className="mt-0 dark:bg-muted">+ <TabsContent value="solutions" className="mt-0 flex-1 dark:bg-muted"><Solutions challenge={challenge} /></TabsContent>- <TabsContent value="submissions" className="mt-0 dark:bg-muted">+ <TabsContent value="submissions" className="mt-0 flex-1 dark:bg-muted"><Submissions challenge={challenge} /></TabsContent></Tabs>diff --git a/src/components/challenge/solutions/index.tsx b/src/components/challenge/solutions/index.tsxindex 668c00ae..a7a50157 100644--- a/src/components/challenge/solutions/index.tsx+++ b/src/components/challenge/solutions/index.tsx@@ -2,13 +2,7 @@import { ArrowUp, MessageCircle, Plus } from 'lucide-react';import { Button } from '~/components/ui/button';-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from '~/components/ui/dialog';+import type { Challenge } from '..';import { SolutionEditor } from './solution-editor';import { useState } from 'react';@@ -21,22 +15,24 @@ export function Solutions({ challenge }: Props) {const [openSolutionEditor, setOpenSolutionEditor] = useState(false);const handleClick = () => {- console.log('do stuff');+ setOpenSolutionEditor(true);};return (- <>- <div className="sticky right-0 top-[41px] z-10 flex h-full items-center justify-between border-b border-zinc-300 bg-background/90 bg-opacity-20 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">- <div className="flex gap-2">- <div className="flex gap-2 rounded-xl bg-blue-600/10 px-4 py-1 text-blue-600 dark:bg-blue-400/10 dark:text-blue-400">- All- </div>- <div className="flex gap-2 rounded-xl bg-black/5 px-4 py-1 text-neutral-500 dark:bg-white/5 dark:text-neutral-400">- Tag 2- </div>- </div>- <Dialog open={openSolutionEditor} onOpenChange={setOpenSolutionEditor}>- <DialogTrigger>+ <div className="relative h-full">+ {openSolutionEditor ? (+ <SolutionEditor challenge={challenge} setOpen={setOpenSolutionEditor} />+ ) : (+ <>+ <div className="sticky right-0 top-[41px] z-10 flex items-center justify-between border-b border-zinc-300 bg-background/90 bg-opacity-20 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">+ <div className="flex gap-2">+ <div className="flex gap-2 rounded-xl bg-blue-600/10 px-4 py-1 text-blue-600 dark:bg-blue-400/10 dark:text-blue-400">+ All+ </div>+ <div className="flex gap-2 rounded-xl bg-black/5 px-4 py-1 text-neutral-500 dark:bg-white/5 dark:text-neutral-400">+ Tag 2+ </div>+ </div><ButtonclassName="h-8 rounded-xl bg-emerald-600 hover:bg-emerald-500 dark:bg-emerald-400 dark:hover:bg-emerald-300"onClick={() => handleClick()}@@ -44,33 +40,18 @@ export function Solutions({ challenge }: Props) {><Plus className="mr-2 h-4 w-4" /> Solution</Button>- </DialogTrigger>- <DialogContent- onEscapeKeyDown={(e) => e.preventDefault()}- onPointerDownOutside={(e) => e.preventDefault()}- className="flex h-5/6 w-11/12 max-w-none flex-col md:w-11/12"- displayX={false}- >- <DialogHeader>- <DialogTitle>Share your solution</DialogTitle>- </DialogHeader>- <div className="h-full pt-4">- <SolutionEditor challenge={challenge} setOpen={setOpenSolutionEditor} />- </div>- </DialogContent>- </Dialog>- </div>- <div className="relative flex flex-col">- <SolutionRow />- <SolutionRow />- <SolutionRow />- <SolutionRow />- <SolutionRow />- <SolutionRow />- <SolutionRow />- <SolutionRow />- </div>- </>+ </div>+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ <SolutionRow />+ </>+ )}+ </div>);}diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsxindex 6cc0fb6a..4fa4de29 100644--- a/src/components/challenge/solutions/solution-editor.tsx+++ b/src/components/challenge/solutions/solution-editor.tsx@@ -9,6 +9,7 @@ import { useToast } from '~/components/ui/use-toast';import { postSolution } from './post-solution.action';import type { Challenge } from '..';import { useSession } from 'next-auth/react';+import { useTheme } from 'next-themes';const getDefaultMarkdown = (solution: string) => `## Thoughts@@ -68,39 +69,86 @@ export function SolutionEditor({ setOpen, challenge }: Props) {}};+ const { theme } = useTheme();+ theme == 'dark'+ ? document.documentElement.setAttribute('data-color-mode', 'dark')+ : document.documentElement.setAttribute('data-color-mode', 'light');+return (- <div className="flex h-full flex-col gap-3">+ <><Form {...form}>{/* eslint-disable-next-line @typescript-eslint/no-misused-promises */}- <form className="flex h-full flex-col gap-3" onSubmit={form.handleSubmit(onSubmit)}>- <FormField- control={form.control}- name="title"- render={({ field }) => (- <FormItem>- <FormControl>- <Input {...field} placeholder="Enter a title for your solution." />- </FormControl>- <FormMessage />- </FormItem>- )}- />- <FormField- control={form.control}- name="content"- render={({ field }) => (- // @ts-ignore- <MDEditor height="100%" value={field.value} onChange={field.onChange} />- )}- />- <div className="flex items-center justify-end gap-2">- <Button variant="ghost" type="button" onClick={() => setOpen(false)}>+ <form className="flex h-full flex-col" onSubmit={form.handleSubmit(onSubmit)}>+ <div className="sticky right-0 top-[41px] z-10 flex items-center justify-between gap-2 border-b border-zinc-300 bg-background/90 bg-opacity-20 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">+ <div className="flex-1">+ <FormField+ control={form.control}+ name="title"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ className="rounded-xl border-zinc-300 bg-zinc-100 focus-visible:ring-0 focus-visible:ring-offset-0 dark:border-zinc-700 dark:bg-zinc-900"+ {...field}+ placeholder="Enter a title for your solution."+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ <Button+ className="h-9 rounded-xl bg-white text-black hover:bg-zinc-200 focus-visible:bg-zinc-200 focus-visible:ring-offset-0 dark:bg-zinc-800 dark:text-zinc-300 dark:hover:bg-zinc-700 dark:focus-visible:bg-zinc-700"+ type="button"+ onClick={() => setOpen(false)}+ >Cancel</Button>- <Button type="submit">Post</Button>+ <Button className="h-9 rounded-xl" type="submit">+ Post+ </Button>+ </div>+ <div className="flex-1">+ <FormField+ control={form.control}+ name="content"+ render={({ field }) => (+ // @ts-ignore+ <MDEditor+ height="100%"+ value={field.value}+ // non-split-screen by default+ preview="edit"+ // removes resize handle on bottom right+ visibleDragbar={false}+ // @ts-ignore+ onChange={field.onChange}+ // TODO: customize toolbar GH #131+ // components={{+ // toolbar: (command, disabled, executeCommand) => {+ // if (command.keyCommand === 'code') {+ // return (+ // <button+ // aria-label="Insert code"+ // disabled={disabled}+ // onClick={(evn) => {+ // evn.stopPropagation();+ // executeCommand(command, command.groupName);+ // }}+ // >+ // Code+ // </button>+ // );+ // }+ // },+ // }}+ />+ )}+ /></div></form></Form>- </div>+ </>);}diff --git a/src/components/ui/markdown.tsx b/src/components/ui/markdown.tsxindex ad42c595..7f9c2535 100644--- a/src/components/ui/markdown.tsx+++ b/src/components/ui/markdown.tsx@@ -11,6 +11,12 @@ export function Markdown({ children }: { children: string }) {<ReactMarkdownremarkPlugins={[remarkGfm]}components={{+ h1: ({ className, ...props }) => (+ <h1+ className={clsx(className, 'mb-2 border-b border-zinc-500 pb-2 text-3xl font-bold')}+ {...props}+ />+ ),p: ({ className, ...props }) => <p className={clsx(className, 'mb-4')} {...props} />,code({ inline, className, children, style: _, ...props }) {const match = /language-(\w+)/.exec(className || '');