habitica-sync/src/view/Components/Taskview/Dailiesview/DailyItem.tsx

38 lines
2 KiB
TypeScript
Raw Normal View History

2021-11-16 18:53:03 +05:30
import * as React from "react";
2021-11-20 17:11:13 +08:00
import ReactMarkdown from "react-markdown";
2021-10-17 21:58:59 -07:00
function DailyItem(props: any) {
2021-11-28 22:47:54 +08:00
const [state, setState] = React.useState('view')
const [title, setTitle] = React.useState('')
const [notes, setNotes] = React.useState('')
2021-11-29 23:20:09 +08:00
if (state === 'view') {
2021-11-28 22:47:54 +08:00
return (
2021-11-23 23:00:47 +08:00
<div className="todo-item" id={props.id}>
<input type="checkbox" className="checkbox" id={props.id} onChange={props.onChange} checked={props.completed} />
<div className="todo-content">
2021-12-05 18:14:39 +08:00
<ReactMarkdown children={props.daily_text} />
2021-11-23 23:00:47 +08:00
<ReactMarkdown children={props.daily_notes} />
</div>
2021-11-29 23:20:09 +08:00
<button className="task-operation">
2021-11-28 22:47:54 +08:00
<span className="material-icons md-24" id={props.id} onClick={() => setState('edit')}>create</span>
2021-11-23 23:00:47 +08:00
</button>
<button className="task-operation">
2021-11-28 22:47:54 +08:00
<span className="material-icons md-24" id={props.id} onClick={props.onChange} title="delete">clear</span>
2021-11-23 23:00:47 +08:00
</button>
2021-11-20 17:11:13 +08:00
</div>
2021-11-28 22:47:54 +08:00
)
} else {
return (
2021-11-29 23:20:09 +08:00
<div className="edit-daily-item edit-item">
2021-11-28 22:47:54 +08:00
<input type="text" onChange={event => setTitle(event.target.value)} defaultValue={props.daily_text}></input>
<input type="text" onChange={event => setNotes(event.target.value)} defaultValue={props.daily_notes}></input>
2021-11-29 23:20:09 +08:00
<div className="edit-daily-button edit-button">
<button className="task-operation"><span className="material-icons md-24" id={props.id} onClick={function (e) { props.onChange(e); setState('view') }} title="submit" data-title={title} data-notes={notes}>check</span></button>
<button className="task-operation"><span className="material-icons md-24" id={props.id} onClick={() => setState('view')} title="cancel">clear</span></button>
</div>
2021-11-28 22:47:54 +08:00
</div>
)
}
2021-10-17 21:58:59 -07:00
}
export default DailyItem