- { t("Do you want to save the changes ?") }
+
+ { t("Do you want to save the changes ?") }
,
() =>{
return this.save()
@@ -41,135 +42,167 @@ export class IDE extends React.Component {
() => {
this.props.needSavingUpdate(false)
.then(() => this.props.history.push(nextLocation));
- }
+ },
);
return false;
});
}
- componentWillUnmount(){
+ componentWillUnmount() {
this.unblock();
window.clearInterval(this.state.id);
}
- save(){
- if(this.props.needSaving === false) return;
+ save() {
+ if (this.props.needSaving === false) return;
// the ipad is the new IE, they don't support the file object so we got to fallback :(
- let blob = new window.Blob([this.state.contentToSave], {type : 'text/plain'});
- return this.props.onSave(blob).then(() => this.props.needSavingUpdate(false));
+ return this.props.onSave(
+ new window.Blob(
+ [this.state.contentToSave],
+ { type: "text/plain" },
+ ),
+ ).then(() => this.props.needSavingUpdate(false));
}
- onUpdate(property, refresh, value){
+ onUpdate(property, refresh, value) {
this.setState({ [property]: value }, () => {
- if(refresh){
+ if (refresh) {
this.state.event.next(["refresh"]);
}
- if(this.props.content === this.state.contentToSave){
+ if (this.props.content === this.state.contentToSave) {
this.props.needSavingUpdate(false);
- }else{
+ } else {
this.props.needSavingUpdate(true);
}
});
}
/* Org Viewer specific stuff */
- toggleAgenda(force = null){
- this.setState({appear_agenda: force === null ? !this.state.appear_agenda : !!force});
+ toggleAgenda(force = null) {
+ this.setState({
+ appear_agenda: force === null ? !this.state.appear_agenda : !!force,
+ });
}
- toggleTodo(force = null){
- this.setState({appear_todo: force === null ? !this.state.appear_todo : !!force});
+ toggleTodo(force = null) {
+ this.setState({
+ appear_todo: force === null ? !this.state.appear_todo : !!force,
+ });
}
- onModeChange(){
+ onModeChange() {
this.state.event.next(["fold"]);
}
- goTo(lineNumber){
+ goTo(lineNumber) {
this.state.event.next(["goTo", lineNumber]);
}
- download(){
+ download() {
document.cookie = "download=yes; path=/; max-age=120;";
- this.setState({random: Math.random()});
- this.state.id = window.setInterval(() => {
- if(/download=yes/.test(document.cookie) === false){
- window.clearInterval(this.state.id);
- this.setState({random: Math.random()});
- }
- }, 100);
+ this.setState({
+ random: Math.random(),
+ id: window.setInterval(() => {
+ if (/download=yes/.test(document.cookie) === false) {
+ window.clearInterval(this.state.id);
+ this.setState({ random: Math.random() });
+ }
+ }, 100),
+ });
}
- render(){
- const changeExt = function(filename, ext){
+ render() {
+ const changeExt = function(filename, ext) {
return filename.replace(/\.org$/, "."+ext);
};
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.download()} enable={/download=yes/.test(document.cookie) ? false : true}>
-
-
-
-
- { t("Save current file") }
- { t("Export as {{VALUE}}", "HTML") }
- { t("Export as {{VALUE}}", "PDF") }
- { t("Export as {{VALUE}}", "Markdown") }
- { t("Export as {{VALUE}}", "TXT") }
- { t("Export as {{VALUE}}", "Latex") }
- { t("Export as {{VALUE}}", "ical") }
- { t("Export as {{VALUE}}", "Open office") }
- { t("Export as {{VALUE}}", "Beamer") }
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ this.download()}
+ enable={/download=yes/.test(document.cookie) ? false : true}>
+
+
+
+
+ { t("Save current file") }
+ { t("Export as {{VALUE}}", "HTML") }
+ { t("Export as {{VALUE}}", "PDF") }
+ { t("Export as {{VALUE}}", "Markdown") }
+ { t("Export as {{VALUE}}", "TXT") }
+ { t("Export as {{VALUE}}", "Latex") }
+ { t("Export as {{VALUE}}", "ical") }
+ { t("Export as {{VALUE}}", "Open office") }
+ { t("Export as {{VALUE}}", "Beamer") }
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
-
+ onModeChange={this.onUpdate.bind(this, "mode", false)}
+ onFoldChange={this.onUpdate.bind(this, "folding", false)}
+ onChange={this.onUpdate.bind(this, "contentToSave", false)} />
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
);
}
}
+
+export const IDE = withRouter(IDEComponent);
diff --git a/client/pages/viewerpage/image_exif.js b/client/pages/viewerpage/image_exif.js
index 74ddb0b7..226308b2 100644
--- a/client/pages/viewerpage/image_exif.js
+++ b/client/pages/viewerpage/image_exif.js
@@ -1,4 +1,3 @@
-/* eslint-disable max-len, no-invalid-this */
import React from "react";
import EXIF from "exif-js";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
@@ -209,7 +208,7 @@ class LargeExifClass extends Exif {
componentDidMount() {
this.refresh_handler(this.props);
}
- componentWillReceiveProps(props) {
+ UNSAFE_componentWillReceiveProps(props) {
this.refresh_handler(props);
}
diff --git a/client/pages/viewerpage/imageviewer.js b/client/pages/viewerpage/imageviewer.js
index 073c1ac0..500ead13 100644
--- a/client/pages/viewerpage/imageviewer.js
+++ b/client/pages/viewerpage/imageviewer.js
@@ -1,31 +1,29 @@
-import React from 'react';
-import path from 'path';
-import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
+import React, { createRef } from "react";
+import path from "path";
+import ReactCSSTransitionGroup from "react-addons-css-transition-group";
-import { MenuBar } from './menubar';
-import { Bundle, Icon, NgIf, Loader, EventEmitter, EventReceiver } from '../../components/';
-import { alert } from '../../helpers/';
-import { Pager } from './pager';
-import { t } from '../../locales/';
-import './imageviewer.scss';
-import './pager.scss';
+import { MenuBar } from "./menubar";
+import { Bundle, Icon, NgIf, Loader, EventEmitter, EventReceiver } from "../../components/";
+import { alert } from "../../helpers/";
+import { Pager } from "./pager";
+import { t } from "../../locales/";
+import "./imageviewer.scss";
+import "./pager.scss";
const SmallExif = (props) => (
- {(Comp) => }
+ {(Comp) => }
);
const LargeExif = (props) => (
- {(Comp) => }
+ {(Comp) => }
);
-@EventReceiver
-@EventEmitter
-export class ImageViewer extends React.Component{
- constructor(props){
+export class ImageViewerComponent extends React.Component {
+ constructor(props) {
super(props);
this.state = {
preload: null,
@@ -35,55 +33,56 @@ export class ImageViewer extends React.Component{
draggable: true,
};
this.shortcut= (e) => {
- if(e.keyCode === 27){ this.setState({show_exif: false}); }
- else if(e.keyCode === 73){ this.setState({show_exif: !this.state.show_exif}); }
+ if (e.keyCode === 27) this.setState({ show_exif: false });
+ else if (e.keyCode === 73) this.setState({ show_exif: !this.state.show_exif });
};
- this.refresh = () => { this.setState({"_": Math.random()}); };
+ this.refresh = () => this.setState({ "_": Math.random() });
+ this.$container = createRef();
}
- componentDidMount(){
+ componentDidMount() {
this.props.subscribe("media::preload", (preload) => {
- this.setState({preload: preload});
+ this.setState({ preload: preload });
});
- document.addEventListener('webkitfullscreenchange', this.refresh);
- document.addEventListener('mozfullscreenchange', this.refresh);
- document.addEventListener('fullscreenchange', this.refresh);
- document.addEventListener('keydown', this.shortcut);
+ document.addEventListener("webkitfullscreenchange", this.refresh);
+ document.addEventListener("mozfullscreenchange", this.refresh);
+ document.addEventListener("fullscreenchange", this.refresh);
+ document.addEventListener("keydown", this.shortcut);
}
- componentWillUnmount(){
+ componentWillUnmount() {
this.props.unsubscribe("media::preload");
- document.removeEventListener('webkitfullscreenchange', this.refresh);
- document.removeEventListener('mozfullscreenchange', this.refresh);
- document.removeEventListener('fullscreenchange', this.refresh);
- document.removeEventListener('keydown', this.shortcut);
+ document.removeEventListener("webkitfullscreenchange", this.refresh);
+ document.removeEventListener("mozfullscreenchange", this.refresh);
+ document.removeEventListener("fullscreenchange", this.refresh);
+ document.removeEventListener("keydown", this.shortcut);
}
- componentWillReceiveProps(props){
- if(props.data !== this.props.data){
- this.setState({is_loaded: false});
+ UNSAFE_componentWillReceiveProps(props) {
+ if (props.data !== this.props.data) {
+ this.setState({ is_loaded: false });
}
}
- toggleExif(){
- if(window.innerWidth < 580){
+ toggleExif() {
+ if (window.innerWidth < 580) {
alert.now(
);
- }else{
+ } else {
this.setState({
- show_exif: !this.state.show_exif
+ show_exif: !this.state.show_exif,
});
}
}
- requestFullScreen(){
- if("webkitRequestFullscreen" in document.body){
- this.refs.$container.webkitRequestFullscreen();
- }else if("mozRequestFullScreen" in document.body){
- this.refs.$container.mozRequestFullScreen();
+ requestFullScreen() {
+ if ("webkitRequestFullscreen" in document.body) {
+ this.$container.current.webkitRequestFullscreen();
+ } else if ("mozRequestFullScreen" in document.body) {
+ this.$container.current.mozRequestFullScreen();
}
}
- render(){
+ render() {
const hasExif = (filename) => {
const ext = path.extname(filename).toLowerCase().substring(1);
return ["jpg", "jpeg", "tiff", "tif"].indexOf(ext) !== -1;
@@ -91,200 +90,223 @@ export class ImageViewer extends React.Component{
return (
-
-
-
-
-
-
-
-
-
-
- this.setState({is_loaded: true})} url={this.props.data} />
-
-
-
-
{ t("Info") }
-
-
+
+
+
+
+
+
+
+
+
+
+ this.setState({ is_loaded: true })}
+ url={this.props.data} />
-
-
-
-
+
+
+ this.setState({ draggable: files.length > 1 ? true : false })}
+ next={(e) => this.setState({ preload: e })} />
-
this.setState({draggable: files.length > 1 ? true : false})}
- next={(e) => this.setState({preload: e})} />
-
-
-
-
+
+
+
);
}
}
-@EventEmitter
-class ImageFancy extends React.Component {
- constructor(props){
+export const ImageViewer = EventReceiver(EventEmitter(ImageViewerComponent));
+
+class ImageFancyComponent extends React.Component {
+ constructor(props) {
super(props);
this.state = {
isLoading: true,
isError: false,
- drag_init: {x: null, t: null},
- drag_current: {x: null, t: null},
- hasAction: false
+ drag_init: { x: null, t: null },
+ drag_current: { x: null, t: null },
+ hasAction: false,
};
-
this.img = new Image();
- this.img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
+ this.img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=";
}
- componentWillReceiveProps(nextProp){
- if(nextProp.url !== this.props.url){
+ UNSAFE_componentWillReceiveProps(nextProp) {
+ if (nextProp.url !== this.props.url) {
this.setState({
isLoading: true,
isError: false,
- drag_current: {x: 0},
- hasAction: false
+ drag_current: { x: 0 },
+ hasAction: false,
});
}
}
- onLoad(){
- this.setState({isLoading: false});
+ onLoad() {
+ this.setState({ isLoading: false });
this.props.onLoad();
}
- onError(w){
- this.setState({isError: true});
+ onError(w) {
+ this.setState({ isError: true });
}
- imageDragStart(e){
+ imageDragStart(e) {
const t = new Date();
- if(e.touches){
+ if (e.touches) {
this.setState({
- drag_init: {x: e.touches[0].clientX, t: t},
- hasAction: true
+ drag_init: { x: e.touches[0].clientX, t: t },
+ hasAction: true,
});
- }else{
+ } else {
this.setState({
- drag_init: {x: e.pageX, t: t},
- hasAction: true
+ drag_init: { x: e.pageX, t: t },
+ hasAction: true,
});
}
- if(e.dataTransfer) e.dataTransfer.setDragImage(this.img, 0, 0);
+ if (e.dataTransfer) e.dataTransfer.setDragImage(this.img, 0, 0);
}
- imageDragEnd(e){
+ imageDragEnd(e) {
const drag_end = {
- x: function(dragX, touch){
- const t = new Date();
- if(dragX !== null) return dragX;
- if(touch && touch[0]){
+ x: function(dragX, touch) {
+ if (dragX !== null) return dragX;
+ if (touch && touch[0]) {
return touch[0].clientX;
}
return 0;
}(e.pageX || null, e.changedTouches || null),
- t: new Date()
+ t: new Date(),
};
- const direction = function(x_current, x_init){
- if(x_current.t - x_init.t > 200){
- if(Math.abs(x_current.x - x_init.x) < (window.innerWidth < 500 ? window.innerWidth / 3 : 250)) return "neutral";
+ const direction = function(x_current, x_init) {
+ if (x_current.t - x_init.t > 200 &&
+ Math.abs(x_current.x - x_init.x) <
+ (window.innerWidth < 500 ? window.innerWidth / 3 : 250)) {
+ return "neutral";
}
return x_current.x > x_init.x ? "right" : "left";
}(drag_end, this.state.drag_init);
- if(direction === "left"){
+ if (direction === "left") {
return this.setState({
- drag_current: {x: - window.innerWidth},
- hasAction: false
+ drag_current: { x: - window.innerWidth },
+ hasAction: false,
}, () => {
this.props.emit("media::next");
});
- }else if(direction === "right"){
+ } else if (direction === "right") {
return this.setState({
- drag_current: {x: + window.innerWidth},
- hasAction: false
+ drag_current: { x: + window.innerWidth },
+ hasAction: false,
}, () => {
this.props.emit("media::previous");
});
}
return this.setState({
- drag_current: {x: 0},
- hasAction: false
+ drag_current: { x: 0 },
+ hasAction: false,
});
}
- imageDrag(e){
- if(e.pageX > 0){
- this.setState({drag_current: {x: e.pageX - this.state.drag_init.x}});
- }else if(e.touches && e.touches[0].clientX > 0){
- this.setState({drag_current: {x: e.touches[0].clientX - this.state.drag_init.x}});
+ imageDrag(e) {
+ if (e.pageX > 0) {
+ this.setState({
+ drag_current: { x: e.pageX - this.state.drag_init.x },
+ });
+ } else if (e.touches && e.touches[0].clientX > 0) {
+ this.setState({
+ drag_current: { x: e.touches[0].clientX - this.state.drag_init.x },
+ });
}
}
- render(){
- if(this.state.isError){
+ render() {
+ if (this.state.isError) {
return (
- { t("Can't load this picture") }
+
+
+ { t("Can't load this picture") }
+
+
);
}
- if(this.state.isLoading){
+ if (this.state.isLoading) {
return (
-
-
+
+
);
}
return (
-
-
-
-
+
+
+
+
);
}
}
-class Img extends React.Component{
- constructor(props){
- super(props);
- }
+const ImageFancy = EventEmitter(ImageFancyComponent);
- render(){
- const image_url = (url, size) => {
- return url+"&size="+parseInt(Math.max(window.innerWidth*size, window.innerHeight*size));
- };
- if(!this.props.src) return null;
-
- return (
-
- );
- }
+function Img({ src, ...props }) {
+ const image_url = (url, size) => {
+ return url+"&size="+parseInt(Math.max(window.innerWidth*size, window.innerHeight*size));
+ };
+ if (!src) return null;
+ return (
+
+ );
}
diff --git a/client/pages/viewerpage/org_viewer.js b/client/pages/viewerpage/org_viewer.js
index e9972643..8f49c6d6 100644
--- a/client/pages/viewerpage/org_viewer.js
+++ b/client/pages/viewerpage/org_viewer.js
@@ -1,4 +1,3 @@
-/* eslint-disable max-len */
import React from "react";
import { StickyContainer, Sticky } from "react-sticky";
@@ -10,87 +9,100 @@ import { t } from "../../locales/";
import "./org_viewer.scss";
export class OrgEventsViewer extends React.Component {
- shouldComponentUpdate(nextProps){
- if(this.props.content !== nextProps.content) return true;
- if(this.props.isActive !== nextProps.isActive) return true;
+ shouldComponentUpdate(nextProps) {
+ if (this.props.content !== nextProps.content) return true;
+ if (this.props.isActive !== nextProps.isActive) return true;
return false;
}
- render(){
+ render() {
const headlines = this.props.isActive ? extractEvents(this.props.content) : [];
return (
-
+
);
}
}
export class OrgTodosViewer extends React.Component {
- shouldComponentUpdate(nextProps){
- if(this.props.content !== nextProps.content) return true;
- if(this.props.isActive !== nextProps.isActive) return true;
+ shouldComponentUpdate(nextProps) {
+ if (this.props.content !== nextProps.content) return true;
+ if (this.props.isActive !== nextProps.isActive) return true;
return false;
}
- render(){
+ render() {
const headlines = this.props.isActive ? extractTodos(this.props.content) : [];
return (
-
+
);
}
}
-
class OrgViewer extends React.Component {
- constructor(props){
+ constructor(props) {
super(props);
this.state = {
headlines: this.buildHeadlines(props.headlines),
content: props.content,
search: "",
- _: null
+ _: null,
+ };
+ this.rerender = () => {
+ this.setState({ _: Math.random() });
};
- this.rerender = () => {this.setState({_: Math.random()});};
this.findResults = debounce(this.findResults.bind(this), 150);
}
- componentWillReceiveProps(props){
+ UNSAFE_componentWillReceiveProps(props) {
this.setState({
headlines: this.buildHeadlines(props.headlines),
- content: props.content
+ content: props.content,
});
}
- buildHeadlines(headlines){
+ buildHeadlines(headlines) {
return headlines
.reduce((acc, headline) => {
- if(!acc[headline["key"]]){ acc[headline["key"]] = []; }
+ if (!acc[headline["key"]]) {
+ acc[headline["key"]] = [];
+ }
acc[headline["key"]].push(headline);
return acc;
}, {});
}
- onChange(i, j, state){
- this.state.headlines[Object.keys(this.state.headlines)[i]][j].status = state;
+ onChange(i, j, state) {
+ const headlines = { ...this.state.headlines };
+ headlines[Object.keys(this.state.headlines)[i]][j].status = state;
this.setState({
- headlines: this.state.headlines
+ headlines: this.state.headlines,
});
}
- onTaskUpdate(type, line, value){
+ onTaskUpdate(type, line, value) {
const content = this.state.content.split("\n");
- let head_line, item_line, head_status, deadline_line, scheduled_line, insertion_line;
- switch(type){
+ let head_line;
+ let item_line;
+ let head_status;
+ let deadline_line;
+ let scheduled_line;
+ let insertion_line;
+ switch (type) {
case "status":
content[line] = content[line].replace(/^(\*+\s)[A-Z]{3,}(\s.*)$/, "$1"+value+"$2");
break;
case "subtask":
- if(value === "DONE"){
+ if (value === "DONE") {
content[line] = content[line].replace(/\[.\]/, "[X]");
- }else{
+ } else {
content[line] = content[line].replace(/\[.\]/, "[ ]");
}
break;
@@ -99,139 +111,139 @@ class OrgViewer extends React.Component {
content[item_line] = content[item_line].replace(/SCHEDULED: <.*?>\s*/, value ? "SCHEDULED: "+orgdate(value)+" " : "");
this.state.headlines[head_status] = this.state.headlines[head_status]
.map((todo) => {
- if(todo.line === head_line){
- if(value) todo.scheduled.timestamp = new Date(value).toISOString();
+ if (todo.line === head_line) {
+ if (value) todo.scheduled.timestamp = new Date(value).toISOString();
else todo.scheduled = null;
}
return todo;
});
- this.setState({headlines: this.state.headlines});
+ this.setState({ headlines: this.state.headlines });
break;
case "existing_deadline":
[head_line, head_status, item_line] = line;
content[item_line] = content[item_line].replace(/DEADLINE: <.*?>\s*/, value ? "DEADLINE: "+orgdate(value) : "");
this.state.headlines[head_status] = this.state.headlines[head_status]
.map((todo) => {
- if(todo.line === head_line){
- if(value) todo.deadline.timestamp = new Date(value).toISOString();
+ if (todo.line === head_line) {
+ if (value) todo.deadline.timestamp = new Date(value).toISOString();
else todo.deadline = null;
}
return todo;
});
- this.setState({headlines: this.state.headlines});
+ this.setState({ headlines: this.state.headlines });
break;
case "new_scheduled":
[head_line, head_status, deadline_line] = line;
- if(deadline_line !== null){
+ if (deadline_line !== null) {
insertion_line = deadline_line;
content[deadline_line] = "SCHEDULED: "+orgdate(value)+" "+content[deadline_line];
- }else{
+ } else {
insertion_line = head_line + 1;
- if(content[insertion_line] === "" && content[insertion_line + 1] === ""){
+ if (content[insertion_line] === "" && content[insertion_line + 1] === "") {
content[insertion_line] = "SCHEDULED: "+orgdate(value);
- }else{
+ } else {
content.splice(
insertion_line,
0,
- "SCHEDULED: "+orgdate(value)
+ "SCHEDULED: "+orgdate(value),
);
}
}
this.state.headlines[head_status] = this.state.headlines[head_status]
.map((todo) => {
- if(todo.line === head_line){
+ if (todo.line === head_line) {
todo.scheduled = {
line: insertion_line,
keyword: "SCHEDULED",
active: true,
range: null,
repeat: null,
- timestamp: new Date(value).toISOString()
+ timestamp: new Date(value).toISOString(),
};
}
return todo;
});
- this.setState({headlines: this.state.headlines});
+ this.setState({ headlines: this.state.headlines });
break;
case "new_deadline":
[head_line, head_status, scheduled_line] = line;
- if(scheduled_line !== null){
+ if (scheduled_line !== null) {
insertion_line = scheduled_line;
content[scheduled_line] = content[scheduled_line]+" DEADLINE: "+orgdate(value);
- }else{
+ } else {
insertion_line = head_line + 1;
- if(content[insertion_line] === "" && content[insertion_line + 1] === ""){
+ if (content[insertion_line] === "" && content[insertion_line + 1] === "") {
content[insertion_line] = "DEADLINE: "+orgdate(value);
- }else{
+ } else {
content.splice(
insertion_line,
0,
- "DEADLINE: "+orgdate(value)
+ "DEADLINE: "+orgdate(value),
);
}
this.state.headlines[head_status] = this.state.headlines[head_status]
.map((todo) => {
- if(todo.line === head_line){
+ if (todo.line === head_line) {
todo.deadline = {
line: insertion_line,
keyword: "DEADLINE",
active: true,
range: null,
repeat: null,
- timestamp: new Date(value).toISOString()
+ timestamp: new Date(value).toISOString(),
};
}
return todo;
});
- this.setState({headlines: this.state.headlines});
+ this.setState({ headlines: this.state.headlines });
}
break;
}
- this.setState({content: content.join("\n")});
+ this.setState({ content: content.join("\n") });
- function orgdate(_date){
+ function orgdate(_date) {
const date = new Date(_date);
return "<"+date.getFullYear()+"-"+leftPad((date.getMonth() + 1).toString(), 2)+"-"+leftPad(date.getDate().toString(), 2)+" "+day(date.getDay())+">";
- function day(n){
- switch(navigator.language.split("-")[0]){
- case "de": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"][n];
+ function day(n) {
+ switch (navigator.language.split("-")[0]) {
+ case "de": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"][n];
break;
- default: return ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][n];
+ default: return ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][n];
}
}
}
}
- navigate(line){
+ navigate(line) {
this.props.goTo(line);
this.onQuit();
}
- onQuit(){
+ onQuit() {
this.props.onUpdate(this.state.content);
this.props.onQuit();
}
- componentDidMount(){
+ componentDidMount() {
window.addEventListener("resize", this.rerender);
}
- componentWillUnmount(){
+ componentWillUnmount() {
window.removeEventListener("resize", this.rerender);
}
- search(terms){
- this.setState({search: terms}, () => {
+ search(terms) {
+ this.setState({ search: terms }, () => {
this.findResults(terms);
});
}
- findResults(terms){
+ findResults(terms) {
let headlines = this.props.headlines;
- if(terms){
+ if (terms) {
headlines = this.props.headlines.filter((headline) => {
const keywords = terms.split(" ");
- const head = function(){
+ const head = function() {
let str = " ";
str += headline["status"] + " ";
str += headline["title"] + " ";
@@ -246,75 +258,75 @@ class OrgViewer extends React.Component {
return keywords.filter((keyword) => new RegExp(" "+keyword, "i").test(head)).length === keywords.length ? true : false;
});
}
- this.setState({headlines: this.buildHeadlines(headlines)});
+ this.setState({ headlines: this.buildHeadlines(headlines) });
}
- render(){
+ render() {
return (
-
-
- { t("empty") }
-
- 0}>
- 750 ? 545 : window.innerHeight - 202}}>
- {
- Object.keys(this.state.headlines).map((list, i) => {
- return (
-
-
- {
- ({style}) => {
- return (
-
-
{list} {this.state.headlines[list].length}
+
0}>
+ 750 ? 545 : window.innerHeight - 202 }}>
+ {
+ Object.keys(this.state.headlines).map((list, i) => {
+ return (
+
+
+ {
+ ({ style }) => {
+ return (
+
+
{list} {this.state.headlines[list].length}
+
+ );
+ }
+ }
+
+
+ {
+ this.state.headlines[list].map((headline, j) => {
+ return (
+
+ );
+ })
+ }
- );
- }
- }
-
-
- {
- this.state.headlines[list].map((headline, j) => {
- return (
-
- );
- })
- }
-
-
- );
- })
- }
-
-
+
+ );
+ })
+ }
+
+
);
}
@@ -322,37 +334,37 @@ class OrgViewer extends React.Component {
class Headline extends React.Component {
- constructor(props){
+ constructor(props) {
super(props);
this.state = {
status: props.todo_status,
- properties: false
+ properties: false,
};
}
- onMenuAction(key){
- if(key === "navigate"){
+ onMenuAction(key) {
+ if (key === "navigate") {
this.props.goTo();
- }else if(key === "properties"){
- this.setState({properties: !this.state.properties});
+ } else if (key === "properties") {
+ this.setState({ properties: !this.state.properties });
}
}
- onStatusToggle(){
- if(!this.props.todo_status) return;
+ onStatusToggle() {
+ if (!this.props.todo_status) return;
const new_status = this.state.status === "todo" ? "done" : "todo";
- this.setState({status: new_status});
+ this.setState({ status: new_status });
- const new_status_label = function(new_status, initial_status, initial_keyword){
- if(new_status === initial_status) return initial_keyword;
+ const new_status_label = function(new_status, initial_status, initial_keyword) {
+ if (new_status === initial_status) return initial_keyword;
return new_status === "todo" ? "TODO" : "DONE";
}(new_status, this.props.todo_status, this.props.status);
this.props.onTaskUpdate("status", this.props.line, new_status_label);
}
- onTimeSet(keyword, existing, value){
- if(existing === true){
+ onTimeSet(keyword, existing, value) {
+ if (existing === true) {
this.props.onTaskUpdate(
"existing_"+keyword,
[
@@ -360,127 +372,130 @@ class Headline extends React.Component {
this.props.sortKey,
this.props[keyword].line,
],
- value
+ value,
);
- }else{
+ } else {
const opposite_keyword = keyword === "scheduled" ? "deadline" : "scheduled";
this.props.onTaskUpdate(
"new_"+keyword,
[
this.props.line,
this.props.sortKey,
- this.props[opposite_keyword] && this.props[opposite_keyword].line || null
+ this.props[opposite_keyword] && this.props[opposite_keyword].line || null,
],
- value
+ value,
);
}
}
- render(){
+ render() {
const dateInput = (obj) => {
- if(!obj || !obj.timestamp) return "";
+ if (!obj || !obj.timestamp) return "";
const d = new Date(obj.timestamp);
return d.getFullYear()+"-"+leftPad((d.getMonth() + 1).toString(), 2)+"-"+leftPad(d.getDate().toString(), 2);
};
return (
-
-
-
-
{this.props.title}
-
-
-
-
-
-
-
- {
- this.props.tags.map((tag, i) => {
- return (
-
{tag}
- );
- })
- }
+
+
+
+
{this.props.title}
+
+
+
+
+
+
+
+ {
+ this.props.tags.map((tag, i) => {
+ return (
+ {tag}
+ );
+ })
+ }
+
+
-
+
+
+
+
+
+ { t("Navigate") }
+ { t("Properties") }
+
+
-
-
-
-
-
- { t("Navigate") }
- { t("Properties") }
-
-
-
-
-
-
-
- this.onTimeSet("scheduled", true, e.target.value)}/>
-
-
- this.onTimeSet("scheduled", false, e.target.value)}/>
-
-
-
-
-
-
- this.onTimeSet("deadline", true, e.target.value)}/>
-
-
- this.onTimeSet("deadline", false, e.target.value)}/>
-
-
-
-
-
0 && this.state.status === "todo" && this.props.type === "todos"} className="subtask_container">
- {
- this.props.tasks.map((task, i) => {
- return (
-
- );
- })
- }
-
+
+
+
+
+ this.onTimeSet("scheduled", true, e.target.value)}/>
+
+
+ this.onTimeSet("scheduled", false, e.target.value)}/>
+
+
+
+
+
+
+ this.onTimeSet("deadline", true, e.target.value)}/>
+
+
+ this.onTimeSet("deadline", false, e.target.value)}/>
+
+
+
+
+
0 && this.state.status === "todo" && this.props.type === "todos"} className="subtask_container">
+ {
+ this.props.tasks.map((task, i) => {
+ return (
+
+ );
+ })
+ }
+
);
}
}
class Subtask extends React.Component {
- constructor(props){
+ constructor(props) {
super(props);
this.state = this.calculateState();
}
- calculateState(){
- return {checked: this.props.status === "DONE"};
+ calculateState() {
+ return { checked: this.props.status === "DONE" };
}
- updateState(e){
+ updateState(e) {
const checked = e.target.checked;
- this.setState({checked: checked}, () => {
- // We don't want the interface to feel laggy while a task is beeing updated. Updating the content
- // and reparsing the result is an expensive operation, this makes it feel like a piece of cake
+ this.setState({ checked: checked }, () => {
+ // We don't want the interface to feel laggy while a task is beeing updated. Updating
+ // the content and reparsing the result is an expensive operation, this makes it feel
+ // like a piece of cake
window.setTimeout(() => {
- window.requestAnimationFrame(() => this.props.onStatusChange(checked ? "DONE" : "TODO"));
+ window.requestAnimationFrame(() => {
+ this.props.onStatusChange(checked ? "DONE" : "TODO");
+ });
}, 0);
});
}
- render(){
+ render() {
return (
-
-
- {this.props.label}
-
+
+
+ {this.props.label}
+
);
}
diff --git a/client/pages/viewerpage/org_viewer.scss b/client/pages/viewerpage/org_viewer.scss
index 7c67f524..ddc729b8 100644
--- a/client/pages/viewerpage/org_viewer.scss
+++ b/client/pages/viewerpage/org_viewer.scss
@@ -69,7 +69,7 @@
overflow-y: auto;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
- padding: 0 10px 70px 10px;
+ padding: 0 10px 10px 10px;
.sticky_header{
z-index: 2;
diff --git a/client/pages/viewerpage/pager.js b/client/pages/viewerpage/pager.js
index 47be4c57..71cc0608 100644
--- a/client/pages/viewerpage/pager.js
+++ b/client/pages/viewerpage/pager.js
@@ -1,94 +1,98 @@
-import React from 'react';
-import { Link, withRouter } from 'react-router-dom';
+import React, { createRef } from "react";
+import { Link, withRouter } from "react-router-dom";
-import { Files } from '../../model/';
-import { sort } from '../../pages/filespage.helper.js';
-import { Icon, NgIf, EventReceiver, EventEmitter } from '../../components/';
-import { dirname, basename, settings_get, getMimeType, debounce, gid, appendShareToUrl } from '../../helpers/';
-import './pager.scss';
+import { Files } from "../../model/";
+import { sort } from "../../pages/filespage.helper.js";
+import { Icon, NgIf, EventReceiver, EventEmitter } from "../../components/";
+import {
+ dirname, basename, settings_get, getMimeType, debounce, appendShareToUrl,
+} from "../../helpers/";
+import "./pager.scss";
-
-@EventEmitter
-@EventReceiver
-@withRouter
-export class Pager extends React.Component {
- constructor(props){
+class PagerComponent extends React.Component {
+ constructor(props) {
super(props);
this.state = {
files: [],
- n: 0
+ n: 0,
};
+ this.$page = createRef();
this.onKeyPress = this.onKeyPress.bind(this);
this.onSubmitDebounced = debounce(this.onFormSubmit.bind(this), 1000);
}
- componentDidMount(){
+ componentDidMount() {
this.setNavigation(this.props);
window.addEventListener("keyup", this.onKeyPress);
- this.props.subscribe('media::next', () => {
+ this.props.subscribe("media::next", () => {
this.navigatePage(this.calculateNextPageNumber(this.state.n));
});
- this.props.subscribe('media::previous', () => {
+ this.props.subscribe("media::previous", () => {
this.navigatePage(this.calculatePrevPageNumber(this.state.n));
});
}
- componentWillReceiveProps(props){
- if(props.path !== this.props.path){
+ UNSAFE_componentWillReceiveProps(props) {
+ if (props.path !== this.props.path) {
this.setNavigation(props);
}
}
- componentWillUnmount(){
+ componentWillUnmount() {
window.removeEventListener("keyup", this.onKeyPress);
- this.props.unsubscribe('media::next');
- this.props.unsubscribe('media::previous');
+ this.props.unsubscribe("media::next");
+ this.props.unsubscribe("media::previous");
this.hasUnmounted = true;
}
- navigatePage(n){
- if(this.state.files[n]){
+ navigatePage(n) {
+ if (this.state.files[n]) {
const url = appendShareToUrl(this.state.files[n].link);
- if(this.refs.$page) this.refs.$page.blur();
- let preload_index = (n >= this.state.n || (this.state.n === this.state.files.length - 1 && n === 0)) ? this.calculateNextPageNumber(n) : this.calculatePrevPageNumber(n);
+ if (this.$page) this.$page.current.blur();
+ const preload_index = (
+ n >= this.state.n ||
+ (this.state.n === this.state.files.length - 1 && n === 0)
+ ) ? this.calculateNextPageNumber(n) : this.calculatePrevPageNumber(n);
Files.url(this.state.files[preload_index].path)
.then((url) => this.props.emit("media::preload", url))
.then(() => this.props.history.push(url))
.catch(() => {});
}
}
- calculateNextPageNumber(n){
- if(n + 1 >= this.state.files.length) return 0;
+ calculateNextPageNumber(n) {
+ if (n + 1 >= this.state.files.length) return 0;
return n + 1;
}
- calculatePrevPageNumber(n){
- if(n <= 0) return this.state.files.length - 1;
+ calculatePrevPageNumber(n) {
+ if (n <= 0) return this.state.files.length - 1;
return n - 1;
}
- setNavigation(props){
+ setNavigation(props) {
Files._ls_from_cache(dirname(props.path))
.then((f) => {
- if(f === null) return Promise.reject({code: "NO_DATA"});
+ if (f === null) return Promise.reject({ code: "NO_DATA" });
return Promise.resolve(f);
})
- .then((f) => f.results.filter((file) => (isImage(file.name) || isVideo(file.name)) && file.type === "file"))
- .then((f) => sort(f, settings_get('filespage_sort') || 'type'))
+ .then((f) => f.results
+ .filter((file) => (isImage(file.name) || isVideo(file.name)) &&
+ file.type === "file"))
+ .then((f) => sort(f, settings_get("filespage_sort") || "type"))
.then((f) => findPosition(f, basename(props.path)))
.then((res) => {
- if(this.hasUnmounted === true) return;
- if(this.props.pageChange) this.props.pageChange(res[0]);
+ if (this.hasUnmounted === true) return;
+ if (this.props.pageChange) this.props.pageChange(res[0]);
this.setState({
files: res[0],
- n: res[1]
+ n: res[1],
});
})
.catch(() => {});
const findPosition = (files, filename) => {
let i;
- for(i=0; i < files.length; i++){
- if(files[i].name === filename){
+ for (i=0; i < files.length; i++) {
+ if (files[i].name === filename) {
break;
}
}
@@ -102,59 +106,67 @@ export class Pager extends React.Component {
};
}
- onFormInputChange(e){
+ onFormInputChange(e) {
let n = parseInt(e.target.value);
- if(Number.isNaN(n)) n = undefined;
- else if(n < 1) n = 0;
- else if(n > this.state.files.length) n = this.state.files.length - 1;
- else{ n = n - 1; }
- this.setState({n: n});
- if(n >= 0){
+ if (Number.isNaN(n)) n = undefined;
+ else if (n < 1) n = 0;
+ else if (n > this.state.files.length) n = this.state.files.length - 1;
+ else n = n - 1;
+
+ this.setState({ n: n });
+ if (n >= 0) {
this.onSubmitDebounced();
}
}
- onFormSubmit(e){
- if(e) e.preventDefault();
+ onFormSubmit(e) {
+ if (e) e.preventDefault();
this.navigatePage(this.state.n);
}
- onKeyPress(e){
- if(e.target.classList.contains("prevent")) return;
- if(e.keyCode === 39){
+ onKeyPress(e) {
+ if (e.target.classList.contains("prevent")) return;
+ if (e.keyCode === 39) {
this.navigatePage(this.calculateNextPageNumber(this.state.n));
- }else if(e.keyCode === 37){
+ } else if (e.keyCode === 37) {
this.navigatePage(this.calculatePrevPageNumber(this.state.n));
}
}
- render(){
- let inputWidth = this.state.n === undefined ? 12 : ((this.state.n + 1).toString().length) * 12;
+ render() {
+ const inputWidth = this.state.n === undefined ?
+ 12 : ((this.state.n + 1).toString().length) * 12;
const nextLink = () => {
const l = this.state.files[this.calculateNextPageNumber(this.state.n)];
- return (((l && l.link) || "") + window.location.search) || '#';
+ return (((l && l.link) || "") + window.location.search) || "#";
};
const prevLink = () => {
const l = this.state.files[this.calculatePrevPageNumber(this.state.n)];
- return (((l && l.link) || "") + window.location.search) || '#';
+ return (((l && l.link) || "") + window.location.search) || "#";
};
const current_page_number = this.state.n === undefined ? "" : this.state.n + 1;
return (
-
- 0} type="inline">
-
-
-
- /
- {this.state.files.length}
-
-
-
-
+
+ 0} type="inline">
+
+
+
+ /
+ {this.state.files.length}
+
+
+
+
);
}
}
+
+export const Pager = EventEmitter(EventReceiver(withRouter(PagerComponent)));