Skip to content

Commit 0f7d97c

Browse files
committed
chore/ui: Add fix for copy paste from chat
Signed-off-by: SeeuSim <[email protected]>
1 parent d52e067 commit 0f7d97c

File tree

6 files changed

+63
-25
lines changed

6 files changed

+63
-25
lines changed

frontend/src/components/blocks/authed/with-nav-blocker.tsx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
12
import { FC, PropsWithChildren } from 'react';
23
import { useBlocker } from 'react-router-dom';
34

45
import { Button } from '@/components/ui/button';
5-
import { Dialog, DialogContent } from '@/components/ui/dialog';
6+
import {
7+
Dialog,
8+
DialogContent,
9+
DialogDescription,
10+
DialogFooter,
11+
DialogTitle,
12+
} from '@/components/ui/dialog';
613

714
export const WithNavBlocker: FC<PropsWithChildren> = ({ children }) => {
815
const blocker = useBlocker(
@@ -13,21 +20,32 @@ export const WithNavBlocker: FC<PropsWithChildren> = ({ children }) => {
1320
{blocker.state === 'blocked' && (
1421
<Dialog modal open>
1522
<DialogContent className='text-primary border-secondary-foreground/40 flex flex-col gap-8'>
16-
<h1 className='text-lg font-medium'>
23+
<DialogTitle className='text-primary text-lg'>
1724
Are you sure you want to navigate away from this page?
18-
</h1>
19-
<div className='flex flex-row justify-between'>
20-
<Button onClick={blocker.reset}>
21-
<span>Cancel</span>
22-
</Button>
23-
<Button variant='destructive' onClick={blocker.proceed}>
24-
<span>Leave Page</span>
25-
</Button>
26-
</div>
27-
<div
28-
id='blockDialogClose'
29-
className='bg-background absolute right-4 top-4 z-50 size-4'
30-
/>
25+
</DialogTitle>
26+
<VisuallyHidden>
27+
<DialogDescription />
28+
</VisuallyHidden>
29+
<DialogFooter>
30+
<div className='flex w-full flex-row justify-between'>
31+
<Button onClick={blocker.reset}>
32+
<span>Cancel</span>
33+
</Button>
34+
<Button
35+
variant='destructive'
36+
onClick={() => {
37+
localStorage.removeItem('ai_chat_history');
38+
blocker.proceed();
39+
}}
40+
>
41+
<span>Leave Page</span>
42+
</Button>
43+
</div>
44+
<div
45+
id='blockDialogClose'
46+
className='bg-background absolute right-4 top-4 z-50 size-4'
47+
/>
48+
</DialogFooter>
3149
</DialogContent>
3250
</Dialog>
3351
)}

frontend/src/components/blocks/interview/chat/chat-markdown.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ export const MarkdownComponent = ({
3131
code({ children, className, ...rest }) {
3232
const [copyCodeText, setCopyCodeText] = useState('Copy Code');
3333

34+
const match = /language-(\w+)/.exec(className || '');
35+
3436
const onCopy = (code: string) => {
37+
const language = match?.[1];
38+
39+
if (language) {
40+
localStorage.setItem('ai-asst-lang', language);
41+
}
42+
3543
navigator.clipboard.writeText(code);
3644
setCopyCodeText('Copied!');
3745
setTimeout(() => {
3846
setCopyCodeText(defaultCopyCodeText);
3947
}, 3000);
4048
};
4149

42-
const match = /language-(\w+)/.exec(className || '');
4350
return match ? (
4451
<div className='flex flex-col'>
4552
<div className='inline-flex translate-y-[10px] items-center justify-between rounded-t-sm bg-gray-700 p-1 text-sm'>

frontend/src/components/blocks/interview/editor.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ export const Editor = ({
193193
height={`${Math.max((height as number) - EXTENSION_HEIGHT, MIN_EDITOR_HEIGHT)}px`}
194194
value={code}
195195
onChange={handleCodeChange}
196+
onPaste={(_event) => {
197+
const lang = localStorage.getItem('ai-asst-lang');
198+
199+
if (lang) {
200+
setLanguage(lang as LanguageName);
201+
localStorage.removeItem('ai-assist-lang');
202+
}
203+
}}
196204
theme={themePreset}
197205
lang={language}
198206
basicSetup={{

frontend/src/components/blocks/interview/question-attempts/attempt-details/code-viewer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const CodeViewer: FC<ICodeProps> = ({ code, language }) => {
2525
};
2626

2727
return (
28-
<div className='flex size-full flex-col text-clip rounded-md'>
28+
<div className='flex size-full flex-col !overflow-clip rounded-lg'>
2929
<div className='bg-muted-foreground text-muted dark:bg-muted dark:text-muted-foreground flex w-full items-center justify-between px-3 py-2'>
3030
<span className='text-sm font-medium'>{language}</span>
3131
<Button
@@ -52,6 +52,7 @@ export const CodeViewer: FC<ICodeProps> = ({ code, language }) => {
5252
PreTag='div'
5353
style={oneDark}
5454
language={language}
55+
// showLineNumbers
5556
>
5657
{code}
5758
</SyntaxHighlighter>

frontend/src/components/blocks/interview/question-attempts/table.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ export function QuestionAttemptsTable<TValue>({
8989
noOptionsText='None of the available languages match your search'
9090
/>
9191
</div>
92-
{/* <Input
93-
placeholder='Search questions...'
94-
value={(table.getColumn('title')?.getFilterValue() as string) ?? ''}
95-
onChange={(event) => table.getColumn('title')?.setFilterValue(event.target.value)}
96-
className='max-w-sm'
97-
/> */}
9892
</div>
9993
<div className='border-border sticky top-0 rounded-t-md border'>
10094
<Table>

frontend/src/components/blocks/interview/room/complete-dialog.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
12
import { useMutation } from '@tanstack/react-query';
23
import { Loader2 } from 'lucide-react';
34
import { Dispatch, FC, PropsWithChildren, SetStateAction, useCallback, useState } from 'react';
@@ -7,8 +8,10 @@ import { Button } from '@/components/ui/button';
78
import {
89
Dialog,
910
DialogContent,
11+
DialogDescription,
1012
DialogFooter,
1113
DialogHeader,
14+
DialogTitle,
1215
DialogTrigger,
1316
} from '@/components/ui/dialog';
1417
import { addQuestionAttempt } from '@/services/question-service';
@@ -69,6 +72,10 @@ export const CompleteDialog: FC<PropsWithChildren<CompleteDialogProps>> = ({
6972
// Navigate to home page
7073
setTimeout(() => {
7174
setCompleting(COMPLETION_STATES.EMPTY, true);
75+
setIsOpen(false);
76+
// Clear AI chat if moving away
77+
localStorage.removeItem('ai-assist-lang');
78+
localStorage.removeItem('ai_chat_history');
7279
navigate('/');
7380
}, 200);
7481
},
@@ -81,9 +88,12 @@ export const CompleteDialog: FC<PropsWithChildren<CompleteDialogProps>> = ({
8188
<Dialog onOpenChange={setIsOpen} open={isOpen}>
8289
<DialogTrigger asChild>{children}</DialogTrigger>
8390
<DialogContent className='border-border'>
84-
<DialogHeader className='text-primary text-lg font-medium'>
85-
Are you sure you wish to mark this question as complete?
91+
<DialogHeader className='text-primary'>
92+
<DialogTitle>Are you sure you wish to mark this question as complete?</DialogTitle>
8693
</DialogHeader>
94+
<VisuallyHidden>
95+
<DialogDescription />
96+
</VisuallyHidden>
8797
<DialogFooter>
8898
<div className='flex w-full justify-between'>
8999
<Button

0 commit comments

Comments
 (0)