You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
import {edit_handler, cancel_handler, text_change_handler, save_handler} from './handlers/Note.js';
|
|
|
|
function Note(vnode_init){
|
|
const {dispatch} = vnode_init.attrs;
|
|
return {
|
|
view: function(vnode){
|
|
const {state, note_state} = vnode.attrs;
|
|
const {is_editing, is_focused, note_id} = note_state;
|
|
const note = state.db[note_id].model;
|
|
if(is_editing){
|
|
return m('.note', [
|
|
m('textarea', {key: 'textarea', onchange: text_change_handler.bind(null, note_state, dispatch), oncreate: is_focused?({dom})=>{ dom.focus(); delete note_state.is_focused; }:null }, note_state.temp_text),
|
|
m('.buttons', {key: 'editing-buttons'}, [
|
|
m('button', {key: 'cancel-button', onclick: cancel_handler.bind(null, state, note_state, dispatch) }, 'Cancel'),
|
|
m('button', {key: 'save-button', onclick: save_handler.bind(null, note_state, dispatch) }, 'Save')
|
|
])
|
|
]);
|
|
}
|
|
else{
|
|
return m('.note', [
|
|
m('.text', {key: 'text'}, note.text),
|
|
m('.buttons', {key: 'viewing-buttons'}, [
|
|
m('button', {key: 'edit-button', onclick: edit_handler.bind(null, note_state, dispatch) }, 'Edit')
|
|
])
|
|
]);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export default Note; |