From f08f6ca0a9d337efff280d4d1669a41b5d9c31c2 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Thu, 2 Sep 2021 22:28:11 +0200 Subject: finish translations, force maximize --- components/App.js | 18 ++++++++----- components/Form.js | 74 ++++++++++++++++++++++++++++++++++++++++++++-------- components/Header.js | 34 +++++++++++++----------- components/Layout.js | 34 ++++++++++++++---------- components/Splash.js | 17 +++++++----- 5 files changed, 124 insertions(+), 53 deletions(-) (limited to 'components') diff --git a/components/App.js b/components/App.js index 59fd5a0..210e0e0 100644 --- a/components/App.js +++ b/components/App.js @@ -1,10 +1,14 @@ import React, {useEffect, useRef} from 'react' +import useSettings from 'hooks/useSettings' +import useMediaQuery from 'hooks/useMediaQuery' import {close, toggleMin, toggleMax, move} from 'helpers/windowActions' import {faArrowUp, faExpandAlt, faTimes, faCompressAlt} from '@fortawesome/free-solid-svg-icons' import {FontAwesomeIcon} from '@fortawesome/react-fontawesome' const App = ({children, app, setApps}) => { + const {t} = useSettings() const winRef = useRef(null); + const forceMax = useMediaQuery(`(max-width: ${app.width}) or (max-height: ${app.height})`); useEffect(() => { move(app.name, winRef, setApps) @@ -17,20 +21,20 @@ const App = ({children, app, setApps}) => { className={ 'window' + (app.min ? ' hidden' : '') - + (app.max ? ' maximized' : '') + + (app.max || forceMax ? ' maximized' : '') } style={{ - maxHeight: app.height, - maxWidth: app.width, + height: app.height, + width: app.width, ...app.pos.length ? {top: app.pos[1], left: app.pos[0]} : { - // top: `calc((( 100vh - ${app.height} ) / 2) + 2em)`, - // left: `calc(( 100vw - ${app.width} ) / 2)`, + top: `calc((( 100vh - ${app.height} ) / 2) + 2em)`, + left: `calc(( 100vw - ${app.width} ) / 2)`, } }} > -

{app.name}

+

{t(app.name)}

{children}
{ app.buttons.includes('min') && ( @@ -38,7 +42,7 @@ const App = ({children, app, setApps}) => { )} - { app.buttons.includes('max') && ( + { app.buttons.includes('max') && !forceMax && ( toggleMax(app.name, setApps)}> diff --git a/components/Form.js b/components/Form.js index f41c958..59f9710 100644 --- a/components/Form.js +++ b/components/Form.js @@ -1,20 +1,72 @@ import styles from 'styles/Main.module.scss' import React from 'react' import PropTypes from 'prop-types' +import useSettings from 'hooks/useSettings' -const Form = ({errorMessage, onSubmit, isLogin}) => ( -
-
- {isLogin ? 'Login to access your notes' : 'Register new user'} -
- - +const Form = ({errorMessage, onSubmit, isLogin}) => { + const {settings, setSettings, t} = useSettings() - + const themeChange = c => { + setSettings(prev => ({...prev, theme: c})) + } - {errorMessage &&

{errorMessage}

} -
-) + const languageChange = l => { + setSettings(prev => ({...prev, language: l})) + } + + return ( +
+
+ {isLogin ? t('log_in') : t('register_user')} +
+ + + {!isLogin && ( + <> + +
+ {t('language')} + {['en', 'pl', 'es', 'de'].map(l => ( + <> + languageChange(l)} + /> + + + ))} +
+
+ {t('color_theme')} + {['green', 'blue', 'black'].map(c => ( + <> + themeChange(c)} + /> +
+ + )} + + + + {errorMessage &&

{t(errorMessage)}

} +
+ ) +} export default Form diff --git a/components/Header.js b/components/Header.js index 5279c80..9ff3d75 100644 --- a/components/Header.js +++ b/components/Header.js @@ -2,15 +2,17 @@ import styles from 'styles/Main.module.scss' import React, {useState} from 'react' import {useRouter} from 'next/router' import Link from 'next/link' -import useUser from 'lib/useUser' -import fetchJson from 'lib/fetchJson' +import useUser from 'hooks/useUser' +import fetchJson from 'helpers/fetchJson' import {focus, toggleMin} from 'helpers/windowActions' import {open} from 'helpers/windowActions' -import appList from 'helpers/appList' +import appList from 'configs/appList' +import useSettings from 'hooks/useSettings' const Header = ({apps, setApps}) => { const [userMenu, setUserMenu] = useState(false); const {user, mutateUser} = useUser() + const {t} = useSettings() const router = useRouter() const handleLogout = async (e) => { @@ -46,7 +48,7 @@ const Header = ({apps, setApps}) => { ...app.min ? {color: '#888'} : {} }} > - {app.name} + {t(app.name)} )) @@ -56,14 +58,14 @@ const Header = ({apps, setApps}) => { {!user?.isLoggedIn && (
  • - Register + {t('register')}
  • )} {!user?.isLoggedIn && (
  • - Login + {t('login')}
  • )} @@ -79,17 +81,19 @@ const Header = ({apps, setApps}) => { <>
    setUserMenu(false)} />
      -
    • - { - open({appName: 'Settings', ...appList.Settings}, setApps) - setUserMenu() - }}> - Settings - -
    • + {user.isVerified && ( +
    • + { + open({appName: 'Settings', ...appList.Settings}, setApps) + setUserMenu() + }}> + {t('Settings')} + +
    • + )}
    • - Logout + {t('logout')}
    diff --git a/components/Layout.js b/components/Layout.js index e915285..d5627e3 100644 --- a/components/Layout.js +++ b/components/Layout.js @@ -1,26 +1,32 @@ import styles from 'styles/Main.module.scss' import React from 'react' import Head from 'next/head' -import {Header, Popup} from 'components' +import {Header, Popup, Splash} from 'components' +import useSettings from 'hooks/useSettings' import PropTypes from 'prop-types' const Layout = ({ children, apps, setApps, - settings, -}) => ( -
    - - My Apps - -
    -
    {children}
    -
    -
    - -
    -) +}) => { + const {settings} = useSettings() + + if (!settings || !settings.theme || !settings.language) return + + return ( +
    + + My Apps + +
    +
    {children}
    +
    +
    + +
    + ) +} export default Layout diff --git a/components/Splash.js b/components/Splash.js index 7976de4..f807202 100644 --- a/components/Splash.js +++ b/components/Splash.js @@ -1,13 +1,18 @@ import styles from 'styles/Main.module.scss' import React from 'react' +import useSettings from 'hooks/useSettings' import {FontAwesomeIcon} from '@fortawesome/react-fontawesome' import {faBan, faSpinner} from '@fortawesome/free-solid-svg-icons' -const Splash = ({type, fixed = false}) => ( -
    - -

    {type === 'connection' ? 'No connection' : 'Loading...'}

    -
    -) +const Splash = ({type, fixed = false}) => { + const {t} = useSettings() + + return ( +
    + +

    {type === 'connection' ? t('no_connection') : t('loading')}

    +
    + ) +} export default Splash -- cgit v1.2.3