${page}
`
}//}}}
componentDidMount() {//{{{
this.props.app.startNode.retrieve(node=>{
this.node.value = node
// The tree isn't guaranteed to have loaded yet. This is also run from
// the tree code, in case the node hasn't loaded.
this.props.app.tree.crumbsUpdateNodes(node)
})
}//}}}
keyHandler(evt) {//{{{
let handled = true
switch(evt.key.toUpperCase()) {
case 'E':
if(evt.shiftKey && evt.altKey)
this.showPage('keys')
else
handled = false
break
case 'N':
if(evt.shiftKey && evt.altKey)
this.createNode()
else
handled = false
break
case 'P':
if(evt.shiftKey && evt.altKey)
this.showPage('node-properties')
else
handled = false
break
case 'S':
if(evt.ctrlKey || (evt.shiftKey && evt.altKey))
this.saveNode()
else
handled = false
break
case 'U':
if(evt.shiftKey && evt.altKey)
this.showPage('upload')
else
handled = false
default:
handled = false
}
if(handled) {
evt.preventDefault()
evt.stopPropagation()
}
}//}}}
showMenu(evt) {//{{{
evt.stopPropagation()
this.menu.value = true
}//}}}
logout() {//{{{
window.localStorage.removeItem('session.UUID')
location.href = '/'
}//}}}
goToNode(nodeID, dontPush) {//{{{
if(this.props.app.nodeModified.value) {
if(!confirm("Changes not saved. Do you want to discard changes?"))
return
}
if(!dontPush)
history.pushState({ nodeID }, '', `/?node=${nodeID}`)
// New node is fetched in order to retrieve content and files.
// Such data is unnecessary to transfer for tree/navigational purposes.
let node = new Node(this.props.app, nodeID)
node.retrieve(node=>{
this.props.app.nodeModified.value = false
this.node.value = node
// Tree needs to know another node is selected, in order to render any
// previously selected node not selected.
this.props.app.tree.setSelected(node)
// Hide tree toggle, as this would be the next natural action to do manually anyway.
// At least in mobile mode.
document.getElementById('app').classList.remove('toggle-tree')
})
}//}}}
createNode(evt) {//{{{
if(evt)
evt.stopPropagation()
let name = prompt("Name")
if(!name)
return
this.node.value.create(name, nodeID=>this.goToNode(nodeID))
}//}}}
saveNode() {//{{{
let content = this.nodeContent.current.contentDiv.current.value
this.node.value.save(content, ()=>this.props.app.nodeModified.value = false)
}//}}}
renameNode() {//{{{
let name = prompt("New name")
if(!name)
return
this.node.value.rename(name, ()=>{
this.goToNode(this.node.value.ID)
this.menu.value = false
})
}//}}}
deleteNode() {//{{{
if(!confirm("Do you want to delete this note and all sub-notes?"))
return
this.node.value.delete(()=>{
this.goToNode(this.node.value.ParentID)
this.menu.value = false
})
}//}}}
showPage(pg) {//{{{
this.page.value = pg
}//}}}
}
class NodeContent extends Component {
constructor(props) {//{{{
super(props)
this.contentDiv = createRef()
this.state = {
modified: false,
//content: props.content,
}
}//}}}
render({ content }) {//{{{
return html`