app delivered as a Docker package: frontend and backend

This commit is contained in:
brian
2021-03-24 13:00:58 -04:00
parent a0101ffb7e
commit c140dd3b67
21 changed files with 696 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import nanoid from '../nanoid.min.js';
import api from '../api.js';
const load_notes = function(state, dispatch){
api.post('/load-notes', {bin_id: state.bin.id})
.then(res=>{
dispatch('notes-loaded', res.notes);
});
};
const runSearch = function(state, dispatch){
api.post('/search', {search_term: state.search_term, sorting: state.sorting, bin_id: state.bin.id})
.then(res=>{
dispatch('update-search-results', res.notes);
});
};
const new_note_handler = function(state, dispatch){
dispatch('add-note', {id: nanoid(), date: Date.now()});
};
const search_term_change_handler = function(state, dispatch, e){
if(e.code === 'Enter'){
runSearch(state, dispatch);
}
else{
dispatch('update-search-term', e.target.value);
}
};
const sorting_change_handler = function(state, dispatch, e){
runSearch(state, dispatch);
dispatch('update-sorting', e.target.value);
};
const new_bin_handler = function(state, dispatch){
const id = nanoid();
// change browser location in address bar:
window.history.pushState(null,'','#'+id);
dispatch('new-bin', {id});
};
export {new_note_handler, search_term_change_handler, sorting_change_handler, load_notes, new_bin_handler};
+17
View File
@@ -0,0 +1,17 @@
import api from '../api.js';
const edit_handler = function(note_state, dispatch){
dispatch('update-note-editing', {id: note_state.note.id, is_editing: true});
};
const cancel_handler = function(note_state, dispatch){
dispatch('update-note-editing', {id: note_state.note.id, is_editing: false});
};
const text_change_handler = function(note_state, dispatch, e){
note_state.temp_text = e.target.value;
};
const save_handler = function(note_state, dispatch){
dispatch('save-note-edit', {id: note_state.note.id, text: note_state.temp_text});
api.post('/save', {bin_id: note_state.bin_id, note_id: note_state.note.id, text: note_state.temp_text})
};
export { edit_handler, cancel_handler, text_change_handler, save_handler };
+32
View File
@@ -0,0 +1,32 @@
import api from '../api.js';
const load_bin_handler = function(state, dispatch, bin_id){
/*
api.post('/load-bin', {id: bin_id})
.then(res => {
dispatch('bin-loaded', {bin:res.bin, _notes:res.notes});
});
*/
api.post('/load-notes', {bin_id})
.then(res => {
dispatch('notes-loaded', res.notes);
});
};
const hash_change_handler = function(state, dispatch, e){
// get bin id from URL
let bin_id = window.location.hash.substring(1); // extract the leading '#'
if(bin_id === ''){
const old_bin_id = state.bin.id;
window.history.replaceState(null,'', '#'+old_bin_id);
}
else{
dispatch('bin-requested', bin_id);
api.post('/load-notes', {bin_id})
.then(res => {
dispatch('notes-loaded', res.notes);
});
}
};
export {load_bin_handler, hash_change_handler};