diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-17 09:57:09 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-17 09:57:09 +0100 |
| commit | e95cf5c7b6a08eb560763d5167fbddc1c2117bcc (patch) | |
| tree | 2f7815c9f39328fcaced2113de727f63e4837fa3 /static/index.js | |
| parent | 0016aaa197697ec5ff38dfb3f63ac8b6f74b48e0 (diff) | |
add file uploading and multi-threading
Diffstat (limited to 'static/index.js')
| -rw-r--r-- | static/index.js | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/static/index.js b/static/index.js index 90b5ffd..2fcca88 100644 --- a/static/index.js +++ b/static/index.js @@ -11,14 +11,25 @@ import Search from './widgets/search/index.js'; import MonthSelect from './widgets/month-select/index.js'; import SettingsView from './pages/settings/index.js'; import ShuffleView from './pages/shuffle/index.js'; +import UploadBar from './widgets/upload-bar/index.js'; sfw.theme.add_css(await sfw.css(import.meta.url, './index.css')); const image_viewer = ImageViewer.new(); +const reload = () => { + image_viewer.clear(); + api.images.list().then(images => { + for (const image of images) { + image_viewer.add(`/api/image/load/${image.id}`); + } + }); +} + const login = LoginView.new({ onlogin: async (user, password) => { if (await api.auth.login(user, password)) { + reload(); login.hide(); } else { login.comment = 'Incorrect username or password.'; @@ -38,10 +49,13 @@ const search = Search.new({ onsubmit: (content) => console.log(content), onhide: () => main.show(), }); + const month_select = MonthSelect.new({ months: m`2019-08`.to(m`2025-11`), }); +const upload_bar = UploadBar.new(); + const settings = SettingsView.new({ onlogout: () => { login.show(); @@ -49,8 +63,7 @@ const settings = SettingsView.new({ }, }); -const shuffle = ShuffleView.new({ -}); +const shuffle = ShuffleView.new({ }); const main = MainView.new({ active_view: image_viewer, @@ -66,7 +79,23 @@ const main = MainView.new({ main.active_view = image_viewer; month_select.show(); }, - onupload: () => api.images.upload_to_timeline(), + onupload: async () => { + const uploader = await api.images.upload_to_timeline(); + + upload_bar.progress = 0; + upload_bar.show(); + + uploader.onprogress = (count, total) => { + upload_bar.progress = count / total; + } + + uploader.ondone = () => { + upload_bar.hide(); + reload(); + } + + uploader.send(); + }, onshuffle: () => { main.active_kind = MainView.Kind.home; main.active_view = shuffle; @@ -86,12 +115,13 @@ document.body.append( main, search, month_select, + upload_bar, ); -login.hide(); -//if (await api.session.is_valid()) { -// login.hide(); -//} else { -// login.focus(); -//} +if (await api.session.is_valid()) { + login.hide(); + reload(); +} else { + login.focus(); +} |