Skip to content

Commit 372841f

Browse files
committed
Update feedback.tsx
1 parent 4c0f31b commit 372841f

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed
Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
1-
"use client";
1+
'use client'
22

3-
import { SiMarkdown } from "@icons-pack/react-simple-icons";
4-
import { ThumbsUpIcon } from "lucide-react";
5-
import { usePathname } from "next/navigation";
3+
import { SiMarkdown } from '@icons-pack/react-simple-icons'
4+
import { ThumbsUpIcon } from 'lucide-react'
5+
import { usePathname } from 'next/navigation'
66
import {
77
type FormEventHandler,
88
useEffect,
99
useState,
1010
useTransition,
11-
} from "react";
12-
import { sendFeedback } from "@/app/actions/feedback";
13-
import { emotions } from "@/app/actions/feedback/emotions";
14-
import { cn } from "@/lib/utils";
15-
import { Button } from "../ui/button";
16-
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
17-
import { Textarea } from "../ui/textarea";
11+
} from 'react'
12+
import { sendFeedback } from '@/app/actions/feedback'
13+
import { emotions } from '@/app/actions/feedback/emotions'
14+
import { cn } from '@/lib/utils'
15+
import { Button } from '../ui/button'
16+
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
17+
import { Textarea } from '../ui/textarea'
1818

19-
type Emotion = (typeof emotions)[number]["name"];
19+
type Emotion = (typeof emotions)[number]['name']
2020

2121
export type Feedback = {
22-
emotion: Emotion;
23-
url?: string;
24-
message: string;
25-
};
22+
emotion: Emotion
23+
url?: string
24+
message: string
25+
}
2626

2727
export const Feedback = () => {
28-
const url = usePathname();
29-
const [submitted, setSubmitted] = useState(false);
30-
const [emotion, setEmotion] = useState<Emotion | null>(null);
31-
const [message, setMessage] = useState("");
32-
const [isPending, startTransition] = useTransition();
28+
const url = usePathname()
29+
const [submitted, setSubmitted] = useState(false)
30+
const [emotion, setEmotion] = useState<Emotion | null>(null)
31+
const [message, setMessage] = useState('')
32+
const [isPending, startTransition] = useTransition()
3333

3434
useEffect(() => {
35-
const item = localStorage.getItem(`docs-feedback-${url}`);
35+
const item = localStorage.getItem(`docs-feedback-${url}`)
3636

3737
if (!item) {
38-
return;
38+
return
3939
}
4040

41-
setSubmitted(true);
42-
}, [url]);
41+
setSubmitted(true)
42+
}, [url])
4343

4444
const submit: FormEventHandler<HTMLFormElement> = (e) => {
45-
e.preventDefault();
45+
e.preventDefault()
4646

4747
if (!emotion) {
48-
return;
48+
return
4949
}
5050

5151
startTransition(() => {
5252
const feedback: Feedback = {
5353
emotion,
5454
message,
55-
};
55+
}
5656

5757
sendFeedback(url, feedback).then(() => {
58-
setSubmitted(true);
59-
setMessage("");
60-
setEmotion(null);
61-
});
62-
});
58+
setSubmitted(true)
59+
setMessage('')
60+
setEmotion(null)
61+
})
62+
})
6363

64-
e?.preventDefault();
65-
};
64+
e?.preventDefault()
65+
}
6666

6767
return (
6868
<Popover>
6969
<PopoverTrigger asChild>
7070
<button
71-
className="flex items-center gap-1.5 text-muted-foreground text-sm transition-colors hover:text-foreground"
72-
type="button"
71+
className='flex items-center gap-1.5 text-muted-foreground text-sm transition-colors hover:text-foreground'
72+
type='button'
7373
>
74-
<ThumbsUpIcon className="size-3.5" />
74+
<ThumbsUpIcon className='size-3.5' />
7575
<span>Give feedback</span>
7676
</button>
7777
</PopoverTrigger>
78-
<PopoverContent className="overflow-hidden p-0">
79-
<div className="overflow-visible">
78+
<PopoverContent className='overflow-hidden p-0'>
79+
<div className='overflow-visible'>
8080
{submitted ? (
81-
<div className="flex flex-col items-center gap-3 rounded-xl bg-sidebar px-3 py-6 text-center text-sm">
81+
<div className='flex flex-col items-center gap-3 rounded-xl bg-sidebar px-3 py-6 text-center text-sm'>
8282
<p>Thank you for your feedback!</p>
8383
</div>
8484
) : (
85-
<form className="flex flex-col" onSubmit={submit}>
86-
<div className="p-2">
85+
<form className='flex flex-col' onSubmit={submit}>
86+
<div className='p-2'>
8787
<Textarea
8888
autoFocus
89-
className="max-h-48 min-h-24 shadow-none"
89+
className='max-h-48 min-h-24 shadow-none'
9090
onChange={(e) => setMessage(e.target.value)}
9191
onKeyDown={(e) => {
92-
if (!e.shiftKey && e.key === "Enter") {
93-
e.currentTarget.form?.requestSubmit();
92+
if (!e.shiftKey && e.key === 'Enter') {
93+
e.currentTarget.form?.requestSubmit()
9494
}
9595
}}
96-
placeholder="Leave your feedback..."
96+
placeholder='Leave your feedback...'
9797
required
9898
value={message}
9999
/>
100100
</div>
101-
<div className="flex items-center justify-end gap-1 px-2 text-muted-foreground">
102-
<SiMarkdown className="inline size-3" />
103-
<p className="text-xs"> supported</p>
101+
<div className='flex items-center justify-end gap-1 px-2 text-muted-foreground'>
102+
<SiMarkdown className='inline size-3' />
103+
<p className='text-xs'> supported</p>
104104
</div>
105-
<div className="mt-2 flex items-center justify-between border-t bg-sidebar p-2">
106-
<div className="flex items-center gap-px">
105+
<div className='mt-2 flex items-center justify-between border-t bg-sidebar p-2'>
106+
<div className='flex items-center gap-px'>
107107
{emotions.map((e) => (
108108
<Button
109109
className={cn(
110-
"text-muted-foreground hover:text-foreground",
111-
emotion === e.name ? "bg-accent text-foreground" : ""
110+
'text-muted-foreground hover:text-foreground',
111+
emotion === e.name ? 'bg-accent text-foreground' : '',
112112
)}
113113
key={e.name}
114114
onClick={() => setEmotion(e.name)}
115-
size="sm"
116-
type="button"
117-
variant="ghost"
115+
size='sm'
116+
type='button'
117+
variant='ghost'
118118
>
119119
{e.emoji}
120-
<span className="sr-only">{e.name}</span>
120+
<span className='sr-only'>{e.name}</span>
121121
</Button>
122122
))}
123123
</div>
124124
<Button
125-
disabled={isPending}
126-
size="sm"
127-
type="submit"
128-
variant="default"
125+
disabled={isPending || !emotion || !message}
126+
size='sm'
127+
type='submit'
128+
variant='default'
129129
>
130130
Send
131131
</Button>
@@ -135,5 +135,5 @@ export const Feedback = () => {
135135
</div>
136136
</PopoverContent>
137137
</Popover>
138-
);
139-
};
138+
)
139+
}

0 commit comments

Comments
 (0)