refuses to load private bins; fixed NodeJS startup error connectiong to Postgres

This commit is contained in:
brian
2021-04-13 00:52:57 -04:00
parent 8432255890
commit 555e33040b
8 changed files with 150 additions and 71 deletions
+1
View File
@@ -27,6 +27,7 @@ function App(vnode_init){
const o = function(handler){ return handler.bind(null, s, dispatch); }
const o1 = function(handler, p1){ return handler.bind(null, s, dispatch, p1); }
return m('.app', {key: 'app'}, [
m('.error-message', {key:'error-message'}, s.error_message),
m('.top', {key: 'top'}, [
m('.top-left', {key: 'top-left'}, [
m('button', {key: 'button', onclick: o(new_note_handler)}, 'New Note...'),
+21 -6
View File
@@ -10,7 +10,12 @@ const preventDblClickSelection = function(e){
const load_notes = function(state, dispatch){
api.post('/load-notes', {bin_id: state.bin_id})
.then(res=>{
dispatch('notes-loaded', res.notes);
if(res.success===true){
dispatch('notes-loaded', res.notes);
}
else if(res.authorized===false){
dispatch('notes-unauthorized');
}
});
};
const runSearch = function(state, dispatch){
@@ -86,11 +91,21 @@ const choose_bin_handler = function(state, dispatch, bin_id){
dispatch('bin-requested', bin_id);
api.post('/load-bin', {bin_id})
.then(res=>{
dispatch('bin-loaded', res.bin);
});
api.post('/load-notes', {bin_id})
.then(res=>{
dispatch('notes-loaded', res.notes);
if(res.success===true){
dispatch('bin-loaded', res.bin);
api.post('/load-notes', {bin_id})
.then(res=>{
if(res.success===true && res.authorized===true){
dispatch('notes-loaded', res.notes);
}
else if(res.success===false && res.authorized===false){
dispatch('notes-unauthorized');
}
});
}
else if(res.success===false && res.authorized==false){
dispatch('bin-unauthorized');
}
});
};
+18 -4
View File
@@ -3,11 +3,18 @@ import api from '../api.js';
const initial_load_bin_handler = function(state, dispatch, bin_id){
api.post('/load-bin', {bin_id})
.then(res => {
dispatch('bin-loaded', res.bin);
if(res.success===false && res.authorized===false){
dispatch('bin-unauthorized');
}
else{
dispatch('bin-loaded', res.bin);
}
});
api.post('/load-notes', {bin_id})
.then(res => {
dispatch('notes-loaded', res.notes);
if(res.success===true){
dispatch('notes-loaded', res.notes);
}
});
};
@@ -22,11 +29,18 @@ const hash_change_handler = function(state, dispatch, e){
dispatch('bin-requested', bin_id);
api.post('/load-bin', {bin_id})
.then(res=>{
dispatch('bin-loaded', res.bin);
if(res.success==true){
dispatch('bin-loaded', res.bin);
}
else if(res.authorized===false){
dispatch('bin-unauthorized');
}
});
api.post('/load-notes', {bin_id})
.then(res => {
dispatch('notes-loaded', res.notes);
if(res.success==true){
dispatch('notes-loaded', res.notes);
}
});
}
};
+10
View File
@@ -14,6 +14,16 @@ body{
}
/* end full-page app */
.error-message{
position: fixed;
top: 0px;
margin-top: 1rem;
width: 40%;
margin-right: auto;
margin-left: auto;
background-color: #ee8888;
}
.app{
height: 100%;
width: 100%;
+5 -2
View File
@@ -99,12 +99,14 @@ function addToBinListIfLoggedIn(state){
const reducer = handleActions({
'new-bin': (s, bin) => { i(s,bin); ref(s,s,'bin_id',bin.id); s.notes=[]; s.temp_bin_name=bin.id; },
'bin-requested': (s, bin_id) => { i(s,{id:bin_id}); ref(s,s,'bin_id',bin_id); s.notes = []; },
'bin-requested': (s, bin_id) => { i(s,{id:bin_id}); ref(s,s,'bin_id',bin_id); s.notes = []; s.error_message=''; },
'bin-loaded': (s, bin) => { i(s,bin); ref(s,s,'bin_id',bin.id); s.temp_bin_name=bin.name; },
'bin-unauthorized': (s) => { s.error_message = 'Not authorized to load bin. Please sign-in.'; },
'update-search-term': (s, search_term) => { s.search_term=search_term; },
'update-search-results': (s, _notes) => { integrateAll(s,s.notes,'note_id',_notes); s.notes =_notes.map(n=>({is_editing: false, temp_text: '', bin_id: s.bin_id, note_id:n.id})); },
'add-note': (s, {id, date}) => { i(s, {id: id, text: '', modified: date}); s.notes.unshift({is_editing: true, temp_text: '', bin_id: s.bin_id, is_focused:true, is_new: true, note_id: id}); },
'notes-loaded': (s, _notes) => { integrateAll(s,_notes); s.notes = _notes.map(n=>({is_editing: false, temp_text: n.text, bin_id: s.bin_id, note_id:n.id})); },
'notes-unauthorized': (s) => { s.error_message = 'Not authorized to load notes in bin. Please sign-in.'; },
'immediately-cancel-note': (s, note_id) => { disintegrate(s,note_id); s.notes.splice(s.notes.findIndex(n=>n.note_id===note_id), 1); },
'update-note-text': (s, {id, text}) => { const note_s=s.notes.find(n=>n.note_id===id); note_s.is_new=false; s.db[note_s.note_id].model.text=text; }, // updates underlying note text (i.e. the "model", not the app note_state) "in the background" (e.g. from a server-pushed update), regardless of whether it's being edited; "save" is a separate action, below
'update-note-editing': (s, {id, is_editing}) => { const note_s=s.notes.find(n=>n.note_id===id); note_s.is_editing=is_editing; note_s.temp_text=s.db[note_s.note_id].model.text; },
@@ -146,7 +148,8 @@ const reducer = handleActions({
ref_count: 1,
model: {id: bin_id, name: bin_id, user_id: ''}
}
}
},
error_message: ''
//search_result_notes: []
});