Skip to content

Commit 1673613

Browse files
committed
fix searcch is empty error
1 parent 447f696 commit 1673613

File tree

2 files changed

+20
-85
lines changed

2 files changed

+20
-85
lines changed

components/SearchDialog.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function SearchDialog() {
135135

136136
// 应该在代码顶部放置断言,以确保 `e.data` 符合 `string` 类型
137137
// 另外,请注意,使用类型断言会带来运行时错误的风险,因此对于不确定类型的值,请确保进行有效的类型验证
138-
const completionResponse= JSON.parse(e.data);
138+
const completionResponse = JSON.parse(e.data);
139139
const text = completionResponse.choices[0].delta?.content || "";
140140

141141
setAnswer((answer) => {
@@ -164,14 +164,16 @@ export function SearchDialog() {
164164

165165
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
166166
e.preventDefault()
167-
console.log(search)
167+
if (!search) {
168+
return false
169+
}
168170

169171
handleConfirm(search)
170172
}
171173

172174
return (
173175
<>
174-
176+
175177
<button
176178
onClick={() => setOpen(true)}
177179
className="text-base flex gap-2 items-center px-4 py-3 z-50 relative
@@ -261,9 +263,8 @@ export function SearchDialog() {
261263
className="col-span-3"
262264
/>
263265
<CornerDownLeft
264-
className={`absolute top-3 right-5 h-4 w-4 text-gray-300 transition-opacity ${
265-
search ? 'opacity-100' : 'opacity-0'
266-
}`}
266+
className={`absolute top-3 right-5 h-4 w-4 text-gray-300 transition-opacity ${search ? 'opacity-100' : 'opacity-0'
267+
}`}
267268
/>
268269
</div>
269270
<div className="text-xs text-gray-500 md:flex space-y-2 md:space-y-0 gap-2 dark:text-gray-100">
@@ -311,11 +312,14 @@ export function SearchDialog() {
311312
</div>
312313
<DialogFooter>
313314
<div className="text-xs text-gray-500 mt-4 md:m-0 dark:text-gray-100">
314-
* 回答由 AI 检索法律文件后生成,不保证准确率,仅供参考学习! <a href="https://www.aigc2d.com" className='ml-1 underline decoration-wavy decoration-indigo-500 underline-offset-2 hover:text-indigo-500' target='_blank'>AIGC2D</a> <a href="https://afdian.net/a/lvwzhen/plan" className='ml-1 underline decoration-wavy decoration-indigo-500 underline-offset-2 hover:text-indigo-500' target='_blank'>打赏赞助</a>
315+
* 回答由 AI 检索法律文件后生成,不保证准确率,仅供参考学习!
316+
<a href="https://www.aigc2d.com" className='ml-1 underline decoration-wavy decoration-indigo-500 underline-offset-2 hover:text-indigo-500' target='_blank'>AIGC2D</a>
315317
</div>
316-
<Button type="submit" className="bg-red-500 block w-full md:w-auto md:inline-block">
318+
{search.length > 0 ? <Button type="submit" className="bg-red-500 block w-full md:w-auto md:inline-block">
319+
Ask
320+
</Button> : <Button type="submit" disabled className="bg-red-500 block w-full md:w-auto md:inline-block">
317321
Ask
318-
</Button>
322+
</Button>}
319323
</DialogFooter>
320324
</form>
321325
</DialogContent>

pages/index.tsx

+7-76
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function Home() {
1818
<link rel="icon" href="/favicon.ico" />
1919
</Head>
2020
<Script
21-
src="https://www.googletagmanager.com/gtag/js?id=G-6GCGYXNM3S"
21+
src="https://www.googletagmanager.com/gtag/js?id=G-BTGGPV7BPL"
2222
strategy="afterInteractive"
2323
/>
2424
<Script id="google-analytics" strategy="afterInteractive">
@@ -27,7 +27,7 @@ export default function Home() {
2727
function gtag(){window.dataLayer.push(arguments);}
2828
gtag('js', new Date());
2929
30-
gtag('config', 'G-6GCGYXNM3S');
30+
gtag('config', 'G-BTGGPV7BPL');
3131
`}
3232
</Script>
3333
<main className={styles.main}>
@@ -43,15 +43,15 @@ export default function Home() {
4343
<ul className="grid grid-cols-2 md:grid-cols-4 gap-3 mt-4 max-w-2xl mx-auto text-xs">
4444
<li>
4545
<Link
46-
href="https://www.aigc2d.com/logo/logo-bg-512.png"
46+
href="https://www.aigc2d.com/"
4747
className="
4848
dark:bg-white/30
4949
dark:text-slate-900
5050
dark:border-slate-900
5151
text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
5252
>
5353
<Image
54-
src={'/MagickPen.png'}
54+
src={'https://www.aigc2d.com/logo/logo-bg-512.png'}
5555
width={100}
5656
height="20"
5757
className="w-full mb-1 h-5 object-contain"
@@ -62,7 +62,7 @@ export default function Home() {
6262
</li>
6363
<li>
6464
<Link
65-
href="https://reviewgpt.net/?ref=lawcnai"
65+
href="https://chat.aigc2d.com/?ref=lawcnai"
6666
className="dark:bg-white/30
6767
dark:border-slate-900
6868
dark:text-slate-900 text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
@@ -72,80 +72,11 @@ export default function Home() {
7272
width={100}
7373
height="20"
7474
className="w-full mb-1 h-5 object-contain"
75-
alt="ReviewGPT - Make Your Writing Awesome"
75+
alt="在线对话ChatGPT"
7676
/>
77-
AI 改写文章
77+
在线对话ChatGPT
7878
</Link>
7979
</li>
80-
<li>
81-
<Link
82-
href="https://openl.io/?ref=lawcnai"
83-
className="dark:bg-white/30
84-
dark:border-slate-900
85-
dark:text-slate-900 text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
86-
>
87-
<Image
88-
src={'/OpenL.png'}
89-
width={100}
90-
height="20"
91-
className="w-full mb-1 h-5 object-contain"
92-
alt="OpenL - AI 翻译专家"
93-
/>
94-
AI 翻译专家
95-
</Link>
96-
</li>
97-
<li>
98-
<Link
99-
href="https://www.teach-anything.com/?ref=lawcnai"
100-
className="dark:bg-white/30
101-
dark:border-slate-900
102-
dark:text-slate-900 text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
103-
>
104-
<Image
105-
src={'/TeachAnything.png'}
106-
width={100}
107-
height="20"
108-
className="w-full mb-1 h-5 object-contain"
109-
alt="Teach Anything - AI 百科全书"
110-
/>
111-
AI 百科全书
112-
</Link>
113-
</li>
114-
<li>
115-
<Link
116-
href="https://ask2end.com/?ref=lawcnai"
117-
className="dark:bg-white/30
118-
dark:border-slate-900
119-
dark:text-slate-900 text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
120-
>
121-
<Image
122-
src={'/Ask2End.png'}
123-
width={100}
124-
height="20"
125-
className="w-full mb-1 h-5 object-contain"
126-
alt="Ask2End - 打破砂锅问到底"
127-
/>
128-
打破砂锅问到底
129-
</Link>
130-
</li>
131-
<li>
132-
<Link
133-
href="https://better.avatarprompt.net/?ref=lawcnai"
134-
className="dark:bg-white/30
135-
dark:border-slate-900
136-
dark:text-slate-900 text-slate-400 border border-slate-300/30 transition-all hover:bg-white/50 hover:backdrop-blur-md py-2.5 rounded-md block"
137-
>
138-
<Image
139-
src={'/BetterPrompt.png'}
140-
width={100}
141-
height="20"
142-
className="w-full mb-1 h-5 object-contain"
143-
alt="Teach Anything - AI 百科全书"
144-
/>
145-
Prompt 生成器
146-
</Link>
147-
</li>
148-
14980
</ul>
15081
</div>
15182

0 commit comments

Comments
 (0)