File tree Expand file tree Collapse file tree 1 file changed +27
-17
lines changed
Expand file tree Collapse file tree 1 file changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -440,23 +440,33 @@ export const CourseReview = ({
440440 </ div >
441441 </ div >
442442 </ div >
443- { review . content . length < 300 || readMore ? (
444- < div className = 'ml-1 mr-4 mt-2 hyphens-auto break-words text-left text-gray-800 dark:text-gray-300' >
445- { review . content }
446- </ div >
447- ) : (
448- < >
449- < div className = 'ml-1 mr-4 mt-2 hyphens-auto break-words text-left text-gray-800 dark:text-gray-300' >
450- { review . content . substring ( 0 , 300 ) + '...' }
451- </ div >
452- < button
453- className = 'ml-1 mr-auto pt-1 text-gray-700 underline transition duration-300 ease-in-out hover:text-red-500 dark:text-gray-300 dark:hover:text-red-500'
454- onClick = { ( ) => setReadMore ( true ) }
455- >
456- Show more
457- </ button >
458- </ >
459- ) }
443+ { ( ( ) => {
444+ const newlineCount = ( review . content . match ( / \n / g) || [ ] ) . length ;
445+ const visualLength = review . content . length + newlineCount * 50 ;
446+ const shouldTruncate = visualLength >= 300 && ! readMore ;
447+
448+ if ( ! shouldTruncate ) {
449+ return (
450+ < div className = 'ml-1 mr-4 mt-2 hyphens-auto whitespace-pre-wrap break-words text-left text-gray-800 dark:text-gray-300' >
451+ { review . content }
452+ </ div >
453+ ) ;
454+ }
455+
456+ return (
457+ < >
458+ < div className = 'ml-1 mr-4 mt-2 hyphens-auto whitespace-pre-wrap break-words text-left text-gray-800 dark:text-gray-300' >
459+ { review . content . substring ( 0 , 300 ) + '...' }
460+ </ div >
461+ < button
462+ className = 'ml-1 mr-auto pt-1 text-gray-700 underline transition duration-300 ease-in-out hover:text-red-500 dark:text-gray-300 dark:hover:text-red-500'
463+ onClick = { ( ) => setReadMore ( true ) }
464+ >
465+ Show more
466+ </ button >
467+ </ >
468+ ) ;
469+ } ) ( ) }
460470 </ div >
461471 </ div >
462472 </ div >
You can’t perform that action at this time.
0 commit comments