Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fe): show toast when copied #2008

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/frontend/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { tags as t } from '@lezer/highlight'
import { createTheme } from '@uiw/codemirror-themes'
import type { ReactCodeMirrorProps } from '@uiw/react-codemirror'
import ReactCodeMirror, { EditorView } from '@uiw/react-codemirror'
import { toast } from 'sonner'
import { ScrollArea, ScrollBar } from './ui/scroll-area'

const editorTheme = createTheme({
Expand Down Expand Up @@ -69,12 +70,15 @@ interface Props extends ReactCodeMirrorProps {
const copyPasteHandler = () => {
return EditorView.domEventHandlers({
paste(event) {
toast.error('Copying and pasting is not allowed')
event.preventDefault()
},
copy(event) {
toast.error('Copying and pasting is not allowed')
event.preventDefault()
},
cut(event) {
toast.error('Copying and pasting is not allowed')
event.preventDefault()
}
})
Expand All @@ -95,7 +99,7 @@ export default function CodeEditor({
extensions={[
fontSize,
languageParser[language](),
enableCopyPaste ? [] : [copyPasteHandler()]
enableCopyPaste ? [] : copyPasteHandler()
]}
value={value}
onChange={onChange}
Expand Down
24 changes: 24 additions & 0 deletions apps/frontend/components/EditorDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
} from '@/components/ui/dialog'
import { renderKatex } from '@/lib/renderKatex'
import { convertToLetter } from '@/lib/utils'
import CopyIcon from '@/public/24_copy.svg'
import compileIcon from '@/public/compileVersion.svg'
import copyIcon from '@/public/copy.svg'
import copyCompleteIcon from '@/public/copyComplete.svg'
import type { ContestProblem, ProblemDetail } from '@/types/type'
import { Level } from '@/types/type'

Check warning on line 24 in apps/frontend/components/EditorDescription.tsx

View workflow job for this annotation

GitHub Actions / Lint

All imports in the declaration are only used as types. Use `import type`

Check warning on line 24 in apps/frontend/components/EditorDescription.tsx

View workflow job for this annotation

GitHub Actions / Lint

All imports in the declaration are only used as types. Use `import type`
import { motion } from 'framer-motion'
import { sanitize } from 'isomorphic-dompurify'
import { FileText } from 'lucide-react'
import Image from 'next/image'
import { useState, useEffect, useRef } from 'react'
import useCopyToClipboard from 'react-use/lib/useCopyToClipboard'
import { toast } from 'sonner'
import {
Tooltip,
TooltipContent,
Expand Down Expand Up @@ -68,7 +70,7 @@
useEffect(() => {
renderKatex(problem.description, katexRef)
console.log(level)
}, [problem.description, katexRef])

Check warning on line 73 in apps/frontend/components/EditorDescription.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'level'. Either include it or remove the dependency array

Check warning on line 73 in apps/frontend/components/EditorDescription.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'level'. Either include it or remove the dependency array

const katexContent = <div ref={katexRef} />
const level = problem.difficulty
Expand Down Expand Up @@ -158,6 +160,17 @@
<Image
onClick={() => {
copy(input + '\n\n', `input-${id}`) // add newline to the end for easy testing
toast('Successfully copied', {
unstyled: true,
closeButton: false,
icon: <Image src={CopyIcon} alt="copy" />,
style: { backgroundColor: '#f0f8ff' },
classNames: {
toast:
'inline-flex items-center py-2 px-3 rounded gap-2',
title: 'text-primary font-medium'
}
})
}}
className="cursor-pointer transition-opacity hover:opacity-60"
src={copyIcon}
Expand Down Expand Up @@ -210,6 +223,17 @@
<Image
onClick={() => {
copy(output + '\n\n', `output-${id}`) // add newline to the end for easy testing
toast('Successfully copied', {
unstyled: true,
closeButton: false,
icon: <Image src={CopyIcon} alt="copy" />,
style: { backgroundColor: '#f0f8ff' },
classNames: {
toast:
'inline-flex items-center py-2 px-3 rounded gap-2',
title: 'text-primary font-medium'
}
})
}}
className="cursor-pointer transition-opacity hover:opacity-60"
src={copyIcon}
Expand Down
7 changes: 7 additions & 0 deletions apps/frontend/public/24_copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading