|
| 1 | +import { useLanguage } from '@/intl/client'; |
| 2 | +import { tString } from '@/intl/translate'; |
1 | 3 | import { tcls } from '@/lib/tailwind'; |
2 | 4 | import { AIMessageRole } from '@gitbook/api'; |
3 | 5 | import type React from 'react'; |
@@ -46,17 +48,9 @@ export function AIChatMessages(props: { |
46 | 48 | {message.content ? message.content : null} |
47 | 49 |
|
48 | 50 | {isLastMessage && chat.loading ? ( |
49 | | - <div className="flex w-full animate-fade-in-slow flex-wrap gap-2"> |
50 | | - {Array.from({ length: 7 }).map((_, index) => ( |
51 | | - <div |
52 | | - key={index} |
53 | | - className="h-4 animate-[fadeIn_500ms_ease_both,pulse_1.5s_infinite] circular-corners:rounded-2xl rounded-corners:rounded-md bg-tint-4" |
54 | | - style={{ |
55 | | - width: `calc(${(index % 4) * 20 + 10}% - 4px)`, |
56 | | - animationDelay: `${index * 0.1}s`, |
57 | | - }} |
58 | | - /> |
59 | | - ))} |
| 51 | + <div className="flex w-full animate-fade-in-slow flex-col gap-2"> |
| 52 | + {!message.content ? <HoldMessage /> : null} |
| 53 | + <LoadingSkeleton /> |
60 | 54 | </div> |
61 | 55 | ) : null} |
62 | 56 |
|
@@ -86,3 +80,55 @@ export function AIChatMessages(props: { |
86 | 80 | </> |
87 | 81 | ); |
88 | 82 | } |
| 83 | + |
| 84 | +function HoldMessage() { |
| 85 | + const language = useLanguage(); |
| 86 | + |
| 87 | + return ( |
| 88 | + <div className="animate-[heightIn_500ms_4500ms_ease_both] py-2 text-tint-subtle"> |
| 89 | + {tString(language, 'ai_chat_hold_message_1') |
| 90 | + .split(' ') |
| 91 | + .map((word, index) => ( |
| 92 | + <span |
| 93 | + key={index} |
| 94 | + className="animate-fade-in-slow" |
| 95 | + style={{ |
| 96 | + animationDelay: `${5000 + index * 200}ms`, |
| 97 | + }} |
| 98 | + > |
| 99 | + {word}{' '} |
| 100 | + </span> |
| 101 | + ))} |
| 102 | + {tString(language, 'ai_chat_hold_message_2') |
| 103 | + .split(' ') |
| 104 | + .map((word, index) => ( |
| 105 | + <span |
| 106 | + key={index} |
| 107 | + className="animate-fade-in-slow" |
| 108 | + style={{ |
| 109 | + animationDelay: `${10000 + index * 200}ms`, |
| 110 | + }} |
| 111 | + > |
| 112 | + {word}{' '} |
| 113 | + </span> |
| 114 | + ))} |
| 115 | + </div> |
| 116 | + ); |
| 117 | +} |
| 118 | + |
| 119 | +function LoadingSkeleton() { |
| 120 | + return ( |
| 121 | + <div className="flex flex-wrap gap-2"> |
| 122 | + {Array.from({ length: 7 }).map((_, index) => ( |
| 123 | + <div |
| 124 | + key={index} |
| 125 | + className="h-4 animate-[fadeIn_500ms_ease_both,pulse_1.5s_infinite] circular-corners:rounded-2xl rounded-corners:rounded-md bg-tint-4" |
| 126 | + style={{ |
| 127 | + width: `calc(${(index % 4) * 20 + 10}% - 4px)`, |
| 128 | + animationDelay: `${index * 0.1}s`, |
| 129 | + }} |
| 130 | + /> |
| 131 | + ))} |
| 132 | + </div> |
| 133 | + ); |
| 134 | +} |
0 commit comments