bin URL navigation
parent
ce0383d31f
commit
10071edfa0
@ -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};
|
Loading…
Reference in New Issue