ui: Use $lib in imports

This commit is contained in:
nemunaire 2022-11-18 15:38:50 +01:00
commit d6f620bc0d
54 changed files with 146 additions and 146 deletions

View file

@ -0,0 +1,41 @@
import { writable } from 'svelte/store';
function createToastsStore() {
const { subscribe, set, update } = writable({toasts: []});
const addToast = (o) => {
o.timestamp = new Date();
o.close = () => {
update((i) => {
i.toasts = i.toasts.filter((j) => {
return !(j.title === o.title && j.msg === o.msg && j.timestamp === o.timestamp)
});
return i;
});
}
update((i) => {
i.toasts.unshift(o);
return i;
});
o.cancel = setTimeout(o.close, o.dismiss?o.dismiss:5000);
};
const addErrorToast = (o) => {
if (!o.title) o.title = 'Une erreur est survenue !';
if (!o.color) o.color = 'danger';
return addToast(o);
};
return {
subscribe,
addToast,
addErrorToast,
};
}
export const ToastsStore = createToastsStore();

27
ui/src/lib/stores/user.js Normal file
View file

@ -0,0 +1,27 @@
import { writable } from 'svelte/store';
function createUserStore() {
const { subscribe, set, update } = writable(undefined);
return {
subscribe,
set: (auth) => {
update((m) => auth);
},
update: (res_auth, cb=null) => {
if (res_auth.status === 200) {
res_auth.json().then((auth) => {
update((m) => (Object.assign(m?m:{}, auth)));
if (cb) {
cb(my);
}
});
} else if (res_auth.status >= 400 && res_auth.status < 500) {
update((m) => (null));
}
},
};
}
export const user = createUserStore();