aboutsummaryrefslogtreecommitdiff
path: root/static/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/index.js')
-rw-r--r--static/index.js137
1 files changed, 0 insertions, 137 deletions
diff --git a/static/index.js b/static/index.js
deleted file mode 100644
index ddbead7..0000000
--- a/static/index.js
+++ /dev/null
@@ -1,137 +0,0 @@
-import * as sfw from 'sfw';
-import * as api from 'api';
-import Month from './month.js';
-
-import LoginView from './pages/login/index.js';
-import MainView from './pages/main/index.js';
-import ImageViewer from './pages/image-viewer/index.js';
-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';
-
-import stylesheet from './index.css';
-sfw.theme.add_css(await sfw.css.sheet(stylesheet));
-
-const image_viewer = ImageViewer.new();
-
-const reload = () => {
- api.images.list().then(images => {
- const last = Month.from_unix(images[0].timestamp);
- let first = Month.from_unix(images.findLast(i => i.timestamp).timestamp);
- month_select.months = first.to(last);
-
- image_viewer.images = images;
- shuffle.images = images;
- });
-}
-
-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.';
- }
- },
-
- onpassword: async (user) => {
- if (await api.auth.is_first_login(user)) {
- login.comment = 'Please enter a new password.';
- } else {
- login.comment = '';
- }
- },
-});
-
-const search = Search.new({
- onsubmit: (content) => console.log(content),
- onhide: () => main.show(),
-});
-
-const month_select = MonthSelect.new({
- onmonth: (month) => image_viewer.jump_to(month),
-});
-const upload_bar = UploadBar.new();
-
-const settings = SettingsView.new({
- onlogout: async () => {
- await api.session.drop();
- login.show();
- main.active_view = image_viewer;
- settings.profile = null;
- },
-});
-
-const shuffle = ShuffleView.new({ });
-
-const main = MainView.new({
- active_view: image_viewer,
- active_kind: MainView.Kind.upload,
-
- onsearch: () => {
- main.active_kind = MainView.Kind.upload;
- main.active_view = image_viewer;
- search.toggle();
- main.hide();
- },
- onmonth: () => {
- main.active_kind = MainView.Kind.upload;
- main.active_view = image_viewer;
- month_select.show();
- },
- onupload: async () => {
- upload_bar.progress = 0;
- upload_bar.show();
-
- const uploader = await api.images.upload_to_timeline();
-
- uploader.onprogress = (count, total) => {
- upload_bar.progress = count / total;
- }
-
- uploader.ondone = () => {
- upload_bar.hide();
- reload();
- }
-
- uploader.send();
- },
- onshuffle: () => {
- shuffle.open();
- main.active_kind = MainView.Kind.home;
- main.active_view = shuffle;
- },
- onsettings: async () => {
- if (!settings.profile) {
- settings.profile = await api.session.current();
- }
-
- main.active_kind = MainView.Kind.home;
- main.active_view = settings;
- },
- onhome: () => {
- main.active_kind = MainView.Kind.upload;
- main.active_view = image_viewer;
- },
-});
-
-document.body.append(
- login,
- main,
- search,
- month_select,
- upload_bar,
-);
-
-if (!await api.session.is_online()) {
- login.hide();
- reload();
-} if (await api.session.is_valid()) {
- login.hide();
- reload();
-} else {
- login.focus();
-}