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

48 lines
1.3 KiB
JavaScript

import api from '../api.js';
const initial_load_bin_handler = function(state, dispatch, bin_id){
api.post('/load-bin', {bin_id})
.then(res => {
if(res.success===false && res.authorized===false){
dispatch('bin-unauthorized');
}
else{
dispatch('bin-loaded', res.bin);
}
});
api.post('/load-notes', {bin_id})
.then(res => {
if(res.success===true){
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=>{
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 => {
if(res.success==true){
dispatch('notes-loaded', res.notes);
}
});
}
};
export {initial_load_bin_handler, hash_change_handler};