Skip to content

Commit

Permalink
added word count to the edit screen
Browse files Browse the repository at this point in the history
  • Loading branch information
meg-ghana committed Sep 17, 2023
1 parent 55baeb8 commit 108af45
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
22 changes: 15 additions & 7 deletions src/screens/EPub/models/data_reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ export default {
chapters[chapterIdx].title = value;
return { ...state, epub: { ...state.epub, ...nextStateOfChapters([...chapters]) } };
},
splitChaptersByScreenshots(state, {payload: {wc}}) {
splitChaptersByScreenshots(state, {payload: {wc}}) { // Enforces Word Count
console.log(`Splitting chapters by screenshots`);
const new_items = [];
const new_items = []; //duplicating some sentences (sentences with less than wc words)

Check failure on line 329 in src/screens/EPub/models/data_reducer.js

View workflow job for this annotation

GitHub Actions / Build

Expected exception block, space or tab after '//' in comment
// min word count that each chapter should have
const default_word_count = 25;
let min_word_count = wc;
Expand All @@ -340,13 +340,20 @@ export default {
}
// loop through chapters and enforce minimum wc
(state.items).forEach(function(elem) {

Check failure on line 342 in src/screens/EPub/models/data_reducer.js

View workflow job for this annotation

GitHub Actions / Build

Block must not be padded by blank lines
let words = (elem.text).split(' ').length;
if (words < min_word_count && new_items.length!==0 ) {

if (new_items.length!==0) {
const oldelem = new_items.pop();
let words = (oldelem.text).split(' ').length;
if(words < min_word_count ) {
// append shorter text to previous chapter
oldelem.text += " ";
oldelem.text += elem.text;
new_items.push(oldelem);
oldelem.text += " ";
oldelem.text += elem.text;
new_items.push(oldelem);
}
else {
new_items.push(oldelem);
new_items.push(elem)
}
} else {
new_items.push(elem);
}
Expand All @@ -366,6 +373,7 @@ export default {
}
let splitChapters = _.map(
new_items,
//state.items

Check failure on line 376 in src/screens/EPub/models/data_reducer.js

View workflow job for this annotation

GitHub Actions / Build

Expected exception block, space or tab after '//' in comment
(data, idx) =>
new EPubChapterData({
items: [data],
Expand Down
1 change: 0 additions & 1 deletion src/screens/EPub/views/EditEPubChapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function EditEPubChapter({ dispatch }) {
<CTFragment width="67%">
<ChapterEditor />
</CTFragment>

<CTFragment
className="ct-epb ech-tool-bar"
sticky
Expand Down
3 changes: 2 additions & 1 deletion src/screens/EPub/views/EditEPubStructure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ function EditEPubStructure({ epub: epubData, dispatch }) {
<CTHeading>{epubData.title}</CTHeading>
<ChapterList setEPubItem={setEPubItem} />
</CTFragment>

<CTFragment sticky scrollY dFlexCol width="35%" padding={[30, 10]}>
<Instruction expanded={instExp} onToggle={toggleInstExp} />
{itemViewElem}
<QuickActions />
</CTFragment>

</CTFragment>
</EPubNavigationProvider>
);
Expand Down
36 changes: 33 additions & 3 deletions src/screens/EPub/views/EditINote/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import React, { useEffect, useState } from 'react';
import _ from 'lodash'
import { CTFragment, CTHeading, CTText } from 'layout';
import { CTFragment, CTHeading, CTText, altEl } from 'layout';
import { connect } from 'dva'
import { EPubNavigationProvider } from '../../components';
import { epub as epubController} from '../../controllers';
import { epub as epubController, generateEPubGuide} from '../../controllers';
import INoteEditor from './INoteEditor';
import Instruction from '../EditEPubStructure/Instruction';
import EPubItemView from '../EditEPubStructure/EPubItemView';
import QuickActions from '../EditEPubStructure/QuickActions';

// import './index.scss';

function EditINote ({epub: epubData, dispatch}) {
const dispatchScroll = _.debounce((e) => dispatch({ type: 'epub/onScroll', payload: e }), 300)
const onScroll = (e) => dispatchScroll(e.target)

const [ePubItem, setEPubItem] = useState(null);
const [instExp, setInstExp] = useState(true);

const toggleInstExp = (e, newExpanded) => setInstExp(newExpanded);

useEffect(() => {
// show the user onboard guide if possible
setTimeout(() => {
const guide = generateEPubGuide();
guide.start();
}, 1000);
}, []);

useEffect(() => {
if (Boolean(ePubItem) && instExp) {
setInstExp(false);
}
}, [ePubItem]);
const itemViewElem = altEl(EPubItemView, Boolean(ePubItem), {
item: ePubItem, setEPubItem
});

const [iNoteItem, setINoteItem] = useState(null);
return (
<EPubNavigationProvider>
<CTFragment dFlex h100 scrollY id={epubController.id.EPubChapterListID} onScroll={onScroll}>
<CTFragment width="75%">
<CTFragment width="65%">
<CTHeading>{epubData.title}</CTHeading>
<INoteEditor> setINoteItem={setINoteItem} dispatch={dispatch} </INoteEditor>
</CTFragment>
<CTFragment sticky scrollY dFlexCol width="35%" padding={[30, 10]}>
<Instruction expanded={instExp} onToggle={toggleInstExp} />
{itemViewElem}
<QuickActions />
</CTFragment>
</CTFragment>
</EPubNavigationProvider>
)
Expand Down

0 comments on commit 108af45

Please sign in to comment.