diff --git a/apps/database-new/app/NewThreadInput.tsx b/apps/database-new/app/NewThreadInput.tsx deleted file mode 100644 index 2fca0c6cc71..00000000000 --- a/apps/database-new/app/NewThreadInput.tsx +++ /dev/null @@ -1,35 +0,0 @@ -'use client' - -import { AssistantChatForm } from '@/components/AssistantChatForm' -import { useAppStateSnapshot } from '@/lib/state' -import { createClient } from '@/lib/supabase/client' - -const NewThreadInput = () => { - const supabase = createClient() - const snap = useAppStateSnapshot() - - return ( - <> -
- aaaaa - { - const { - data: { user }, - } = await supabase.auth.getUser() - if (!user) { - snap.setLoginDialogOpen(true) - return false - } - return true - }} - placeholder="e.g Create a Telegram-like chat application" - /> -
- - ) -} - -export default NewThreadInput diff --git a/apps/database-new/app/[thread_id]/[message_id]/page.tsx b/apps/database-new/app/[thread_id]/[message_id]/page.tsx index 4ff81c18eb7..3c8b3fc3f83 100644 --- a/apps/database-new/app/[thread_id]/[message_id]/page.tsx +++ b/apps/database-new/app/[thread_id]/[message_id]/page.tsx @@ -9,7 +9,9 @@ import { CodeEditor } from './CodeEditor' import { Messages } from './Messages' import { SchemaFlow } from './SchemaFlow' import { getAssistantResponse } from './getAssistantMessage' - +import { createClient } from '@/lib/supabase/client' +import { LoginDialog } from '@/app/LoginDialog' +import LoginForm from '@/components/Auth/LoginForm' export interface ThreadPageProps { params: { thread_id: string @@ -19,7 +21,11 @@ export interface ThreadPageProps { export default async function ThreadPage({ params }: ThreadPageProps) { const promise = getAssistantResponse(params.thread_id, params.message_id) + const supabase = createClient() + const { + data: { user }, + } = await supabase.auth.getUser() return (
- +
@@ -50,6 +56,10 @@ export default async function ThreadPage({ params }: ThreadPageProps) { }> + + + + ) diff --git a/apps/database-new/app/page.tsx b/apps/database-new/app/page.tsx index da4528f1609..8de02322f55 100644 --- a/apps/database-new/app/page.tsx +++ b/apps/database-new/app/page.tsx @@ -1,9 +1,9 @@ // import LoginForm from '@/components/Auth/LoginForm' import type { Metadata } from 'next' import { LoginDialog } from './LoginDialog' -import NewThreadInput from './NewThreadInput' import LoginForm from '@/components/Auth/LoginForm' import RecentlyGenerated from '@/components/RecentlyGenerated' +import { AssistantChatForm } from '@/components/AssistantChatForm' export const metadata: Metadata = { title: 'database.design | Create', @@ -17,7 +17,13 @@ const NewThread = async ({ return ( <>
- +
+ +
+ {/* @Terry - just throwing this in here for now. we may want to reconfigre the h-full/justify-center of the input */} diff --git a/apps/database-new/components/AssistantChatForm/index.tsx b/apps/database-new/components/AssistantChatForm/index.tsx index df77176b4cd..7b79e0658df 100644 --- a/apps/database-new/components/AssistantChatForm/index.tsx +++ b/apps/database-new/components/AssistantChatForm/index.tsx @@ -2,13 +2,22 @@ import { Loader2 } from 'lucide-react' import { useParams } from 'next/navigation' -import { ChangeEvent, FormHTMLAttributes, ReactNode, forwardRef, useRef } from 'react' +import { + ChangeEvent, + FormHTMLAttributes, + ReactNode, + forwardRef, + useEffect, + useRef, + useState, +} from 'react' + import { useFormStatus } from 'react-dom' import { TextArea_Shadcn_, cn } from 'ui' - +import { useAppStateSnapshot } from '@/lib/state' import { ChatSuggestions } from './ChatSuggestions' import { upsertMessageFormAction } from './action' - +import { createClient } from '@/lib/supabase/client' export interface FormProps extends FormHTMLAttributes { loading?: boolean disabled?: boolean @@ -62,18 +71,28 @@ const SubmitButton = forwardRef Promise } -const AssistantChatForm = ({ - chatContext, - placeholder, - canSubmit = () => Promise.resolve(true), -}: AssistantChatFormProps) => { +const AssistantChatForm = ({ placeholder }: AssistantChatFormProps) => { + const supabase = createClient() + const snap = useAppStateSnapshot() + const { thread_id } = useParams() + const textAreaRef = useRef(null) + const [isLoggedIn, setIsLoggedIn] = useState(false) + + useEffect(() => { + async function checkUser() { + const { + data: { user }, + } = await supabase.auth.getUser() + if (user) setIsLoggedIn(true) + } + checkUser() + }) const disabled = false @@ -101,10 +120,7 @@ const AssistantChatForm = ({
{ - const flag = await canSubmit() - if (flag) { - upsertMessageFormAction(formData) - } + isLoggedIn ? upsertMessageFormAction(formData) : snap.setLoginDialogOpen(true) }} >
@@ -132,7 +148,8 @@ const AssistantChatForm = ({ isLoading={disabled} />
- {chatContext === 'new' && ( + + {!thread_id && ( { if (textAreaRef?.current) textAreaRef.current.value = v