Add paginated outputText
This commit is contained in:
		
							parent
							
								
									797ef6a1fa
								
							
						
					
					
						commit
						f87acd5514
					
				| @ -30,7 +30,9 @@ export const RsvpReader = () => { | |||||||
|         <Options></Options> |         <Options></Options> | ||||||
|         <TotalTime /> |         <TotalTime /> | ||||||
|       </div> |       </div> | ||||||
|       <div className={styles.item}>{/* <TextOutput /> */}</div> |       <div className={styles.item}> | ||||||
|  |         <TextOutput /> | ||||||
|  |       </div> | ||||||
|     </div> |     </div> | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| .current { | .current { | ||||||
|   text-decoration: underline; |   background-color: yellow; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .sentenceBeginning { | .sentenceBeginning { | ||||||
|  | |||||||
| @ -5,17 +5,26 @@ import classNames from 'classnames' | |||||||
| import { getNextSmallerNumber } from '../lib/array-util.js' | import { getNextSmallerNumber } from '../lib/array-util.js' | ||||||
| import { | import { | ||||||
|   selectParsedText, |   selectParsedText, | ||||||
|   selectCurrentSegmentIndex |   selectCurrentSegmentIndex, | ||||||
|  |   selectDisplayMode, | ||||||
|  |   selectSegmentWindow | ||||||
| } from '../store/selectors.js' | } from '../store/selectors.js' | ||||||
| 
 | 
 | ||||||
| import styles from './TextOutput.css' | import styles from './TextOutput.css' | ||||||
| 
 | 
 | ||||||
| export const TextOutput = () => { | export const TextOutput = () => { | ||||||
|   const { segments, sentences, words } = useSelector(selectParsedText) |   const { segments, offset } = useSelector(selectSegmentWindow) | ||||||
|  |   const { sentences, words } = useSelector(selectParsedText) | ||||||
|   const curSegment = useSelector(selectCurrentSegmentIndex) |   const curSegment = useSelector(selectCurrentSegmentIndex) | ||||||
|  |   const mode = useSelector(selectDisplayMode) | ||||||
|   return ( |   return ( | ||||||
|  |     <> | ||||||
|  |       <div> | ||||||
|  |         {mode}, {offset} | ||||||
|  |       </div> | ||||||
|       <div> |       <div> | ||||||
|         {segments.map((segment, idx) => { |         {segments.map((segment, idx) => { | ||||||
|  |           idx = idx + offset | ||||||
|           const isCurrent = curSegment === idx |           const isCurrent = curSegment === idx | ||||||
|           const isWordStart = words.includes(idx) |           const isWordStart = words.includes(idx) | ||||||
|           const wordBeginning = isWordStart |           const wordBeginning = isWordStart | ||||||
| @ -38,5 +47,6 @@ export const TextOutput = () => { | |||||||
|           ) |           ) | ||||||
|         })} |         })} | ||||||
|       </div> |       </div> | ||||||
|  |     </> | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
|  | |||||||
| @ -15,7 +15,15 @@ export const initialState = { | |||||||
|   wpm: 300, |   wpm: 300, | ||||||
|   offset: -15, |   offset: -15, | ||||||
|   running: false, |   running: false, | ||||||
|   lang: 'en' |   lang: 'en', | ||||||
|  |   textDisplay: { | ||||||
|  |     mode: 'pagination', | ||||||
|  |     options: { | ||||||
|  |       pagination: { pageLength: 50 }, | ||||||
|  |       segments: { prev: 9, next: 40 }, | ||||||
|  |       sentences: { prev: 1, next: 8 } | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const reducer = { | const reducer = { | ||||||
|  | |||||||
| @ -11,9 +11,10 @@ const notNull = val => val != null | |||||||
| // parsedText selectors
 | // parsedText selectors
 | ||||||
| 
 | 
 | ||||||
| export const selectMaxLength = state => state.maxLength | export const selectMaxLength = state => state.maxLength | ||||||
|  | export const selectOriginalText = state => state.originalText | ||||||
| 
 | 
 | ||||||
| export const selectParsedText = createSelector( | export const selectParsedText = createSelector( | ||||||
|   state => state.originalText, |   selectOriginalText, | ||||||
|   selectMaxLength, |   selectMaxLength, | ||||||
|   (originalText, maxLength) => parseText(originalText, maxLength) |   (originalText, maxLength) => parseText(originalText, maxLength) | ||||||
| ) | ) | ||||||
| @ -166,3 +167,26 @@ export const selectTotalTime = createSelector(selectIntervals, intervals => | |||||||
| // player
 | // player
 | ||||||
| 
 | 
 | ||||||
| export const selectRunning = state => state.running | export const selectRunning = state => state.running | ||||||
|  | 
 | ||||||
|  | // text display
 | ||||||
|  | 
 | ||||||
|  | export const selectDisplayMode = state => state.textDisplay.mode | ||||||
|  | export const selectDisplayOptions = state => state.textDisplay.options | ||||||
|  | export const selectCurrentDisplayOptions = createSelector( | ||||||
|  |   selectDisplayMode, | ||||||
|  |   selectDisplayOptions, | ||||||
|  |   (mode, options) => options[mode] | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | export const selectSegmentWindow = createSelector( | ||||||
|  |   selectDisplayMode, | ||||||
|  |   selectCurrentDisplayOptions, | ||||||
|  |   selectCurrentSegmentIndex, | ||||||
|  |   selectSegments, | ||||||
|  |   (mode, options, idx, segments) => { | ||||||
|  |     const page = Math.floor(idx / options.pageLength) | ||||||
|  |     const start = page * options.pageLength | ||||||
|  |     const end = page * options.pageLength + options.pageLength | ||||||
|  |     return { offset: start, segments: segments.slice(start, end) } | ||||||
|  |   } | ||||||
|  | ) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user