bin URL navigation

This commit is contained in:
brian
2021-03-17 11:53:41 -04:00
parent ce0383d31f
commit 10071edfa0
4 changed files with 59 additions and 6 deletions
+2 -2
View File
@@ -31,9 +31,9 @@ const sorting_change_handler = function(state, dispatch, e){
};
const new_bin_handler = function(state, dispatch){
const id = nanoid();
// TODO: consolidate: this will cause two redraws:
// change browser location in address bar:
window.history.pushState(null,'','#'+id);
dispatch('new-bin', {id});
dispatch('notes-loaded', []);
};
export {new_note_handler, search_term_change_handler, sorting_change_handler, load_notes, new_bin_handler};
+32
View File
@@ -0,0 +1,32 @@
import api from '../api-stub.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};