@@ -2,7 +2,7 @@ import { cleanUrl } from "@/libs/clean-url"
2
2
import { useStorage } from "@plasmohq/storage/hook"
3
3
import { useQuery , useQueryClient } from "@tanstack/react-query"
4
4
import { Select } from "antd"
5
- import { RotateCcw } from "lucide-react"
5
+ import { Loader2 , RotateCcw } from "lucide-react"
6
6
import { useEffect , useState } from "react"
7
7
import { Trans , useTranslation } from "react-i18next"
8
8
import { useMessage } from "~/hooks/useMessage"
@@ -50,6 +50,88 @@ export const EmptySidePanel = () => {
50
50
51
51
const { setSelectedModel, selectedModel, chatMode, setChatMode } =
52
52
useMessage ( )
53
+ const renderSection = ( ) => {
54
+ return (
55
+ < div className = "mt-4" >
56
+ < Select
57
+ onChange = { ( e ) => {
58
+ setSelectedModel ( e )
59
+ localStorage . setItem ( "selectedModel" , e )
60
+ } }
61
+ value = { selectedModel }
62
+ size = "large"
63
+ filterOption = { ( input , option ) =>
64
+ option . label . toLowerCase ( ) . indexOf ( input . toLowerCase ( ) ) >= 0 ||
65
+ option . value . toLowerCase ( ) . indexOf ( input . toLowerCase ( ) ) >= 0
66
+ }
67
+ showSearch
68
+ placeholder = { t ( "common:selectAModel" ) }
69
+ style = { { width : "100%" } }
70
+ className = "mt-4"
71
+ options = { ollamaInfo . models ?. map ( ( model ) => ( {
72
+ label : model . name ,
73
+ value : model . model
74
+ } ) ) }
75
+ />
76
+
77
+ < div className = "mt-4" >
78
+ < div className = "inline-flex items-center" >
79
+ < label
80
+ className = "relative flex items-center p-3 rounded-full cursor-pointer"
81
+ htmlFor = "check" >
82
+ < input
83
+ type = "checkbox"
84
+ checked = { chatMode === "rag" }
85
+ onChange = { ( e ) => {
86
+ setChatMode ( e . target . checked ? "rag" : "normal" )
87
+ } }
88
+ className = "before:content[''] peer relative h-5 w-5 cursor-pointer appearance-none rounded-md border border-blue-gray-200 transition-all before:absolute before:top-2/4 before:left-2/4 before:block before:h-12 before:w-12 before:-translate-y-2/4 before:-translate-x-2/4 before:rounded-full before:bg-blue-gray-500 before:opacity-0 before:transition-opacity"
89
+ id = "check"
90
+ />
91
+ < span className = "absolute text-white transition-opacity opacity-0 pointer-events-none top-2/4 left-2/4 -translate-y-2/4 -translate-x-2/4 peer-checked:opacity-100 " >
92
+ < svg
93
+ xmlns = "http://www.w3.org/2000/svg"
94
+ className = "h-3.5 w-3.5"
95
+ viewBox = "0 0 20 20"
96
+ fill = "currentColor"
97
+ stroke = "currentColor"
98
+ strokeWidth = "1" >
99
+ < path
100
+ fillRule = "evenodd"
101
+ d = "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
102
+ clipRule = "evenodd" > </ path >
103
+ </ svg >
104
+ </ span >
105
+ </ label >
106
+ < label
107
+ className = "mt-px font-light cursor-pointer select-none text-gray-900 dark:text-gray-400"
108
+ htmlFor = "check" >
109
+ { t ( "common:chatWithCurrentPage" ) }
110
+ </ label >
111
+ </ div >
112
+ </ div >
113
+ </ div >
114
+ )
115
+ }
116
+
117
+ if ( ! checkOllamaStatus ) {
118
+ return (
119
+ < div className = "mx-auto sm:max-w-md px-4 mt-10" >
120
+ < div className = "rounded-lg justify-center items-center flex flex-col border dark:border-gray-700 p-8 bg-white dark:bg-[#262626] shadow-sm" >
121
+ < div className = "inline-flex items-center space-x-2" >
122
+ < p className = "dark:text-gray-400 text-gray-900" >
123
+ < span > 👋</ span >
124
+ { t ( "welcome" ) }
125
+ </ p >
126
+ </ div >
127
+ { ollamaStatus === "pending" && (
128
+ < Loader2 className = "mr-2 h-4 w-4 animate-spin" />
129
+ ) }
130
+ { ollamaStatus === "success" && ollamaInfo . isOk && renderSection ( ) }
131
+ </ div >
132
+ </ div >
133
+ )
134
+ }
53
135
54
136
return (
55
137
< div className = "mx-auto sm:max-w-md px-4 mt-10" >
@@ -62,7 +144,7 @@ export const EmptySidePanel = () => {
62
144
</ p >
63
145
</ div >
64
146
) }
65
- { ! isRefetching && ollamaStatus === "success" && checkOllamaStatus ? (
147
+ { ! isRefetching && ollamaStatus === "success" ? (
66
148
ollamaInfo . isOk ? (
67
149
< div className = "inline-flex items-center space-x-2" >
68
150
< div className = "w-3 h-3 bg-green-500 rounded-full" > </ div >
@@ -115,67 +197,7 @@ export const EmptySidePanel = () => {
115
197
)
116
198
) : null }
117
199
118
- { ollamaStatus === "success" && ollamaInfo . isOk && (
119
- < div className = "mt-4" >
120
- < Select
121
- onChange = { ( e ) => {
122
- setSelectedModel ( e )
123
- localStorage . setItem ( "selectedModel" , e )
124
- } }
125
- value = { selectedModel }
126
- size = "large"
127
- filterOption = { ( input , option ) =>
128
- option . label . toLowerCase ( ) . indexOf ( input . toLowerCase ( ) ) >= 0 ||
129
- option . value . toLowerCase ( ) . indexOf ( input . toLowerCase ( ) ) >= 0
130
- }
131
- showSearch
132
- placeholder = { t ( "common:selectAModel" ) }
133
- style = { { width : "100%" } }
134
- className = "mt-4"
135
- options = { ollamaInfo . models ?. map ( ( model ) => ( {
136
- label : model . name ,
137
- value : model . model
138
- } ) ) }
139
- />
140
-
141
- < div className = "mt-4" >
142
- < div className = "inline-flex items-center" >
143
- < label
144
- className = "relative flex items-center p-3 rounded-full cursor-pointer"
145
- htmlFor = "check" >
146
- < input
147
- type = "checkbox"
148
- checked = { chatMode === "rag" }
149
- onChange = { ( e ) => {
150
- setChatMode ( e . target . checked ? "rag" : "normal" )
151
- } }
152
- className = "before:content[''] peer relative h-5 w-5 cursor-pointer appearance-none rounded-md border border-blue-gray-200 transition-all before:absolute before:top-2/4 before:left-2/4 before:block before:h-12 before:w-12 before:-translate-y-2/4 before:-translate-x-2/4 before:rounded-full before:bg-blue-gray-500 before:opacity-0 before:transition-opacity"
153
- id = "check"
154
- />
155
- < span className = "absolute text-white transition-opacity opacity-0 pointer-events-none top-2/4 left-2/4 -translate-y-2/4 -translate-x-2/4 peer-checked:opacity-100 " >
156
- < svg
157
- xmlns = "http://www.w3.org/2000/svg"
158
- className = "h-3.5 w-3.5"
159
- viewBox = "0 0 20 20"
160
- fill = "currentColor"
161
- stroke = "currentColor"
162
- strokeWidth = "1" >
163
- < path
164
- fillRule = "evenodd"
165
- d = "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
166
- clipRule = "evenodd" > </ path >
167
- </ svg >
168
- </ span >
169
- </ label >
170
- < label
171
- className = "mt-px font-light cursor-pointer select-none text-gray-900 dark:text-gray-400"
172
- htmlFor = "check" >
173
- { t ( "common:chatWithCurrentPage" ) }
174
- </ label >
175
- </ div >
176
- </ div >
177
- </ div >
178
- ) }
200
+ { ollamaStatus === "success" && ollamaInfo . isOk && renderSection ( ) }
179
201
</ div >
180
202
</ div >
181
203
)
0 commit comments