From 60411550a5e1da0b231d8446a8af065bb09419f3 Mon Sep 17 00:00:00 2001 From: eduardruzga Date: Fri, 22 Nov 2024 11:05:18 +0200 Subject: [PATCH] Make tooltip easier to reuse across the app --- app/components/chat/BaseChat.tsx | 326 ++++++++++++++---------- app/components/chat/Messages.client.tsx | 68 ++--- app/components/sidebar/HistoryItem.tsx | 31 ++- app/components/sidebar/Menu.client.tsx | 13 +- app/components/ui/Tooltip.tsx | 24 ++ 5 files changed, 258 insertions(+), 204 deletions(-) create mode 100644 app/components/ui/Tooltip.tsx diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 902cb23..627d959 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -1,7 +1,7 @@ // @ts-nocheck // Preventing TS checks with files presented in the video for a better presentation. import type { Message } from 'ai'; -import React, { type RefCallback, useEffect } from 'react'; +import React, { type RefCallback, useEffect, useState } from 'react'; import { ClientOnly } from 'remix-utils/client-only'; import { Menu } from '~/components/sidebar/Menu.client'; import { IconButton } from '~/components/ui/IconButton'; @@ -10,9 +10,11 @@ import { classNames } from '~/utils/classNames'; import { MODEL_LIST, DEFAULT_PROVIDER, PROVIDER_LIST, initializeModelList } from '~/utils/constants'; import { Messages } from './Messages.client'; import { SendButton } from './SendButton.client'; -import { useState } from 'react'; import { APIKeyManager } from './APIKeyManager'; import Cookies from 'js-cookie'; +import { importChat } from '~/utils/chatExport'; +import { toast } from 'react-toastify'; +import * as Tooltip from '@radix-ui/react-tooltip'; import styles from './BaseChat.module.scss'; import type { ProviderInfo } from '~/utils/types'; @@ -22,7 +24,7 @@ const EXAMPLE_PROMPTS = [ { text: 'Build a simple blog using Astro' }, { text: 'Create a cookie consent form using Material UI' }, { text: 'Make a space invaders game' }, - { text: 'How do I center a div?' }, + { text: 'How do I center a div?' } ]; const providerList = PROVIDER_LIST; @@ -107,9 +109,9 @@ export const BaseChat = React.forwardRef( sendMessage, handleInputChange, enhancePrompt, - handleStop, + handleStop }, - ref, + ref ) => { const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200; const [apiKeys, setApiKeys] = useState>({}); @@ -145,7 +147,7 @@ export const BaseChat = React.forwardRef( expires: 30, // 30 days secure: true, // Only send over HTTPS sameSite: 'strict', // Protect against CSRF - path: '/', // Accessible across the site + path: '/' // Accessible across the site }); } catch (error) { console.error('Error saving API keys to cookies:', error); @@ -153,72 +155,73 @@ export const BaseChat = React.forwardRef( }; return ( -
- {() => } -
-
- {!chatStarted && ( -
-

- Where ideas begin -

-

- Bring ideas to life in seconds or get help on existing projects. -

-
- )} -
- - {() => { - return chatStarted ? ( - - ) : null; - }} - + +
+ {() => } +
+
+ {!chatStarted && ( +
+

+ Where ideas begin +

+

+ Bring ideas to life in seconds or get help on existing projects. +

+
+ )}
- - {provider && ( - updateApiKey(provider.name, key)} - /> - )} + + {() => { + return chatStarted ? ( + + ) : null; + }} +
+ + {provider && ( + updateApiKey(provider.name, key)} + /> + )} +