Skip to content

Commit

Permalink
chore: fixing linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gruselhaus committed Jan 14, 2022
1 parent b7008d4 commit 2894385
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"prefer-const": ["error", {
"destructuring": "all"
}],
"comma-dangle": ["error", "never"]
"comma-dangle": 0
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"env": {
Expand Down
31 changes: 27 additions & 4 deletions src/Api/API.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getFromHash } from "../Functions/smallestHash";
import Settings from "../Components/Settings";
import escapeRegex from "escape-string-regexp";
import Settings from "../Components/Settings";
import { getFromHash } from "../Functions/smallestHash";

function sortAlphabetically(a, b) {
a = a.toLowerCase();
Expand All @@ -15,7 +15,30 @@ function sortAlphabetically(a, b) {
return 0;
}

const toReplace = ["CDU / CSU", "Union", "CDU/CSU", /(?:<!(Europäischen|Europäische) )Union/gi, "CDU und CSU", "CDU", "CSU", "Freie Demokraten", "Liberalen", "Liberale", "FDP", "BÜNDNIS 90 / DIE GRÜNEN", "BÜNDNIS 90/DIE GRÜNEN", "Grünen", "PIRATENpartei", "alternative für deutschland", "Die Linken", "Die Linke", "Linken", "Linke", "Die Linkspartei.PDS", "unionsgeführten Regierungen"];
const toReplace = [
"CDU / CSU",
"Union",
"CDU/CSU",
/(?:<!(Europäischen|Europäische) )Union/gi,
"CDU und CSU",
"CDU",
"CSU",
"Freie Demokraten",
"Liberalen",
"Liberale",
"FDP",
"BÜNDNIS 90 / DIE GRÜNEN",
"BÜNDNIS 90/DIE GRÜNEN",
"Grünen",
"PIRATENpartei",
"alternative für deutschland",
"Die Linken",
"Die Linke",
"Linken",
"Linke",
"Die Linkspartei.PDS",
"unionsgeführten Regierungen",
];

const url = process.env.REACT_APP_BACKEND_URL || "https://api.parteiduell.de";
export class API {
Expand All @@ -26,7 +49,7 @@ export class API {
fetchApi(path, params) {
const fetchUrl = new URL(path, url);
fetchUrl.search = new URLSearchParams(params);

return fetch(fetchUrl).then(
(result) => result.json(),
(error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from "react";
import { Settings as SettingsIcon } from "react-bytesize-icons";
import Main from "./Main";
import Footer from "./Components/Footer";
import Main from "./Main";

class App extends Component {
constructor(props) {
Expand Down
33 changes: 31 additions & 2 deletions src/Components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,39 @@ import windowSize from "react-window-size";
class Result extends Component {
// return colours for confetti
returnColours() {
if (this.props.selected === "NPD" || this.props.selected === "AfD" || this.props.selected === "DIE RECHTE" || this.props.selected === "REP" || this.props.selected === "BüSo" || this.props.selected === "pro Deutschland" || this.props.selected === "DIE FREIHEIT" || this.props.selected === "Deutsche Konservative" || this.props.selected === "DVU" || this.props.selected === "ALFA") {
if (
this.props.selected === "NPD" ||
this.props.selected === "AfD" ||
this.props.selected === "DIE RECHTE" ||
this.props.selected === "REP" ||
this.props.selected === "BüSo" ||
this.props.selected === "pro Deutschland" ||
this.props.selected === "DIE FREIHEIT" ||
this.props.selected === "Deutsche Konservative" ||
this.props.selected === "DVU" ||
this.props.selected === "ALFA"
) {
return ["#8B4513"];
} else {
return ["#f44336", "#e91e63", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4CAF50", "#8BC34A", "#CDDC39", "#FFEB3B", "#FFC107", "#FF9800", "#FF5722", "#795548"];
return [
"#f44336",
"#e91e63",
"#9c27b0",
"#673ab7",
"#3f51b5",
"#2196f3",
"#03a9f4",
"#00bcd4",
"#009688",
"#4CAF50",
"#8BC34A",
"#CDDC39",
"#FFEB3B",
"#FFC107",
"#FF9800",
"#FF5722",
"#795548",
];
}
}

Expand Down
18 changes: 6 additions & 12 deletions src/Components/Startscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class Startscreen extends Component {
super();
let completedStartscreen = false;
if (typeof Storage !== "undefined") {
completedStartscreen =
localStorage.getItem("completedStartscreen") === "true" ? true : false;
completedStartscreen = localStorage.getItem("completedStartscreen") === "true" ? true : false;
}

this.state = {
Expand All @@ -27,18 +26,13 @@ class Startscreen extends Component {
<div className="startscreen">
<h2>Willkommen bei Parteiduell!</h2>
<p>
Als Teil des „Jugend hackt“-Workshops in Frankfurt am Main haben
wir ein Quiz erstellt, welches Spielenden die Möglichkeit gibt
politische Aussage einer Partei zuzuordnen.
Als Teil des „Jugend hackt“-Workshops in Frankfurt am Main haben wir ein Quiz erstellt, welches Spielenden die Möglichkeit gibt politische Aussage
einer Partei zuzuordnen.
</p>
<p>Wir wollen Menschen unterhaltsam über Politik informieren und die Position der Parteien aufzeigen.</p>
<p>
Wir wollen Menschen unterhaltsam über Politik informieren und die
Position der Parteien aufzeigen.
</p>
<p>
Sie werden immer zuerst eine Frage oder These des Wahl-o-Mats
sehen. Darunter sehen Sie die Stellungnahme einer Partei. Doch
welcher? Das können Sie nun erraten.
Sie werden immer zuerst eine Frage oder These des Wahl-o-Mats sehen. Darunter sehen Sie die Stellungnahme einer Partei. Doch welcher? Das können
Sie nun erraten.
</p>
<p>Viel Spaß!</p>
<label className="next">
Expand Down
15 changes: 3 additions & 12 deletions src/Functions/FragmentIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ export class FragmentIdentifier {

set(item) {
const hashes = smallestHashes(Object.values(item.possibleAnswers));
window.location.hash =
item.theseId +
":" +
item.possibleParties.sort().join(",") +
":" +
hashes[Object.keys(item.possibleAnswers).indexOf(item.answer)];
window.location.hash = item.theseId + ":" + item.possibleParties.sort().join(",") + ":" + hashes[Object.keys(item.possibleAnswers).indexOf(item.answer)];
}

get() {
const [theseId, possibleParties, hash] = decodeURIComponent(
window.location.hash,
)
.substr(1)
.split(":");
const [theseId, possibleParties, hash] = decodeURIComponent(window.location.hash).substr(1).split(":");

this.api.preload();

return this.api
.list(1, { id: theseId, parties: possibleParties.split(",") }) // fetch from REMOTE!
.then(items => {
.then((items) => {
return this.api.getItem(items, hash);
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/Functions/base66.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const stringOfChars =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_~";
const stringOfChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_~";
const radix = stringOfChars.length;

export function encode(number) {
Expand Down
2 changes: 1 addition & 1 deletion src/Functions/findGetParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function findGetParameter(parameterName) {
window.location.search
.substr(1)
.split("&")
.forEach(function(item) {
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
Expand Down
8 changes: 2 additions & 6 deletions src/Functions/smallestHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ function cyrb53(str, seed = 0) {
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 =
Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 =
Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
Math.imul(h1 ^ (h1 >>> 13), 3266489909);
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}

Expand Down
14 changes: 6 additions & 8 deletions src/Main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { css } from "@emotion/react";
import React, { Component } from "react";

import { BarLoader } from "react-spinners";
import { css } from "@emotion/react";

import { API } from "./Api/API";
import "./assets/App.css";
import Result from "./Components/Result";
import Option from "./Components/Option";
import Startscreen from "./Components/Startscreen";
import Result from "./Components/Result";
import Settings from "./Components/Settings";
import { API } from "./Api/API";
import Startscreen from "./Components/Startscreen";
import { findGetParameter } from "./Functions/findGetParameter";
import { FragmentIdentifier } from "./Functions/FragmentIdentifier";

Expand Down Expand Up @@ -109,7 +107,7 @@ class Main extends Component {
return (
<>
<Startscreen />
<Settings ref={this.settings} onClose={this.onSettingsClose.bind(this)}api={ api } />
<Settings ref={this.settings} onClose={this.onSettingsClose.bind(this)} api={api} />
<p className="these">{item.these}</p>
<p className="statement quote" aria-label={item.statement.replace(/█████/g, "Partei")}>
<span aria-hidden="true">{"„" + item.statement + "“"}</span>
Expand All @@ -132,7 +130,7 @@ class Main extends Component {
<Settings ref={this.settings} onClose={this.onSettingsClose.bind(this)} />
<BarLoader css={BarLoaderCSS} sizeUnit={"px"} size={4000} color={"#414242"} />
</>
);
);
}
}
}
Expand Down
51 changes: 19 additions & 32 deletions src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
// opt-in, read https://bit.ly/CRA-PWA

const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
);

export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
Expand All @@ -31,7 +29,7 @@ export function register(config) {
return;
}

window.addEventListener('load', () => {
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

if (isLocalhost) {
Expand All @@ -41,10 +39,7 @@ export function register(config) {
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
console.log("This web app is being served cache-first by a service " + "worker. To learn more, visit https://bit.ly/CRA-PWA");
});
} else {
// Is not localhost. Just register service worker
Expand All @@ -57,22 +52,19 @@ export function register(config) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
console.log("New content is available and will be used when all " + "tabs for this page are closed. See https://bit.ly/CRA-PWA.");

// Execute callback
if (config && config.onUpdate) {
Expand All @@ -82,7 +74,7 @@ function registerValidSW(swUrl, config) {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log("Content is cached for offline use.");

// Execute callback
if (config && config.onSuccess) {
Expand All @@ -93,23 +85,20 @@ function registerValidSW(swUrl, config) {
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
.catch((error) => {
console.error("Error during service worker registration:", error);
});
}

function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
const contentType = response.headers.get("content-type");
if (response.status === 404 || (contentType != null && contentType.indexOf("javascript") === -1)) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
Expand All @@ -120,15 +109,13 @@ function checkValidServiceWorker(swUrl, config) {
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
console.log("No internet connection found. App is running in offline mode.");
});
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister();
});
}
Expand Down

0 comments on commit 2894385

Please sign in to comment.