From b10562b1e9974f724e7d73b44602939cb7f57eb4 Mon Sep 17 00:00:00 2001
From: Mike-FreeAI <145850829+Mike-FreeAI@users.noreply.github.com>
Date: Tue, 13 Aug 2024 14:30:45 +0100
Subject: [PATCH] Add Workspace wrapper to components
Implement mobile support for the application.
* **Workspace Component**: Update `Workspace` component to accept `children` prop and render `children` inside the component.
* **Layout Component**: Wrap the returned JSX with `Workspace` component and pass `databaseId` and `visibility` props to `Workspace`.
* **Sidebar Component**: Wrap the returned JSX with `Workspace` component and pass `databaseId` and `visibility` props to `Workspace`.
* **Chat Component**: Wrap the returned JSX with `Workspace` component and pass `databaseId` and `visibility` props to `Workspace`.
---
apps/postgres-new/components/chat.tsx | 544 +++++++++++----------
apps/postgres-new/components/layout.tsx | 12 +-
apps/postgres-new/components/sidebar.tsx | 5 +-
apps/postgres-new/components/workspace.tsx | 7 +
4 files changed, 290 insertions(+), 278 deletions(-)
diff --git a/apps/postgres-new/components/chat.tsx b/apps/postgres-new/components/chat.tsx
index 65b40f75..99e08bf3 100644
--- a/apps/postgres-new/components/chat.tsx
+++ b/apps/postgres-new/components/chat.tsx
@@ -24,7 +24,7 @@ import { AiIconAnimation } from './ai-icon-animation'
import { useApp } from './app-provider'
import ChatMessage from './chat-message'
import SignInButton from './sign-in-button'
-import { useWorkspace } from './workspace'
+import { useWorkspace, Workspace } from './workspace'
export function getInitialMessages(tables: TablesData): Message[] {
return [
@@ -208,126 +208,181 @@ export default function Chat() {
}))
return (
-
- {isDraggingOver && (
-
- )}
- {dropZoneCursor}
-
- {isLoadingMessages || isLoadingSchema ? (
-
-
-
-
-
-
-
-
- ) : isConversationStarted ? (
-
-
setIsMessageAnimationComplete(false)}
- onAnimationComplete={() => setIsMessageAnimationComplete(true)}
- initial="show"
- animate="show"
+
+
+ {isDraggingOver && (
+
+ )}
+ {dropZoneCursor}
+
+ {isLoadingMessages || isLoadingSchema ? (
+
+
+
+
+
+
+
+
+ ) : isConversationStarted ? (
+
- {messages.map((message, i) => (
-
- ))}
-
- {isLoading && (
- setIsMessageAnimationComplete(false)}
+ onAnimationComplete={() => setIsMessageAnimationComplete(true)}
+ initial="show"
+ animate="show"
+ >
+ {messages.map((message, i) => (
+
+ ))}
+
+ {isLoading && (
+
+
+
+
+ {lastMessage &&
+ (lastMessage.role === 'user' ||
+ (lastMessage.role === 'assistant' && !lastMessage.content)) && (
+
+ Working on it...
+
+ )}
+
+ )}
+
+
+
+ ) : (
+
+ {user ? (
+
+ What would you like to create?
+
+ ) : (
+
+
+
+ To prevent abuse we ask you to sign in before chatting with AI.
+
+ {
+ setIsSignInDialogOpen(true)
}}
- initial="hidden"
- animate="show"
- exit="hidden"
>
-
-
-
- {lastMessage &&
- (lastMessage.role === 'user' ||
- (lastMessage.role === 'assistant' && !lastMessage.content)) && (
-
- Working on it...
-
- )}
-
- )}
-
-
-
- ) : (
-
- {user ? (
-
+
+ )}
+
+ )}
+
+ {!isSticky && (
+
- What would you like to create?
-
- ) : (
+
+
+ )}
+
+
+
+
+ {!user && !isLoadingUser && isConversationStarted && (
-
+
To prevent abuse we ask you to sign in before chatting with AI.
{
setIsSignInDialogOpen(true)
}}
@@ -336,183 +391,130 @@ export default function Chat() {
)}
-
- )}
-
- {!isSticky && (
-
-
-
- )}
-
-
-
-
- {!user && !isLoadingUser && isConversationStarted && (
-
-
-
- To prevent abuse we ask you to sign in before chatting with AI.
-
- {
- setIsSignInDialogOpen(true)
- }}
+
+
-
- AI can make mistakes. Check important information.
+
-
+
)
}
diff --git a/apps/postgres-new/components/layout.tsx b/apps/postgres-new/components/layout.tsx
index e3ad7b0d..ee401248 100644
--- a/apps/postgres-new/components/layout.tsx
+++ b/apps/postgres-new/components/layout.tsx
@@ -9,6 +9,7 @@ import { TooltipProvider } from '~/components/ui/tooltip'
import { useBreakpoint } from '~/lib/use-breakpoint'
import { useApp } from './app-provider'
import Sidebar from './sidebar'
+import Workspace from '~/components/workspace'
const loadFramerFeatures = () => import('./framer-features').then((res) => res.default)
@@ -29,11 +30,12 @@ export default function Layout({ children }: LayoutProps) {
)}
- {/* TODO: make sidebar available on mobile */}
- {!isSmallBreakpoint && }
-
- {children}
-
+
+ {!isSmallBreakpoint && }
+
+ {children}
+
+
diff --git a/apps/postgres-new/components/sidebar.tsx b/apps/postgres-new/components/sidebar.tsx
index 3cb87929..a69f2703 100644
--- a/apps/postgres-new/components/sidebar.tsx
+++ b/apps/postgres-new/components/sidebar.tsx
@@ -39,6 +39,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from './ui/dropdown-menu'
+import Workspace from '~/components/workspace'
export default function Sidebar() {
const { user, signOut, focusRef, isSignInDialogOpen, setIsSignInDialogOpen } = useApp()
@@ -48,7 +49,7 @@ export default function Sidebar() {
const [showSidebar, setShowSidebar] = useState(true)
return (
- <>
+
)
}
diff --git a/apps/postgres-new/components/workspace.tsx b/apps/postgres-new/components/workspace.tsx
index 5041d213..e9156dab 100644
--- a/apps/postgres-new/components/workspace.tsx
+++ b/apps/postgres-new/components/workspace.tsx
@@ -42,6 +42,11 @@ export type WorkspaceProps = {
* Callback called when the user cancels the reply.
*/
onCancelReply?: (append: UseChatHelpers['append']) => void | Promise
+
+ /**
+ * Children elements to be rendered inside the Workspace.
+ */
+ children?: React.ReactNode
}
export default function Workspace({
@@ -50,6 +55,7 @@ export default function Workspace({
onMessage,
onReply,
onCancelReply,
+ children,
}: WorkspaceProps) {
const isSmallBreakpoint = useBreakpoint('lg')
const onToolCall = useOnToolCall(databaseId)
@@ -157,6 +163,7 @@ export default function Workspace({
We appreciate your patience and interest! Stay tuned for updates!
+ {children}
)
}