Skip to content

Commit

Permalink
fix (public): linter in frontend rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Feb 25, 2024
1 parent 6ab60bb commit d5b0abb
Show file tree
Hide file tree
Showing 70 changed files with 568 additions and 579 deletions.
4 changes: 1 addition & 3 deletions public/assets/boot/ctrl_boot_frontoffice.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import rxjs, { ajax } from "../lib/rx.js";
import { loadJS } from "../helpers/loader.js";
// import { setup_cache } from "../helpers/cache.js";
import { init as setup_loader } from "../helpers/loader.js";
import { init as setup_loader, loadJS } from "../helpers/loader.js";
import { report } from "../helpers/log.js";


export default async function main() {
try {
await Promise.all([ // procedure with no outside dependencies
Expand Down
31 changes: 17 additions & 14 deletions public/assets/components/breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { animate, slideYOut, slideYIn, slideXIn, opacityOut } from "../lib/animate.js";
import { animate, slideYOut, slideYIn, opacityOut } from "../lib/animate.js";
import { loadCSS } from "../helpers/loader.js";

class ComponentBreadcrumb extends window.HTMLDivElement {

constructor() {
super();
if (new window.URL(location.href).searchParams.get("nav") === "false") {
Expand Down Expand Up @@ -30,12 +29,12 @@ class ComponentBreadcrumb extends window.HTMLDivElement {

switch (name) {
case "path":
if (newValue == "") return;
if (newValue === "") return;
return this.renderPath({ path: newValue, previous: oldValue || null });
case "indicator":
return this.renderIndicator()
return this.renderIndicator();
}
throw new Error("component::breadcrumb.js unknow attribute name: "+ name)
throw new Error("component::breadcrumb.js unknow attribute name: "+ name);
}

static get observedAttributes() {
Expand All @@ -45,7 +44,7 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
async renderPath({ path = "", previous }) {
path = this.__normalised(path);
previous = this.__normalised(previous);
let pathChunks = path.split("/");
const pathChunks = path.split("/");

// STEP1: leaving animation on elements that will be removed
if (previous !== null && previous.indexOf(path) >= 0) {
Expand Down Expand Up @@ -97,7 +96,7 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
${limitSize(label, true)}
</span>
`;
return `<div>${limitSize(label)}</div>`
return `<div>${limitSize(label)}</div>`;
})();

return `
Expand Down Expand Up @@ -133,17 +132,21 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
if (state && this.getAttribute("indicator") !== "false") state = true;

const $indicator = this.querySelector(`[data-bind="path"]`)
.lastChild
.querySelector("span");
.lastChild
.querySelector("span");

if (state) {
$indicator.style.opacity = 1;
$indicator.innerHTML = `<div class="component_saving">*</div>`;
await animate($indicator, { time: 500, keyframes: [
{ transform: "scale(0)", offset: 0 },
{ transform: "scale(1.5)", offset: 0.3 },
{ transform: "scale(1)", offset: 1 },
], fill: "none"});
await animate($indicator, {
time: 500,
keyframes: [
{ transform: "scale(0)", offset: 0 },
{ transform: "scale(1.5)", offset: 0.3 },
{ transform: "scale(1)", offset: 1 },
],
fill: "none"
});
} else {
$indicator.style.opacity = 0;
await animate($indicator, { time: 200, keyframes: opacityOut(), fill: "none" });
Expand Down
4 changes: 2 additions & 2 deletions public/assets/components/decorator_shell_filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export default function(ctrl) {
ctrl(createRender($main));
ctrlSidebar(createRender(qs($page, `[data-bind="sidebar"]`)));

onDestroy(async () => {
onDestroy(async() => {
if ((history.state.previous || "").startsWith("/view/") && location.pathname.startsWith("/files/")) {
await animate($main, { time: 100, keyframes: slideYOut(20), fill: "none" });
$main.classList.add("hidden");
}
});
}
};
}

async function ctrlSidebar(render) {
Expand Down
2 changes: 1 addition & 1 deletion public/assets/components/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ComponentDropdown extends HTMLDivElement {
}

render() {
this.classList.add("component_dropdown", "view", "sort")
this.classList.add("component_dropdown", "view", "sort");
this.appendChild(createFragment(`
<div class="dropdown_button">
<img class="component_icon" draggable="false" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzODQgNTEyIj4KICA8cGF0aCBmaWxsPSIjZjJmMmYyIiBkPSJNIDM2MCw0NjAgSCAyNCBDIDEwLjcsNDYwIDAsNDUzLjMgMCw0NDAgdiAtMTIgYyAwLC0xMy4zIDEwLjcsLTIwIDI0LC0yMCBoIDMzNiBjIDEzLjMsMCAyNCw2LjcgMjQsMjAgdiAxMiBjIDAsMTMuMyAtMTAuNywyMCAtMjQsMjAgeiIgLz4KICA8cGF0aCBmaWxsPSIjZjJmMmYyIiBkPSJNIDIyNi41NTM5LDIzNC44ODQyOCBWIDUyLjk0MzI4MyBjIDAsLTYuNjI3IC01LjM3MywtMTIgLTEyLC0xMiBoIC00NCBjIC02LjYyNywwIC0xMiw1LjM3MyAtMTIsMTIgViAyMzQuODg0MjggaCAtNTIuMDU5IGMgLTIxLjM4MiwwIC0zMi4wOSwyNS44NTEgLTE2Ljk3MSw0MC45NzEgbCA4Ni4wNTksODYuMDU5IGMgOS4zNzMsOS4zNzMgMjQuNTY5LDkuMzczIDMzLjk0MSwwIGwgODYuMDU5LC04Ni4wNTkgYyAxNS4xMTksLTE1LjExOSA0LjQxMSwtNDAuOTcxIC0xNi45NzEsLTQwLjk3MSB6IiAvPgo8L3N2Zz4K" alt="download_white">
Expand Down
2 changes: 1 addition & 1 deletion public/assets/components/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Loader extends window.HTMLElement {
customElements.define("component-loader", Loader);

export function createLoader($parent, opts = {}) {
const { wait = 500 } = opts
const { wait = 500 } = opts;
const cancel = effect(new rxjs.Observable((observer) => {
const $icon = createElement(`
<div class="component_loader">
Expand Down
3 changes: 1 addition & 2 deletions public/assets/components/menubar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createElement } from "../lib/skeleton/index.js";
import { animate, slideYIn } from "../lib/animate.js";
import { basename } from "../lib/path.js";
import assert from "../lib/assert.js";
Expand All @@ -10,7 +9,7 @@ export default class ComponentMenubar extends window.HTMLElement {
constructor() {
super();

this.classList.add("component_menubar")
this.classList.add("component_menubar");
this.innerHTML = `
<div class="component_container">
<span>
Expand Down
2 changes: 1 addition & 1 deletion public/assets/helpers/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function loadJS(baseURL, path, opts = {}) {
const $script = document.createElement("script");
const link = new URL(path, baseURL) + "?version=" + version;
$script.setAttribute("src", link.toString());
for (let key in opts) {
for (const key in opts) {
$script.setAttribute(key, opts[key]);
}
if (typeof type === "string") ;
Expand Down
3 changes: 2 additions & 1 deletion public/assets/lib/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function animate($node, opts = {}) {
return new Promise((done) => {
$node.animate(keyframes, {
duration: time,
fill, easing,
fill,
easing,
}).onfinish = done;
});
}
Expand Down
6 changes: 3 additions & 3 deletions public/assets/lib/assert.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export default class assert {
static type(object, type, msg) {
if (object instanceof type) return;
throw new Error(msg ? msg : `assertion failed - unexpected type for ${object.toString()}`);
throw new Error(msg || `assertion failed - unexpected type for ${object.toString()}`);
}

static truthy(object, msg) {
if (object) return;
throw new Error(msg ? msg : `assertion failed - object is not truthy`);
throw new Error(msg || `assertion failed - object is not truthy`);
}

static fail(object, msg) {
throw new Error(msg ? msg : `assertion failed - ${object}`);
throw new Error(msg || `assertion failed - ${object}`);
}
}
18 changes: 10 additions & 8 deletions public/assets/lib/chromecast.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class ChromecastManager {
init() {
// TODO: additional rules for setup
let src = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";
const src = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";
if (document.head.querySelector(`script[src="${src}"]`)) return Promise.resolve();

return new Promise((done) => {
const script = document.createElement("script");
script.src = src;
script.onerror = () => done();
window["__onGCastApiAvailable"] = function(isAvailable) {
if (isAvailable) cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
if (isAvailable) window.cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: window.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
autoJoinPolicy: window.chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
});
done();
};
document.head.appendChild(script)
document.head.appendChild(script);
});
}

Expand Down Expand Up @@ -45,20 +45,22 @@ class ChromecastManager {
// url. Once we have that app, the authorisation will come from a customData field
// of a chrome.cast.media.LoadRequest
const target = new URL(mediaInfo.contentId);
target.searchParams.append("authorization", Session.authorization);
target.searchParams.append("authorization", window.Session.authorization);
mediaInfo.contentId = target.toString();
return new chrome.cast.media.LoadRequest(mediaInfo);
return new window.chrome.cast.media.LoadRequest(mediaInfo);
}

context() {
if (!this.isAvailable()) return
if (!this.isAvailable()) return;
return window.cast.framework.CastContext.getInstance();
}

session() {
const context = this.context();
if (!context) return;
return context.getCurrentSession();
}

media() {
const session = this.session();
if (!session) return;
Expand Down
3 changes: 0 additions & 3 deletions public/assets/lib/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
export function pluck() {} // TODO

export functon spread() {} // TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutations, applyMutation, onClick } from "../../lib/rx.js";
import { createForm } from "../../lib/form.js";
import { qs, qsa } from "../../lib/dom.js";
Expand Down
2 changes: 1 addition & 1 deletion public/assets/pages/adminpage/ctrl_backend_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function initStorage() {
rxjs.map(({ connections }) => connections),
rxjs.tap((connections) => {
if (backendsEnabled$.value !== undefined) return;
backendsEnabled$.next(Array.isArray(connections) ? connections : [])
backendsEnabled$.next(Array.isArray(connections) ? connections : []);
}),
).toPromise();
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/pages/adminpage/ctrl_settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation } from "../../lib/rx.js";
import { qs, qsa } from "../../lib/dom.js";
import { createForm, mutateForm } from "../../lib/form.js";
Expand Down
4 changes: 2 additions & 2 deletions public/assets/pages/connectpage/ctrl_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default async function(render) {
let n = parseInt(settings_get("login_tab"));
if (Number.isNaN(n)) n = (conns.length || 0) / 2 - 1;
if (n < 0 || n >= conns.length) n = 0;
return n
return n;
}),
rxjs.tap((current) => setCurrentBackend(Math.round(current))),
));
Expand Down Expand Up @@ -171,7 +171,7 @@ export default async function(render) {
if (Object.keys(p).length > 0) {
url += "&state=" + btoa(JSON.stringify(p));
}
location.href = url
location.href = url;
return rxjs.EMPTY;
}),
rxjs.mergeMap((formData) => { // CASE 2: oauth2 related backends like dropbox and gdrive
Expand Down
1 change: 0 additions & 1 deletion public/assets/pages/ctrl_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ trace: ${err.stack || "N/A"}`;
return [msg, trace.trim()];
}


const css = `
.error-page {
width: 80%;
Expand Down
4 changes: 2 additions & 2 deletions public/assets/pages/ctrl_filespage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement, createRender } from "../lib/skeleton/index.js";
import rxjs, { effect } from "../lib/rx.js";
import { qs } from "../lib/dom.js";
import { loadCSS } from "../helpers/loader.js";
import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js"
import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js";

import { getState$ } from "./filespage/ctrl_filesystem_state.js";
import componentFilesystem, { init as initFilesystem } from "./filespage/ctrl_filesystem.js";
Expand Down Expand Up @@ -30,7 +30,7 @@ export default WithShell(function(render) {
componentFilesystem(createRender(qs($page, "[is=\"component_filesystem\"]")));

// feature3: render the menubar
componentSubmenu(createRender(qs($page, "[is=\"component_submenu\"]")))
componentSubmenu(createRender(qs($page, "[is=\"component_submenu\"]")));
});

export function init() {
Expand Down
5 changes: 2 additions & 3 deletions public/assets/pages/ctrl_viewerpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const mime$ = getConfig().pipe(
);

function loadModule(appName) {
switch(appName) {
switch (appName) {
case "editor":
return import("./viewerpage/application_editor.js");
case "pdf":
Expand Down Expand Up @@ -55,8 +55,7 @@ export default WithShell(async function(render) {
)),
rxjs.catchError(ctrlError()),
));

})
});

export async function init() {
return Promise.all([
Expand Down
19 changes: 11 additions & 8 deletions public/assets/pages/filespage/ctrl_filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createLoader } from "../../components/loader.js";
import ctrlError from "../ctrl_error.js";

import { createThing } from "./thing.js";
import { handleError, getFiles } from "./ctrl_filesystem_state.js";
// import { handleError, getFiles } from "./ctrl_filesystem_state.js";
import { ls } from "./model_files.js";

export default async function(render) {
Expand Down Expand Up @@ -51,13 +51,13 @@ export default async function(render) {
animate($list, { time: 200, keyframes: slideYIn(5) });
$list.appendChild($fs);

/////////////////////////////////////////
/// //////////////////////////////////////
// CASE 1: virtual scroll isn't enabled
if (files.length <= VIRTUAL_SCROLL_MINIMUM_TRIGGER) {
return rxjs.EMPTY;
}

/////////////////////////////////////////
/// //////////////////////////////////////
// CASE 2: with virtual scroll
const $listBefore = qs($page, ".ifscroll-before");
const $listAfter = qs($page, ".ifscroll-after");
Expand All @@ -74,13 +74,16 @@ export default async function(render) {
$listAfter.style.height = `${height - size}px`;
};
setHeight(0);
const top = ($node) => $node.getBoundingClientRect().top;
// const top = ($node) => $node.getBoundingClientRect().top;
return rxjs.of({
files, path,
files,
path,
currentState: 0,
$list,
setHeight,
FILE_HEIGHT, BLOCK_SIZE, COLUMN_PER_ROW,
FILE_HEIGHT,
BLOCK_SIZE,
COLUMN_PER_ROW,
MARGIN: 35, // TODO: top($list) - top($list.closest(".scroll-y"));
});
}),
Expand Down Expand Up @@ -130,7 +133,7 @@ export default async function(render) {
// nearest COLUMN_PER_ROW
fileEnd += 1;
if (fileEnd % COLUMN_PER_ROW === 0) {
break
break;
}
}
}
Expand All @@ -142,7 +145,7 @@ export default async function(render) {
const file = files[i];
if (file === undefined) $fs.appendChild(createThing({
type: "hidden",
}))
}));
else $fs.appendChild(createThing({
name: file.name,
// name: `file ${i}`,
Expand Down
2 changes: 1 addition & 1 deletion public/assets/pages/filespage/ctrl_filesystem_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export const onSearch = () => {
console.log("SEARCH");
};

export const getFiles = (n) => {}
export const getFiles = (n) => {};
Loading

0 comments on commit d5b0abb

Please sign in to comment.