mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
maintain (refactoring): cleanup code
This commit is contained in:
parent
a9350c3126
commit
395b312012
7 changed files with 13 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
// cheap event system that handle subscription, unsubscriptions and event emitions
|
// cheap event system that handle subscription, unsubscriptions and event emitions
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { randomString } from "../helpers/";
|
||||||
const emitters = {};
|
const emitters = {};
|
||||||
|
|
||||||
function subscribe(key, event, fn) {
|
function subscribe(key, event, fn) {
|
||||||
|
|
@ -37,7 +38,7 @@ function emit(event, payload) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EventReceiver(WrappedComponent) {
|
export function EventReceiver(WrappedComponent) {
|
||||||
const id = Math.random().toString();
|
const id = randomString();
|
||||||
|
|
||||||
return class extends React.Component {
|
return class extends React.Component {
|
||||||
subscribe(event, callback) {
|
subscribe(event, callback) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export function SettingsPage({ isSaving = nop }) {
|
||||||
const onChange = (_form) => {
|
const onChange = (_form) => {
|
||||||
_form.connections = window.CONFIG.connections;
|
_form.connections = window.CONFIG.connections;
|
||||||
delete _form.constant;
|
delete _form.constant;
|
||||||
refresh(Math.random());
|
refresh(Date.now());
|
||||||
isSaving(true);
|
isSaving(true);
|
||||||
Config.save(_form, true, () => {
|
Config.save(_form, true, () => {
|
||||||
isSaving(false);
|
isSaving(false);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Files } from "../model/";
|
import { Files } from "../model/";
|
||||||
import { notify, upload } from "../helpers/";
|
import { notify, upload, randomString } from "../helpers/";
|
||||||
import Path from "path";
|
import Path from "path";
|
||||||
import { Observable } from "rxjs/Observable";
|
import { Observable } from "rxjs/Observable";
|
||||||
import { t } from "../locales/";
|
import { t } from "../locales/";
|
||||||
|
|
@ -180,16 +180,6 @@ export const onUpload = function(path, e) {
|
||||||
|
|
||||||
extractFiles.then((files) => upload.add(path, files));
|
extractFiles.then((files) => upload.add(path, files));
|
||||||
|
|
||||||
// adapted from: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
|
||||||
function _rand_id() {
|
|
||||||
function s4() {
|
|
||||||
return Math.floor((1 + Math.random()) * 0x10000)
|
|
||||||
.toString(16)
|
|
||||||
.substring(1);
|
|
||||||
}
|
|
||||||
return s4() + s4() + s4() + s4();
|
|
||||||
}
|
|
||||||
|
|
||||||
function extract_upload_directory_the_way_that_works_but_non_official(items, files = []) {
|
function extract_upload_directory_the_way_that_works_but_non_official(items, files = []) {
|
||||||
const traverseDirectory = (item, _files, parent_id) => {
|
const traverseDirectory = (item, _files, parent_id) => {
|
||||||
const file = {
|
const file = {
|
||||||
|
|
@ -210,7 +200,7 @@ export const onUpload = function(path, e) {
|
||||||
} else if (item.isDirectory) {
|
} else if (item.isDirectory) {
|
||||||
file.type = "directory";
|
file.type = "directory";
|
||||||
file.path += "/";
|
file.path += "/";
|
||||||
file._id = _rand_id();
|
file._id = randomString();
|
||||||
if (parent_id) file._prior = parent_id;
|
if (parent_id) file._prior = parent_id;
|
||||||
_files.push(file);
|
_files.push(file);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import React, { createRef } from "react";
|
||||||
import { Redirect } from "react-router";
|
import { Redirect } from "react-router";
|
||||||
|
|
||||||
import { Share } from "../model/";
|
import { Share } from "../model/";
|
||||||
import { notify, basename, filetype, findParams } from "../helpers/";
|
import { notify, basename, filetype, findParams, randomString } from "../helpers/";
|
||||||
import { Loader, Input, Button, Container, ErrorPage, Icon } from "../components/";
|
import { Loader, Input, Button, Container, ErrorPage, Icon } from "../components/";
|
||||||
import { t } from "../locales/";
|
import { t } from "../locales/";
|
||||||
import "./error.scss";
|
import "./error.scss";
|
||||||
|
|
@ -67,7 +67,7 @@ export class SharePageComponent extends React.Component {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const className = this.state.error ? `error rand-${Math.random().toString()}` : "";
|
const className = this.state.error ? `error rand-${randomString()}` : "";
|
||||||
|
|
||||||
if (this.state.path !== null) {
|
if (this.state.path !== null) {
|
||||||
if (!!findParams("next")) {
|
if (!!findParams("next")) {
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,11 @@ class IDEComponent extends React.Component {
|
||||||
download() {
|
download() {
|
||||||
document.cookie = "download=yes; path=/; max-age=120;";
|
document.cookie = "download=yes; path=/; max-age=120;";
|
||||||
this.setState({
|
this.setState({
|
||||||
random: Math.random(),
|
refresh: Date.now(),
|
||||||
id: window.setInterval(() => {
|
id: window.setInterval(() => {
|
||||||
if (/download=yes/.test(document.cookie) === false) {
|
if (/download=yes/.test(document.cookie) === false) {
|
||||||
window.clearInterval(this.state.id);
|
window.clearInterval(this.state.id);
|
||||||
this.setState({ random: Math.random() });
|
this.setState({ refresh: Date.now() });
|
||||||
}
|
}
|
||||||
}, 100),
|
}, 100),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import ReactCSSTransitionGroup from "react-addons-css-transition-group";
|
||||||
|
|
||||||
import { MenuBar } from "./menubar";
|
import { MenuBar } from "./menubar";
|
||||||
import { Bundle, Icon, NgIf, Loader, EventEmitter, EventReceiver } from "../../components/";
|
import { Bundle, Icon, NgIf, Loader, EventEmitter, EventReceiver } from "../../components/";
|
||||||
import { alert } from "../../helpers/";
|
import { alert, randomString } from "../../helpers/";
|
||||||
import { Pager } from "./pager";
|
import { Pager } from "./pager";
|
||||||
import { t } from "../../locales/";
|
import { t } from "../../locales/";
|
||||||
import "./imageviewer.scss";
|
import "./imageviewer.scss";
|
||||||
|
|
@ -36,7 +36,7 @@ export class ImageViewerComponent extends React.Component {
|
||||||
if (e.keyCode === 27) this.setState({ show_exif: false });
|
if (e.keyCode === 27) this.setState({ show_exif: false });
|
||||||
else if (e.keyCode === 73) this.setState({ show_exif: !this.state.show_exif });
|
else if (e.keyCode === 73) this.setState({ show_exif: !this.state.show_exif });
|
||||||
};
|
};
|
||||||
this.refresh = () => this.setState({ "_": Math.random() });
|
this.refresh = () => this.setState({ "_": randomString() });
|
||||||
this.$container = createRef();
|
this.$container = createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { StickyContainer, Sticky } from "react-sticky";
|
||||||
import { Modal, NgIf, Icon, Dropdown, DropdownButton, DropdownList, DropdownItem } from "../../components/";
|
import { Modal, NgIf, Icon, Dropdown, DropdownButton, DropdownList, DropdownItem } from "../../components/";
|
||||||
import { extractEvents, extractTodos } from "../../helpers/org";
|
import { extractEvents, extractTodos } from "../../helpers/org";
|
||||||
import { leftPad } from "../../helpers/common";
|
import { leftPad } from "../../helpers/common";
|
||||||
import { debounce } from "../../helpers/";
|
import { debounce, randomString } from "../../helpers/";
|
||||||
import { t } from "../../locales/";
|
import { t } from "../../locales/";
|
||||||
import "./org_viewer.scss";
|
import "./org_viewer.scss";
|
||||||
|
|
||||||
|
|
@ -53,9 +53,7 @@ class OrgViewer extends React.Component {
|
||||||
search: "",
|
search: "",
|
||||||
_: null,
|
_: null,
|
||||||
};
|
};
|
||||||
this.rerender = () => {
|
this.rerender = () => this.setState({ _: randomString() });
|
||||||
this.setState({ _: Math.random() });
|
|
||||||
};
|
|
||||||
this.findResults = debounce(this.findResults.bind(this), 150);
|
this.findResults = debounce(this.findResults.bind(this), 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue