Skip to content

Commit

Permalink
Small fixes (#245)
Browse files Browse the repository at this point in the history
* Doc info rendering deferred. Doc info does not need realtime rendering.
* Small tweaks
  • Loading branch information
mkoskim authored Oct 13, 2024
1 parent bc13cbd commit 6f7191b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/gui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Inform,
ListItemText,
Typography,
DeferredRender,
} from "../common/factory";

import { OpenFolderButton, HeadInfo, WordInfo, CharInfo, WordsToday } from "../common/components";
Expand Down Expand Up @@ -291,16 +292,16 @@ function WithDoc({setCommand, doc, updateDoc, recent}) {
<Separator />
<ViewSelectButtons selected={doc.ui.view.selected} setSelected={setSelected}/>
<Separator/>
{/* No need for real time rendering */}
<DeferredRender>
<HeadInfo head={head} updateDoc={updateDoc}/>
<Separator />
<Filler />

<Separator/>
<WordsToday text={text} last={doc.head.last}/>
<WordInfo text={text} missing={missing} chars={chars} last={doc.head.last}/>
<Separator/>
<WordInfo text={text} missing={missing}/>
<Separator/>
<CharInfo chars={chars}/>
</DeferredRender>
{/* <CloseButton setCommand={setCommand}/> */}

<Separator />
Expand Down
36 changes: 22 additions & 14 deletions src/gui/common/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TextField,
Label,
Accordion, AccordionSummary, AccordionDetails,
Separator,
} from "../common/factory";

import PopupState, { bindTrigger, bindMenu } from 'material-ui-popup-state';
Expand Down Expand Up @@ -254,31 +255,38 @@ export class HeadInfo extends React.PureComponent {
}
}

export class WordsToday extends React.PureComponent {
export class WordInfo extends React.PureComponent {
render() {
const {text, last} = this.props;
if(!last) return null;
const {text, missing, last, chars} = this.props;

const delta = text - last.text
return <Label>Today: {delta >= 0 ? "+" : ""}{delta}</Label>
const detail = missing ? `-${missing}` : ""

return <>
Words:&nbsp;<span style={{color: "green"}}>{text}</span>
<Separator/>
<WordsToday text={text} last={last}/>
<Separator/>
Target: {text + missing}&nbsp;<span style={{color: "firebrick"}}>{detail}</span>
<Separator/>
<CharInfo chars={chars}/>
</>
}
}

export class WordInfo extends React.PureComponent {
class CharInfo extends React.PureComponent {
render() {
const {text, missing} = this.props;

const total = `Words: ${text + missing}`
const detail = missing ? ` (${text} / ${missing})` : ""
const {chars} = this.props;

return <Label>{total}{detail}</Label>
return <Label>Chars: {chars}</Label>
}
}

export class CharInfo extends React.PureComponent {
class WordsToday extends React.PureComponent {
render() {
const {chars} = this.props;
const {text, last} = this.props;
if(!last) return null;

return <Label>Chars: {chars}</Label>
const delta = text - last.text
return <Label>Today: {delta >= 0 ? "+" : ""}{delta}</Label>
}
}

0 comments on commit 6f7191b

Please sign in to comment.