@@ -2,13 +2,13 @@ package todo
22
33import bootstrap.*
44import component.ButtonBar
5- import platform.toDate
5+ import component.bootstrap.textInput
66import platform.toProviderDate
77import react.*
88import react.router.dom.RouteResultHistory
99import component.repository.ID
1010import platform.launchHandlingErrors
11- import todo.model.Factory
11+ import platform.toJsDate
1212import todo.model.ToDo
1313import util.emptyToNull
1414import kotlin.js.Date
@@ -33,18 +33,23 @@ interface ToDoState : RState {
3333class ToDoScreen (props : ToDoProps ) : RComponent<ToDoProps, ToDoState>(props) {
3434
3535 override fun ToDoState.init (props : ToDoProps ) {
36- original = props.id?.let { Factory .toDoRepository.find(it) }
36+ original = props.id?.let { Config .toDoRepository.find(it) }
3737 name = original?.name ? : " "
38- dueDate = original?.dueDate?.toDate ()
38+ dueDate = original?.dueDate?.toJsDate ()
3939 notes = original?.notes ? : " "
4040 validated = false
4141 }
4242
4343 private fun save (event : React .SubmitEvent ) {
4444 if (event.currentTarget?.checkValidity() == true && state.name.isNotBlank()) {
45- val updatedToDo = ToDo (state.name, state.dueDate?.toProviderDate(), state.notes.emptyToNull(), id = state.original?.id)
45+ val updatedToDo = ToDo (
46+ name = state.name,
47+ dueDate = state.dueDate?.toProviderDate(),
48+ notes = state.notes.emptyToNull(),
49+ id = state.original?.id
50+ )
4651 launchHandlingErrors(" save $updatedToDo " ) {
47- Factory .toDoRepository.save(updatedToDo)
52+ Config .toDoRepository.save(updatedToDo)
4853 }
4954 props.history.goBack()
5055 }
@@ -60,7 +65,7 @@ class ToDoScreen(props: ToDoProps) : RComponent<ToDoProps, ToDoState>(props) {
6065 private fun delete () {
6166 state.original?.id?.let { toDoId ->
6267 launchHandlingErrors(" delete $toDoId " ) {
63- Factory .toDoRepository.remove(toDoId)
68+ Config .toDoRepository.remove(toDoId)
6469 }
6570 }
6671 props.history.goBack()
@@ -76,33 +81,11 @@ class ToDoScreen(props: ToDoProps) : RComponent<ToDoProps, ToDoState>(props) {
7681 attrs.onSubmit = { save(it); it.preventDefault() }
7782 attrs.validated = state.validated
7883 attrs.onSubmit = { event -> save(event); event.preventDefault() }
79- child(Form .Group ::class ) {
80- attrs.controlId = " name"
81- child(Form .Label ::class ) { + " Description" }
82- child(InputGroup ::class ) {
83- textInputControl {
84- attrs.value = state.name
85- attrs.required = true
86- attrs.placeholder = " (some description)"
87- attrs.size = 40
88- attrs.onAnyChange = { it.target?.let { setState { name = it.value } } }
89- attrs.required = true
90- }
91- child(Form .Control .Feedback ::class ) {
92- attrs.type = " invalid"
93- + " Please Specify a Name"
94- }
95- }
84+ textInput(" To Do" , state.name, " (some description)" , required = true ) {
85+ setState { name = it ? : " " }
9686 }
97- child(Form .Group ::class ) {
98- attrs.controlId = " note"
99- child(Form .Label ::class ) { + " Notes" }
100- textInputControl {
101- attrs.value = state.notes
102- attrs.placeholder = " (some notes)"
103- attrs.size = 60
104- attrs.onAnyChange = { it.target?.let { setState { notes = it.value } } }
105- }
87+ textInput(" Notes" , state.notes, " (some notes)" ) {
88+ setState { notes = it ? : " " }
10689 }
10790 child(Form .Group ::class ) {
10891 child(ButtonToolbar ::class ) {
0 commit comments