You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pastebin/nginx/public_html/handlers/index.js

34 lines
934 B
JavaScript

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);
});
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-bin', {bin_id})
.then(res=>{
dispatch('bin-loaded', res.bin);
});
api.post('/load-notes', {bin_id})
.then(res => {
dispatch('notes-loaded', res.notes);
});
}
};
export {initial_load_bin_handler, hash_change_handler};