Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Prettier and StandardJS #474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="ca-es">
<head>
<meta charset="utf-8" />
Expand Down
94 changes: 47 additions & 47 deletions app/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import React from "react";
import { HashRouter as Router } from "react-router-dom";
import React from 'react'
import { HashRouter as Router } from 'react-router-dom'

import Storage from "react-simple-storage";
import { TranslatorProvider, useTranslate } from "react-translate";
import { Helmet, HelmetProvider } from "react-helmet-async";
import available from "./i18n/available";
import Storage from 'react-simple-storage'
import { TranslatorProvider, useTranslate } from 'react-translate'
import { Helmet, HelmetProvider } from 'react-helmet-async'
import available from './i18n/available'

import ErrorCatcher from "./ErrorCatcher";
import Dashboard from "./Dashboard";
import { WidgetsList } from "./Widget";
import ErrorCatcher from './ErrorCatcher'
import Dashboard from './Dashboard'
import { WidgetsList } from './Widget'

import { BackendProvider, IndexesHandler } from "./Backend";
import { BackendProvider, IndexesHandler } from './Backend'

// App Helmet: Controls HTML <head> elements with SideEffect
// - Set a default title and title template, translated
const AppHelmet = ({ language }) => {
const t = useTranslate("App");
const title = t("Covid Data - Refactored");
const t = useTranslate('App')
const title = t('Covid Data - Refactored')
return (
<Helmet titleTemplate={`%s | ${title}`} defaultTitle={title}>
<html lang={language} />
</Helmet>
);
};
)
}

// Concentrate all providers (4) used in the app into a single component
const AppProviders = ({ translations, language, children }) => (
Expand All @@ -31,79 +31,79 @@ const AppProviders = ({ translations, language, children }) => (
<BackendProvider>
<AppHelmet language={language} />
<Router>
<div className="App" id="router-container">
<div className='App' id='router-container'>
{children}
</div>
</Router>
</BackendProvider>
</HelmetProvider>
</TranslatorProvider>
);
)

const fixLocationHash = () => {
const decoded = decodeURIComponent(global.location.hash);
if (decoded !== "" && decoded !== global.location.hash) {
const hash = decoded.replace(/[^#]*(#.*)$/, "$1");
global.location.replace(hash);
const decoded = decodeURIComponent(global.location.hash)
if (decoded !== '' && decoded !== global.location.hash) {
const hash = decoded.replace(/[^#]*(#.*)$/, '$1')
global.location.replace(hash)
}
};
}

const getDefaultLanguage = (available) => {
const languageNav = (global.navigator.language ?? "").toLowerCase();
const languageNav = (global.navigator.language ?? '').toLowerCase()
return available.find((language) => language.key === languageNav)
? languageNav
: "ca-es";
};
: 'ca-es'
}

class App extends React.Component {
constructor() {
super();
constructor () {
super()

// Fix bad browser encoding HASH
fixLocationHash();
fixLocationHash()

const language = getDefaultLanguage(available);
const language = getDefaultLanguage(available)
this.state = {
initializing: true, // For Storage
language,
theme: false, // Use defined by user in browser
tutorialSeen: false,
};
tutorialSeen: false
}
}

// Called after Storage hydrated the component
stopInitializing = () => this.setState({ initializing: false });
stopInitializing = () => this.setState({ initializing: false })

// Handle global configuration options
handleLanguageChange = (language) => this.setState({ language });
handleThemeChange = (theme) => this.setState({ theme });
handleTutorialSeenChange = (tutorialSeen) => this.setState({ tutorialSeen });
handleLanguageChange = (language) => this.setState({ language })
handleThemeChange = (theme) => this.setState({ theme })
handleTutorialSeenChange = (tutorialSeen) => this.setState({ tutorialSeen })

render() {
const { language, theme, tutorialSeen } = this.state;
render () {
const { language, theme, tutorialSeen } = this.state
const translations = available.find(
(_language) => _language.key === language
).value;
).value

return (
<AppProviders
{...{
translations,
language,
language
}}
>
{/* Persistent state saver into localStorage */}
<ErrorCatcher origin="Storage">
<ErrorCatcher origin='Storage'>
<Storage
parent={this}
prefix="App"
blacklist={["initializing"]}
prefix='App'
blacklist={['initializing']}
onParentStateHydrated={this.stopInitializing}
/>
</ErrorCatcher>

{/* Shows the app, with ErrorBoundaries */}
<ErrorCatcher origin="Dashboard">
<ErrorCatcher origin='Dashboard'>
<Dashboard
// Use language and handle its change
language={language}
Expand All @@ -115,19 +115,19 @@ class App extends React.Component {
tutorialSeen={tutorialSeen}
onTutorialSeen={this.handleTutorialSeenChange}
>
<ErrorCatcher origin="IndexesHandler">
<ErrorCatcher origin='IndexesHandler'>
<IndexesHandler>
<ErrorCatcher origin="WidgetsList">
<ErrorCatcher origin='WidgetsList'>
<WidgetsList />
</ErrorCatcher>
</IndexesHandler>
</ErrorCatcher>
</Dashboard>
</ErrorCatcher>
</AppProviders>
);
)
}
}

export default App;
export { fixLocationHash, getDefaultLanguage }; // For tests
export default App
export { fixLocationHash, getDefaultLanguage } // For tests
Loading
Loading