2022-10-04 16:34:37 +00:00
|
|
|
import { derived, writable } from 'svelte/store';
|
2022-10-04 15:25:58 +00:00
|
|
|
|
|
|
|
import { getActions } from '../lib/action'
|
|
|
|
|
|
|
|
function createActionsStore() {
|
2022-10-04 16:34:37 +00:00
|
|
|
const { subscribe, set, update } = writable({list: null, fileIdx: null});
|
2022-10-04 15:25:58 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
|
|
|
|
set: (v) => {
|
|
|
|
update((m) => Object.assign(m, v));
|
|
|
|
},
|
|
|
|
|
|
|
|
refresh: async () => {
|
|
|
|
const list = await getActions();
|
2022-10-04 16:34:37 +00:00
|
|
|
const fileIdx = {};
|
|
|
|
list.forEach(function(action, k) {
|
|
|
|
fileIdx[action.path] = action;
|
|
|
|
});
|
|
|
|
|
|
|
|
update((m) => (Object.assign(m, {list, fileIdx})));
|
2022-10-04 15:25:58 +00:00
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
|
|
|
update: (res_actions, cb=null) => {
|
|
|
|
if (res_actions.status === 200) {
|
|
|
|
res_actions.json().then((list) => {
|
2022-10-04 16:34:37 +00:00
|
|
|
const fileIdx = {};
|
|
|
|
list.forEach(function(action, k) {
|
|
|
|
fileIdx[action.path] = action;
|
|
|
|
})
|
|
|
|
|
|
|
|
update((m) => (Object.assign(m, {list, fileIdx})));
|
2022-10-04 15:25:58 +00:00
|
|
|
|
|
|
|
if (cb) {
|
|
|
|
cb(list);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = createActionsStore();
|
2022-10-04 16:34:37 +00:00
|
|
|
|
|
|
|
export const actions_idx = derived(
|
|
|
|
actions,
|
|
|
|
($actions) => ($actions.fileIdx),
|
|
|
|
);
|