|
1 | 1 | import type React from 'react'; |
2 | 2 | import { useEffect, useRef } from 'react'; |
3 | 3 |
|
4 | | -import { ChevronRight } from 'lucide-react'; |
5 | | - |
6 | 4 | import { Button } from '@/components/ui/button'; |
7 | 5 |
|
8 | 6 | import type { TargetVerse } from './DraftingPage'; |
@@ -78,12 +76,29 @@ export const TargetPanel: React.FC<TargetPanelProps> = ({ |
78 | 76 | }; |
79 | 77 |
|
80 | 78 | useEffect(() => { |
| 79 | + const activeVerseElement = verseRefs.current[activeVerseId]; |
81 | 80 | const textarea = textareaRefs.current[activeVerseId]; |
| 81 | + |
| 82 | + if (activeVerseElement && scrollRef.current) { |
| 83 | + const container = scrollRef.current; |
| 84 | + const verseTop = activeVerseElement.offsetTop; |
| 85 | + const verseHeight = activeVerseElement.offsetHeight; |
| 86 | + const containerHeight = container.clientHeight; |
| 87 | + const currentScroll = container.scrollTop; |
| 88 | + |
| 89 | + if (verseTop < currentScroll || verseTop + verseHeight > currentScroll + containerHeight) { |
| 90 | + container.scrollTo({ |
| 91 | + top: verseTop - containerHeight / 2 + verseHeight / 2, |
| 92 | + behavior: 'smooth', |
| 93 | + }); |
| 94 | + } |
| 95 | + } |
| 96 | + |
82 | 97 | if (textarea) { |
83 | 98 | textarea.focus(); |
84 | 99 | autoResizeTextarea(textarea); |
85 | 100 | } |
86 | | - }, [activeVerseId]); |
| 101 | + }, [activeVerseId, scrollRef]); |
87 | 102 |
|
88 | 103 | useEffect(() => { |
89 | 104 | if (verses.length === 0) { |
@@ -115,7 +130,7 @@ export const TargetPanel: React.FC<TargetPanelProps> = ({ |
115 | 130 | style={{ scrollbarWidth: 'thin' }} |
116 | 131 | onScroll={handleScroll} |
117 | 132 | > |
118 | | - <div className='space-y-4 pb-6'> |
| 133 | + <div className={`space-y-4 ${verses.length < totalSourceVerses ? 'pb-48' : 'pb-6'}`}> |
119 | 134 | {Array.from({ length: totalSourceVerses }, (_, index) => { |
120 | 135 | const verseId = index + 1; |
121 | 136 | const TargetVerse = verses.find(kv => kv.verseNumber === verseId); |
@@ -152,25 +167,24 @@ export const TargetPanel: React.FC<TargetPanelProps> = ({ |
152 | 167 | </div> |
153 | 168 | ); |
154 | 169 | })} |
155 | | - </div> |
156 | 170 |
|
157 | | - {verses.length < totalSourceVerses && ( |
158 | | - <div className='mb-12 flex justify-end pb-6'> |
159 | | - <Button |
160 | | - className={`bg-primary flex items-center gap-2 px-6 py-2 font-medium shadow-lg transition-all ${ |
161 | | - verses.find(v => v.verseNumber === activeVerseId)?.content.trim() |
162 | | - ? 'hover:bg-primary-hover cursor-pointer text-white' |
163 | | - : 'cursor-not-allowed bg-gray-300 text-gray-500' |
164 | | - }`} |
165 | | - disabled={!verses.find(v => v.verseNumber === activeVerseId)?.content.trim()} |
166 | | - title='Enter' |
167 | | - onClick={() => moveToNextVerse()} |
168 | | - > |
169 | | - Next Verse |
170 | | - <ChevronRight className='h-4 w-4' /> |
171 | | - </Button> |
172 | | - </div> |
173 | | - )} |
| 171 | + {verses.length < totalSourceVerses && ( |
| 172 | + <div className='flex justify-end'> |
| 173 | + <Button |
| 174 | + className={`bg-primary flex items-center gap-2 px-6 py-2 font-medium shadow-lg transition-all ${ |
| 175 | + verses.find(v => v.verseNumber === activeVerseId)?.content.trim() |
| 176 | + ? 'hover:bg-primary-hover cursor-pointer text-white' |
| 177 | + : 'cursor-not-allowed bg-gray-300 text-gray-500' |
| 178 | + }`} |
| 179 | + disabled={!verses.find(v => v.verseNumber === activeVerseId)?.content.trim()} |
| 180 | + title='Enter' |
| 181 | + onClick={() => moveToNextVerse()} |
| 182 | + > |
| 183 | + Next Verse |
| 184 | + </Button> |
| 185 | + </div> |
| 186 | + )} |
| 187 | + </div> |
174 | 188 | </div> |
175 | 189 | </div> |
176 | 190 | ); |
|
0 commit comments