Site done
This commit is contained in:
parent
d747d9419f
commit
cca01dc055
11 changed files with 293 additions and 8 deletions
27
src/stores/videos.js
Normal file
27
src/stores/videos.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { writable } from 'svelte/store';
|
||||
|
||||
function createVideosStore() {
|
||||
const { subscribe, set, update } = writable({videos: [], idx_videos: {}, loading: true});
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
update: async (res_videos, cb=null) => {
|
||||
if (res_videos.status === 200) {
|
||||
const videos = await res_videos.json();
|
||||
const idx_videos = {};
|
||||
|
||||
for (const v of videos) {
|
||||
idx_videos[v.id] = v;
|
||||
}
|
||||
|
||||
update((t) => (Object.assign(t, {videos, idx_videos, loading: false})));
|
||||
|
||||
if (cb) {
|
||||
cb(videos);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const videos = createVideosStore();
|
||||
Reference in a new issue