diff --git a/js/functions.js b/js/functions.js index 1d79057..d216607 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,162 +1,44 @@ -"use strict"; - -// Little display-bar in the upper right corner -var Status = (function(){ - var loadingText = document.getElementById("status-text"); - var statusImage = document.getElementById("status-image"); - - return { - loading: function(msg) { - statusImage.src = "/static/images/loading.gif"; - loadingText.innerHTML = msg; - }, - - success: function(msg) { - statusImage.src = "/static/images/done.png"; - loadingText.innerHTML = _.defaultTo(msg, ""); - }, - - error: function(msg) { - statusImage.src = "/static/images/error.png"; - loadingText.innerHTML = ""+msg+""; - console.error(msg); - } - }; -})(); - - -// Check browser support -var isSupported = self.fetch && self._ && self.Promise; - -// If not supported show error -if(!isSupported) { - (function() { - var isMissing = []; - - if(!self.fetch) isMissing.push("fetch"); - if(!self.Promise) isMissing.push("promise"); - if(!self._) isMissing.push("lodash"); - - // And a link with an error report to reddit... maybe not best way but its something - var url = "https://www.reddit.com/message/compose/?to=Jubbeart"; - url += "&subject="+encodeURIComponent("Missing dependencies: " + isMissing.join(" ")); - url += "&message="+encodeURIComponent("Comment (optional): "); - url += "%0A%0A"+encodeURIComponent("Browser details: "+navigator.userAgent); - Status.error("Error: Missing dependencies ("+isMissing+"). Contact /u/jubbeart"); - })(); -} - -var Reddit = (function() { - var subreddit = _.defaultTo(window.location.pathname.split("/")[2], 'all'); - - return { - subreddit: subreddit, - isAll: _.toLower(subreddit) === 'all', - threadID: window.location.pathname.split("/")[4], - permalink: window.location.pathname.split("/")[6] - }; -})(); - -var Fetch2 = (function(){ - return { - get: function(url, error){ - return fetch(url) - .catch(function(error){ - return Promise.reject(error); - }) - .then(function(response){ - if(response.ok) { - return response; - } else { - return Promise.reject(error); - } - }); - }, - - json: function(response) { - return response.json(); - }, - - handleError: function(error) { - if(_.includes(_.toLower(error), "error")) { - Status.error(error); - } else { - Status.error("Error: "+error); - } - } - }; -})(); - -var ElasticSearch = (function() { - var elastic = "https://elastic.pushshift.io"; - - return { - thread: function(){}, - comment: function(){}, - threadURL: elastic+"/rs/submissions/_search?source=", - commentURL: elastic+"/rc//comments/_search?source=" - }; -})(); // HTML parsing -var HTML = (function (){ - return { - parse: function(htmlString) { - var tmpDiv = document.createElement('div'); - tmpDiv.innerHTML = htmlString; - return tmpDiv.childNodes.length === 0 ? "" : tmpDiv.childNodes[0].nodeValue; - }, - main: document.getElementById("main") - }; -})(); +const HTML = (function () { + return { + parse(htmlString) { + const tmpDiv = document.createElement('div') + tmpDiv.innerHTML = htmlString + return tmpDiv.childNodes.length === 0 ? '' : tmpDiv.childNodes[0].nodeValue + }, + main: document.getElementById('main'), + } +}()) // UTC time handling, very usefull when dealing with elasticsearch -var Time = (function(){ -return { - utc: function() { - return Math.floor(_.now()/1000); - }, +var Time = (function () { + return { + utc() { + return Math.floor(_.now() / 1000) + }, - toUTC: function(timeString) { - var parts = timeString.split(/[a-zA-Z]+/); - var times = 1; + toUTC(timeString) { + const parts = timeString.split(/[a-zA-Z]+/) + let times = 1 - // Number before the time (e.g. 2years or 12hour) - if(parts.length === 2 && parts[0] !== "") { - times = _.parseInt(parts[0]); - } + // Number before the time (e.g. 2years or 12hour) + if (parts.length === 2 && parts[0] !== '') { + times = _.parseInt(parts[0]) + } - if(_.includes(timeString, "hour")) return times * 3600; - if(_.includes(timeString, "day")) return times * 86400; - if(_.includes(timeString, "week")) return times * 604800; - if(_.includes(timeString, "month")) return times * 2592000; - if(_.includes(timeString, "year")) return times * 31536000; - - return Time.utc(); - }, - - difference: function(timeString) { - return Time.utc() - Time.toUTC(timeString); - } -}; -})(); - -// The get variables used in the url -var GetVars = (function(){ - return { - get: function(key) { - var pairs = _.defaultTo(window.location.href.split("?")[1], "").split("&"); - - for(var i = 0, len = pairs.length; i < len; i++) { - if(pairs[i].split("=")[0] === key) { - return pairs[i].split("=")[1]; - } - } - - return undefined; - } - }; -})(); + if (_.includes(timeString, 'hour')) return times * 3600 + if (_.includes(timeString, 'day')) return times * 86400 + if (_.includes(timeString, 'week')) return times * 604800 + if (_.includes(timeString, 'month')) return times * 2592000 + if (_.includes(timeString, 'year')) return times * 31536000 + return Time.utc() + }, + difference(timeString) { + return Time.utc() - Time.toUTC(timeString) + }, + } +}()) diff --git a/js/subreddit.js b/js/subreddit.js index f00d428..950de8d 100644 --- a/js/subreddit.js +++ b/js/subreddit.js @@ -1,8 +1,8 @@ -"use strict"; +'use strict'; -var app = (function(){ -return { - loadPage: function() { +let app = (function () { + return { + loadPage() { Status.loading("Loading subreddit..."); document.title = Reddit.isAll ? "all subreddits" : Reddit.subreddit; HTML.main.innerHTML += _.templates.subredditInfo({subreddit: Reddit.subreddit, time: Vars.time}); @@ -30,21 +30,7 @@ return { Status.success(); }) .catch(Fetch2.handleError); - } -}; -})(); + }, + } +}()); -var Vars = (function(){ - return { - postPerPage: 50, - time: _.defaultTo(GetVars.get("t"), Reddit.isAll ? "12hour" : "day"), - page: _.defaultTo(_.parseInt(GetVars.get("page")), 1), - reload: function(event) { - document.location.href = document.location.href.split("?")[0] + "?t=" + event.value; - } - }; -})(); - -if(isSupported) { - app.loadPage(); -} \ No newline at end of file diff --git a/nginx-config/letsencrypt.conf b/server-config/letsencrypt.conf similarity index 100% rename from nginx-config/letsencrypt.conf rename to server-config/letsencrypt.conf diff --git a/nginx-config/nginx-basic b/server-config/nginx-basic similarity index 100% rename from nginx-config/nginx-basic rename to server-config/nginx-basic diff --git a/nginx-config/nginx-ssl b/server-config/nginx-ssl similarity index 100% rename from nginx-config/nginx-ssl rename to server-config/nginx-ssl diff --git a/src/index.html b/src/index.html index 97bb53c..a45acea 100644 --- a/src/index.html +++ b/src/index.html @@ -1,16 +1,70 @@ + + + - Removeddit - - - - - - + Removeddit + + + + + + - -
+ +
\ No newline at end of file diff --git a/src/js/App.js b/src/js/App.js index 0791b51..b6d6aa9 100644 --- a/src/js/App.js +++ b/src/js/App.js @@ -5,21 +5,22 @@ import { Route, } from 'react-router-dom' -import Menu from 'components/Menu' +import Header from 'components/Header' import { About, Thread, Subreddit } from 'pages' export default props => ( - <> - + +
+
- + ) diff --git a/src/js/components/Menu.js b/src/js/components/Header.js similarity index 88% rename from src/js/components/Menu.js rename to src/js/components/Header.js index 2f75010..5ca7877 100644 --- a/src/js/components/Menu.js +++ b/src/js/components/Header.js @@ -1,6 +1,6 @@ import React from 'react' import { Link } from 'react-router-dom' -import StatusBox from 'components/StatusBox' +import StatusBox from 'containers/StatusBox' export default () => (
diff --git a/src/js/components/SubredditPagination.js b/src/js/components/SubredditPagination.js index 834ae22..22ede00 100644 --- a/src/js/components/SubredditPagination.js +++ b/src/js/components/SubredditPagination.js @@ -1,7 +1,7 @@ import React from 'react' export default (props) => { - let pageination = <> + let pageination = for (let i = props.start; i <= props.end; i++) { if (props.currentPage === i) { @@ -11,13 +11,14 @@ export default (props) => { } } return ( -