Writer's Friend
is a visual tool to improve writing experience. It will allow users to to easily navigate through their works and and edit texts.
-
Users can create entities, like trees with following levels:
- world
- book series
- book
- chapter/story
Entities are stored in Redux store as an ordered array of entities of highest level, with nested array of children-entities. Nesting goes up to 4 levels.
Redux store updated using following function.
export let updateEntity = (array, child) => { //finding original entity let oldChild = findEntity(array, child.id); //generating updated entity let newChild = {...oldChild, ...child}; //if order parameter not passed - remove it if (child.order===undefined) delete newChild.order; //create a full copy of original array let newArray = deepCopy(array); //if position was changed if (oldChild.parentId !== newChild.parentId || (newChild.order!==undefined && oldChild.order !== newChild.order)) { //remove entity from original position newArray = removeEntity(array, oldChild.id); //adjust order if (newChild.order === "last" || newChild.parentId === null){ delete newChild.order; } else if (oldChild.parentId === newChild.parentId && newChild.order > oldChild.order) { newChild.order--; } //add entity to the new position newArray = addEntity(newArray, newChild); } //if position stayed the same else { if (oldChild.parentId === null) { //for top level - update entity newArray = updateFn(array, newChild) } else { //for deeper-level entity - copy array with callback function that would update entity when it get's to it let path = findPath(array, newChild.id) newArray = copyArray(array, newChild, path, updateFn) } } return newArray; }
-
Chapters
andstories
are leaf-entities.There are 2 ways to
create new story/chapter
:- Through entity creation form:
- Pressing Start writing button - that would create story on the hiest level.
-
import Cookies from 'js-cookie'; const [theme, setTheme] = useState("peach") // array of pre-defined themes const themeList = useMemo(()=>["peach", "beach", "midnight", "dark"],[]); // check cookies for set theme useEffect(() => { dispatch(sessionActions.restoreUser()) .then(() => { if (Cookies.get('color-theme') && themeList.includes(Cookies.get('color-theme'))) { setTheme(Cookies.get('color-theme')) } else { Cookies.set('color-theme','peach') } setIsLoaded(true) }); }, [dispatch, themeList]); //set theme-class to body useEffect(()=>{ document.body.setAttribute("class", "") document.body.classList.add(theme) },[theme])
I used CSS variables to set colors for each theme
.midnight { --bg-color1: #245579; --text-color1: #000; --text-hover1: #ffbc42; --bg-color2: #d81159; --text-color2: #333; --text-hover2: #ffbc42; ... }