📉
slate-transcript-editor-docs
  • Slate Transcript Editor - Docs
  • notes
    • Apple script testing
    • css-injection-karaoke
    • insert-text-at-selection
    • set-selection
    • notes
    • web workers
    • Takeaways form draftJs vs Slate
    • pause-while-typing
    • verbose-generate-previous-timings-up-to-current-func
  • ADR
    • [short title of solved problem and solution] - ADR Template
Powered by GitBook
On this page

Was this helpful?

  1. notes

verbose-generate-previous-timings-up-to-current-func

/**
 * See explanation in `src/utils/dpe-to-slate/index.js` for how this function works with css injection
 * to provide current paragaph's highlight.
 * @param {Number} currentTime - float in seconds
 */
const generatePreviousTimingsUpToCurrent = (currentTime) => {
  const lastWordStartTime = props.transcriptData.words[props.transcriptData.words.length - 1].start;
  const lastWordStartTimeInt = parseInt(lastWordStartTime);
  const emptyListOfTimes = Array(lastWordStartTimeInt);
  const listOfTimesInt = [...emptyListOfTimes.keys()];
  const listOfTimesUpToCurrentTimeInt = listOfTimesInt.splice(0, currentTime, 0);
  const stringlistOfTimesUpToCurrentTimeInt = listOfTimesUpToCurrentTimeInt.join(' ');
  return stringlistOfTimesUpToCurrentTimeInt;
};

One line

const generatePreviousTimingsUpToCurrent = (currentTime) => {
  return [...Array(parseInt(props.transcriptData.words[props.transcriptData.words.length - 1].start)).keys()].splice(0, currentTime, 0).join(' ');
};

simplified without using words

function generatePreviousTimingsUpToCurrent(start) {
  return new Array(parseInt(start))
    .fill(1)
    .map((_, i) => i + 1)
    .join(' ');
}
Previouspause-while-typingNextADR

Last updated 3 years ago

Was this helpful?