@@ -30,6 +30,7 @@ import { downloadFile, titleToKebabCase } from '~/lib/util'
30
30
import { cn } from '~/lib/utils'
31
31
import { useApp } from './app-provider'
32
32
import { CodeBlock } from './code-block'
33
+ import SignInButton from './sign-in-button'
33
34
import ThemeDropdown from './theme-dropdown'
34
35
import {
35
36
DropdownMenu ,
@@ -40,14 +41,45 @@ import {
40
41
} from './ui/dropdown-menu'
41
42
42
43
export default function Sidebar ( ) {
43
- const { user, signOut, focusRef } = useApp ( )
44
+ const { user, signOut, focusRef, isSignInDialogOpen , setIsSignInDialogOpen } = useApp ( )
44
45
let { id : currentDatabaseId } = useParams < { id : string } > ( )
45
46
const router = useRouter ( )
46
47
const { data : databases , isLoading : isLoadingDatabases } = useDatabasesQuery ( )
47
48
const [ showSidebar , setShowSidebar ] = useState ( true )
48
49
49
50
return (
50
51
< >
52
+ < Dialog
53
+ open = { isSignInDialogOpen }
54
+ onOpenChange = { ( open ) => {
55
+ setIsSignInDialogOpen ( open )
56
+ } }
57
+ >
58
+ < DialogContent className = "max-w-2xl" >
59
+ < DialogHeader >
60
+ < DialogTitle > Sign in to create a database</ DialogTitle >
61
+ < div className = "py-2 border-b" />
62
+ </ DialogHeader >
63
+ < h2 className = "font-bold" > Why do I need to sign in?</ h2 >
64
+ < p >
65
+ Even though your Postgres databases run{ ' ' }
66
+ < a
67
+ className = "underline"
68
+ href = "https://pglite.dev"
69
+ target = "_blank"
70
+ rel = "noopener noreferrer"
71
+ >
72
+ directly in the browser
73
+ </ a >
74
+ , we still need to connect to an API that runs the large language model (required for
75
+ all database interactions).
76
+ </ p >
77
+ < p > We ask you to sign in to prevent API abuse.</ p >
78
+ < div className = "flex justify-center items-center my-3" >
79
+ < SignInButton />
80
+ </ div >
81
+ </ DialogContent >
82
+ </ Dialog >
51
83
< AnimatePresence initial = { false } mode = "popLayout" >
52
84
{ showSidebar && (
53
85
< m . div
@@ -83,8 +115,12 @@ export default function Sidebar() {
83
115
< m . div layout = "position" layoutId = "new-database-button" >
84
116
< Button
85
117
onClick = { ( ) => {
86
- router . push ( '/' )
87
- focusRef . current ?. focus ( )
118
+ if ( ! user ) {
119
+ setIsSignInDialogOpen ( true )
120
+ } else {
121
+ router . push ( '/' )
122
+ focusRef . current ?. focus ( )
123
+ }
88
124
} }
89
125
className = "gap-2"
90
126
>
@@ -176,8 +212,12 @@ export default function Sidebar() {
176
212
< Button
177
213
size = { 'icon' }
178
214
onClick = { ( ) => {
179
- router . push ( '/' )
180
- focusRef . current ?. focus ( )
215
+ if ( ! user ) {
216
+ setIsSignInDialogOpen ( true )
217
+ } else {
218
+ router . push ( '/' )
219
+ focusRef . current ?. focus ( )
220
+ }
181
221
} }
182
222
>
183
223
< PackagePlus size = { 14 } />
@@ -201,24 +241,24 @@ export default function Sidebar() {
201
241
</ TooltipContent >
202
242
</ Tooltip >
203
243
{ user && (
204
- < Tooltip >
205
- < TooltipTrigger asChild >
206
- < m . div layout = "position" layoutId = "sign-out-button" >
207
- < Button
208
- size = { 'icon' }
209
- variant = "secondary"
210
- onClick = { async ( ) => {
211
- await signOut ( )
212
- } }
213
- >
214
- < LogOut size = { 16 } strokeWidth = { 2 } />
215
- </ Button >
216
- </ m . div >
217
- </ TooltipTrigger >
218
- < TooltipContent side = "right" >
219
- < p > Sign out</ p >
220
- </ TooltipContent >
221
- </ Tooltip >
244
+ < Tooltip >
245
+ < TooltipTrigger asChild >
246
+ < m . div layout = "position" layoutId = "sign-out-button" >
247
+ < Button
248
+ size = { 'icon' }
249
+ variant = "secondary"
250
+ onClick = { async ( ) => {
251
+ await signOut ( )
252
+ } }
253
+ >
254
+ < LogOut size = { 16 } strokeWidth = { 2 } />
255
+ </ Button >
256
+ </ m . div >
257
+ </ TooltipTrigger >
258
+ < TooltipContent side = "right" >
259
+ < p > Sign out</ p >
260
+ </ TooltipContent >
261
+ </ Tooltip >
222
262
) }
223
263
</ div >
224
264
</ div >
@@ -258,7 +298,7 @@ function DatabaseMenuItem({ database, isActive }: DatabaseMenuItemProps) {
258
298
< DialogTitle > Deployments are in Private Alpha</ DialogTitle >
259
299
< div className = "py-2 border-b" />
260
300
</ DialogHeader >
261
- < h2 className = "font-medium " > What are deployments?</ h2 >
301
+ < h2 className = "font-bold " > What are deployments?</ h2 >
262
302
< p >
263
303
Deploy your database to a serverless PGlite instance so that it can be accessed outside
264
304
the browser using any Postgres client:
0 commit comments