import { store } from 'app/store' export const getSection = index => { const { sections } = store.getState().viewer return sections[index] } export const getNextSection = section => { const { sections } = store.getState().viewer if (section.index === sections.length - 1) { return null } return sections[section.index + 1] } export const parseCredits = lines => { let sections = [] let current lines.split("\n").forEach((s, i) => { if (s[0] === "#") { current = { title: s.replace("#", "").trim(), lines: [], i } sections.push(current) } else { current.lines.push(s.trim()) } }) return sections } export const groupColumns = (lines, cols) => { const perColumn = Math.floor(lines.length / cols) const columns = [] for (let i = 0; i < cols; i++) { columns.push(lines.slice(i * perColumn, (i+1) * perColumn)) } return columns }