From 236d71bdbac148cb63f6cae2a96d85f199af7a4d Mon Sep 17 00:00:00 2001 From: paulclindo Date: Wed, 29 Nov 2023 17:55:18 -0500 Subject: [PATCH 1/9] refactor: shinkai-tray ui components --- .../src/components/chat/message.tsx | 16 +- .../shinkai-tray/src/components/ui/avatar.tsx | 48 ----- .../shinkai-tray/src/components/ui/button.tsx | 70 ------- .../src/components/ui/checkbox.tsx | 28 --- .../src/components/ui/command.tsx | 153 --------------- .../components/ui/copy-to-clipboard-icon.tsx | 48 ----- .../shinkai-tray/src/components/ui/dialog.tsx | 118 ------------ .../src/components/ui/dots-loader.tsx | 13 -- .../src/components/ui/error-message.tsx | 10 - apps/shinkai-tray/src/components/ui/form.tsx | 181 ------------------ .../src/components/ui/hover-card.tsx | 27 --- apps/shinkai-tray/src/components/ui/input.tsx | 25 --- apps/shinkai-tray/src/components/ui/label.tsx | 24 --- .../src/components/ui/popover.tsx | 29 --- .../src/components/ui/qr-code.tsx | 32 ---- .../src/components/ui/scroll-area.tsx | 53 ----- .../shinkai-tray/src/components/ui/select.tsx | 118 ------------ .../src/components/ui/separator.tsx | 29 --- .../src/components/ui/skeleton.tsx | 18 -- .../shinkai-tray/src/components/ui/switch.tsx | 27 --- .../src/components/ui/textarea.tsx | 48 ----- .../src/components/ui/tooltip.tsx | 28 --- apps/shinkai-tray/src/globals.css | 10 +- .../src/pages/chat/chat-conversation.tsx | 26 +-- .../src/pages/chat/empty-message.tsx | 16 +- apps/shinkai-tray/src/pages/chat/layout.tsx | 26 +-- apps/shinkai-tray/src/pages/create-agent.tsx | 57 ++---- apps/shinkai-tray/src/pages/create-chat.tsx | 18 +- apps/shinkai-tray/src/pages/create-job.tsx | 32 ++-- apps/shinkai-tray/src/pages/generate-code.tsx | 35 ++-- .../src/pages/layout/main-layout.tsx | 28 ++- .../src/pages/layout/simple-layout.tsx | 1 + apps/shinkai-tray/src/pages/onboarding.tsx | 26 +-- apps/shinkai-tray/tailwind.config.js | 14 +- libs/shinkai-ui/src/components/command.tsx | 9 +- libs/shinkai-ui/src/components/textfield.tsx | 11 +- 36 files changed, 144 insertions(+), 1308 deletions(-) delete mode 100644 apps/shinkai-tray/src/components/ui/avatar.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/button.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/checkbox.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/command.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/copy-to-clipboard-icon.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/dialog.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/dots-loader.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/error-message.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/form.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/hover-card.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/input.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/label.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/popover.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/qr-code.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/scroll-area.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/select.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/separator.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/skeleton.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/switch.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/textarea.tsx delete mode 100644 apps/shinkai-tray/src/components/ui/tooltip.tsx diff --git a/apps/shinkai-tray/src/components/chat/message.tsx b/apps/shinkai-tray/src/components/chat/message.tsx index 9d42633dd..9d398b419 100644 --- a/apps/shinkai-tray/src/components/chat/message.tsx +++ b/apps/shinkai-tray/src/components/chat/message.tsx @@ -1,17 +1,19 @@ import type { ShinkaiMessage } from '@shinkai_network/shinkai-message-ts/models'; import { MessageSchemaType } from '@shinkai_network/shinkai-message-ts/models'; import { ChatConversationMessage } from '@shinkai_network/shinkai-node-state/lib/queries/getChatConversation/types'; -import MarkdownPreview from '@uiw/react-markdown-preview'; - -import { cn } from '../../lib/utils'; -import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'; -import CopyToClipboardIcon from '../ui/copy-to-clipboard-icon'; import { + Avatar, + AvatarFallback, + AvatarImage, + CopyToClipboardIcon, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, -} from '../ui/tooltip'; +} from '@shinkai_network/shinkai-ui'; +import MarkdownPreview from '@uiw/react-markdown-preview'; + +import { cn } from '../../lib/utils'; export const getMessageFilesInbox = ( message: ShinkaiMessage, @@ -70,7 +72,7 @@ const Message = ({
, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -Avatar.displayName = AvatarPrimitive.Root.displayName; - -const AvatarImage = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -AvatarImage.displayName = AvatarPrimitive.Image.displayName; - -const AvatarFallback = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; - -export { Avatar, AvatarImage, AvatarFallback }; diff --git a/apps/shinkai-tray/src/components/ui/button.tsx b/apps/shinkai-tray/src/components/ui/button.tsx deleted file mode 100644 index 9ff48f1c3..000000000 --- a/apps/shinkai-tray/src/components/ui/button.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import { Slot } from '@radix-ui/react-slot'; -import { cva, type VariantProps } from 'class-variance-authority'; -import { Loader } from 'lucide-react'; -import * as React from 'react'; - -import { cn } from '../../lib/utils'; - -const buttonVariants = cva( - 'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-gray-300', - { - variants: { - variant: { - default: - 'bg-primary-600 hover:bg-primary-700 text-white shadow dark:bg-gray-50 dark:text-gray-900 dark:hover:bg-gray-50/90', - destructive: - 'bg-red-500 text-gray-50 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:text-gray-50 dark:hover:bg-red-900/90', - outline: - 'border border-gray-200 bg-transparent shadow-sm hover:bg-gray-100 hover:text-gray-900 dark:border-gray-800 dark:hover:bg-gray-800 dark:hover:text-gray-50', - secondary: - 'bg-gray-100 text-gray-900 shadow-sm hover:bg-gray-100/80 dark:bg-gray-800 dark:text-gray-50 dark:hover:bg-gray-800/80', - ghost: - 'hover:bg-gray-800 hover:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-50', - link: 'text-gray-900 underline-offset-4 hover:underline dark:text-gray-50', - }, - size: { - default: 'h-9 px-4 py-2', - sm: 'h-8 rounded-md px-3 text-xs', - lg: 'h-10 rounded-md px-8', - icon: 'h-9 w-9', - }, - }, - defaultVariants: { - variant: 'default', - size: 'default', - }, - }, -); - -export interface ButtonProps - extends React.ButtonHTMLAttributes, - VariantProps { - asChild?: boolean; - isLoading?: boolean; -} - -const Button = React.forwardRef( - ( - { className, variant, size, asChild = false, isLoading = false, ...props }, - ref, - ) => { - const Comp = asChild ? Slot : 'button'; - return ( - - {isLoading ? ( - - ) : null} - {isLoading && size === 'icon' ? null : props.children} - - ); - }, -); -Button.displayName = 'Button'; - -export { Button, buttonVariants }; diff --git a/apps/shinkai-tray/src/components/ui/checkbox.tsx b/apps/shinkai-tray/src/components/ui/checkbox.tsx deleted file mode 100644 index 51ae52220..000000000 --- a/apps/shinkai-tray/src/components/ui/checkbox.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import * as CheckboxPrimitive from '@radix-ui/react-checkbox'; -import { CheckIcon } from '@radix-ui/react-icons'; -import * as React from 'react'; - -import { cn } from '../../lib/utils'; - -const Checkbox = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - - - -)); -Checkbox.displayName = CheckboxPrimitive.Root.displayName; - -export { Checkbox }; diff --git a/apps/shinkai-tray/src/components/ui/command.tsx b/apps/shinkai-tray/src/components/ui/command.tsx deleted file mode 100644 index 006d7b245..000000000 --- a/apps/shinkai-tray/src/components/ui/command.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import { DialogProps } from '@radix-ui/react-dialog'; -import { MagnifyingGlassIcon } from '@radix-ui/react-icons'; -import { Command as CommandPrimitive } from 'cmdk'; -import * as React from 'react'; - -import { cn } from '../../lib/utils'; -import { Dialog, DialogContent } from './dialog'; - -const Command = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -Command.displayName = CommandPrimitive.displayName; - -interface CommandDialogProps extends DialogProps {} - -const CommandDialog = ({ children, ...props }: CommandDialogProps) => { - return ( - - - - {children} - - - - ); -}; - -const CommandInput = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( -
- - -
-)); - -CommandInput.displayName = CommandPrimitive.Input.displayName; - -const CommandList = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandList.displayName = CommandPrimitive.List.displayName; - -const CommandEmpty = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->((props, ref) => ( - -)); - -CommandEmpty.displayName = CommandPrimitive.Empty.displayName; - -const CommandGroup = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandGroup.displayName = CommandPrimitive.Group.displayName; - -const CommandSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -CommandSeparator.displayName = CommandPrimitive.Separator.displayName; - -const CommandItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandItem.displayName = CommandPrimitive.Item.displayName; - -const CommandShortcut = ({ - className, - ...props -}: React.HTMLAttributes) => { - return ( - - ); -}; -CommandShortcut.displayName = 'CommandShortcut'; - -export { - Command, - CommandDialog, - CommandInput, - CommandList, - CommandEmpty, - CommandGroup, - CommandItem, - CommandShortcut, - CommandSeparator, -}; diff --git a/apps/shinkai-tray/src/components/ui/copy-to-clipboard-icon.tsx b/apps/shinkai-tray/src/components/ui/copy-to-clipboard-icon.tsx deleted file mode 100644 index 77dcd5843..000000000 --- a/apps/shinkai-tray/src/components/ui/copy-to-clipboard-icon.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { CheckCircle2, CopyIcon } from 'lucide-react'; -import { useState } from 'react'; - -import { cn } from '../../lib/utils'; -import { Button } from './button'; - -type CopyToClipboardIconProps = { - string?: string; - children?: React.ReactNode; - className?: string; -}; - -const CopyToClipboardIcon = ({ - string, - children, - className, -}: CopyToClipboardIconProps) => { - const [clipboard, setClipboard] = useState(false); - - let timeout: ReturnType; - const onCopy = () => { - if (!string) return; - const string_ = string.trim(); - navigator.clipboard.writeText(string_); - setClipboard(true); - clearTimeout(timeout); - timeout = setTimeout(() => setClipboard(false), 1000); - }; - - const ClipboardIcon = clipboard ? CheckCircle2 : CopyIcon; - - return ( - - ); -}; - -export default CopyToClipboardIcon; diff --git a/apps/shinkai-tray/src/components/ui/dialog.tsx b/apps/shinkai-tray/src/components/ui/dialog.tsx deleted file mode 100644 index 72eccf934..000000000 --- a/apps/shinkai-tray/src/components/ui/dialog.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import * as DialogPrimitive from '@radix-ui/react-dialog'; -import { Cross2Icon } from '@radix-ui/react-icons'; -import * as React from 'react'; - -import { cn } from '../../lib/utils'; - -const Dialog = DialogPrimitive.Root; - -const DialogTrigger = DialogPrimitive.Trigger; - -const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => ( - -); -DialogPortal.displayName = DialogPrimitive.Portal.displayName; - -const DialogOverlay = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; - -const DialogContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( - - - - {children} - - - Close - - - -)); -DialogContent.displayName = DialogPrimitive.Content.displayName; - -const DialogHeader = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-); -DialogHeader.displayName = 'DialogHeader'; - -const DialogFooter = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-); -DialogFooter.displayName = 'DialogFooter'; - -const DialogTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogTitle.displayName = DialogPrimitive.Title.displayName; - -const DialogDescription = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogDescription.displayName = DialogPrimitive.Description.displayName; - -export { - Dialog, - DialogTrigger, - DialogContent, - DialogHeader, - DialogFooter, - DialogTitle, - DialogDescription, -}; diff --git a/apps/shinkai-tray/src/components/ui/dots-loader.tsx b/apps/shinkai-tray/src/components/ui/dots-loader.tsx deleted file mode 100644 index 18d01ceb4..000000000 --- a/apps/shinkai-tray/src/components/ui/dots-loader.tsx +++ /dev/null @@ -1,13 +0,0 @@ -const DotsLoader = ({ className }: { className?: string }) => { - return ( -
-
-
-
-
-
-
- ); -}; - -export default DotsLoader; diff --git a/apps/shinkai-tray/src/components/ui/error-message.tsx b/apps/shinkai-tray/src/components/ui/error-message.tsx deleted file mode 100644 index f075ad541..000000000 --- a/apps/shinkai-tray/src/components/ui/error-message.tsx +++ /dev/null @@ -1,10 +0,0 @@ -const ErrorMessage = ({ message }: { message: string }) => { - return ( -
- Error: - {message} -
- ); -}; - -export default ErrorMessage; diff --git a/apps/shinkai-tray/src/components/ui/form.tsx b/apps/shinkai-tray/src/components/ui/form.tsx deleted file mode 100644 index 19f0f0f09..000000000 --- a/apps/shinkai-tray/src/components/ui/form.tsx +++ /dev/null @@ -1,181 +0,0 @@ -import * as LabelPrimitive from '@radix-ui/react-label'; -import { Slot } from '@radix-ui/react-slot'; -import * as React from 'react'; -import { - Controller, - ControllerProps, - FieldPath, - FieldValues, - FormProvider, - useFormContext, -} from 'react-hook-form'; - -import { cn } from '../../lib/utils'; -import { Label } from './label'; - -const Form = FormProvider; - -type FormFieldContextValue< - TFieldValues extends FieldValues = FieldValues, - TName extends FieldPath = FieldPath, -> = { - name: TName; -}; - -const FormFieldContext = React.createContext( - {} as FormFieldContextValue, -); - -const FormField = < - TFieldValues extends FieldValues = FieldValues, - TName extends FieldPath = FieldPath, ->({ - ...props -}: ControllerProps) => { - return ( - - - - ); -}; - -const useFormField = () => { - const fieldContext = React.useContext(FormFieldContext); - const itemContext = React.useContext(FormItemContext); - const { getFieldState, formState } = useFormContext(); - - const fieldState = getFieldState(fieldContext.name, formState); - - if (!fieldContext) { - throw new Error('useFormField should be used within '); - } - - const { id } = itemContext; - - return { - id, - name: fieldContext.name, - formItemId: `${id}-form-item`, - formDescriptionId: `${id}-form-item-description`, - formMessageId: `${id}-form-item-message`, - ...fieldState, - }; -}; - -type FormItemContextValue = { - id: string; -}; - -const FormItemContext = React.createContext( - {} as FormItemContextValue, -); - -const FormItem = React.forwardRef< - HTMLDivElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => { - const id = React.useId(); - - return ( - -
- - ); -}); -FormItem.displayName = 'FormItem'; - -const FormLabel = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => { - const { error, formItemId } = useFormField(); - - return ( -