Cleaned up styles, squishy crab, better language switching

This commit is contained in:
Ben Grant 2021-05-31 20:33:37 +10:00
parent bb4b6468b4
commit 17290562c8
16 changed files with 140 additions and 133 deletions

View file

@ -36,7 +36,7 @@
</script>
</head>
<body>
<noscript><h1>🦀 Crab Fit doesn't work without Javascript 🏋️</h1><p>Enable Javascript or try a different browser.<p></noscript>
<noscript style="font-family: Karla, sans-serif; text-align: center; margin: 20vh 0; display: block;"><h1>🦀 Crab Fit doesn't work without Javascript 🏋️</h1><p>Enable Javascript or try a different browser.<p></noscript>
<div id="root"></div>
</body>
</html>

View file

@ -1,9 +1,5 @@
import { useState, useEffect, useCallback, Suspense, lazy } from 'react';
import {
BrowserRouter,
Switch,
Route,
} from 'react-router-dom';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import { ThemeProvider, Global } from '@emotion/react';
import { Settings, Loading, Egg } from 'components';

View file

@ -19,8 +19,6 @@ import {
Day,
} from './calendarFieldStyle';
import localeImports from 'res/dayjs_locales';
dayjs.extend(isToday);
dayjs.extend(localeData);
dayjs.extend(updateLocale);
@ -58,8 +56,7 @@ const CalendarField = ({
}) => {
const weekStart = useSettingsStore(state => state.weekStart);
const locale = useLocaleUpdateStore(state => state.locale);
const setLocale = useLocaleUpdateStore(state => state.setLocale);
const { t, i18n } = useTranslation('home');
const { t } = useTranslation('home');
const [type, setType] = useState(0);
@ -92,22 +89,11 @@ const CalendarField = ({
};
useEffect(() => {
if (Object.keys(localeImports).includes(i18n.language)) {
localeImports[i18n.language]().then(() => {
dayjs.locale(i18n.language);
setLocale(dayjs.locale());
if (weekStart !== dayjs.Ls[i18n.language].weekStart) {
dayjs.updateLocale(i18n.language, { weekStart });
}
});
} else {
// Fallback
if (weekStart !== dayjs.Ls.en.weekStart) {
dayjs.updateLocale('en', { weekStart });
}
if (dayjs.Ls.hasOwnProperty(locale) && weekStart !== dayjs.Ls[locale].weekStart) {
dayjs.updateLocale(locale, { weekStart });
}
setDates(calculateMonth(month, year, weekStart));
}, [weekStart, month, year, i18n.language, setLocale]);
}, [weekStart, month, year, locale]);
return (
<Wrapper locale={locale}>

View file

@ -0,0 +1,31 @@
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import {
Wrapper,
A,
Top,
Image,
Title,
Tagline,
} from './logoStyle';
import image from 'res/logo.svg';
const Logo = () => {
const { t } = useTranslation('common');
return (
<Wrapper>
<A as={Link} to="/">
<Top>
<Image src={image} alt="" />
<Title>CRAB FIT</Title>
</Top>
<Tagline>{t('common:tagline')}</Tagline>
</A>
</Wrapper>
);
};
export default Logo;

View file

@ -0,0 +1,64 @@
import styled from '@emotion/styled';
export const Wrapper = styled.div`
display: flex;
align-items: center;
justify-content: center;
`;
export const A = styled.a`
text-decoration: none;
@keyframes jelly {
from,to {
-webkit-transform: scale(1,1);
transform: scale(1,1)
}
25% {
-webkit-transform: scale(.9,1.1);
transform: scale(.9,1.1)
}
50% {
-webkit-transform: scale(1.1,.9);
transform: scale(1.1,.9)
}
75% {
-webkit-transform: scale(.95,1.05);
transform: scale(.95,1.05)
}
}
&:hover img {
animation: jelly .5s 1;
}
`;
export const Top = styled.div`
display: inline-flex;
justify-content: center;
align-items: center;
`;
export const Image = styled.img`
width: 2.5rem;
margin-right: 16px;
`;
export const Title = styled.span`
display: block;
font-size: 2rem;
color: ${props => props.theme.primary};
font-family: 'Molot', sans-serif;
font-weight: 400;
text-shadow: 0 2px 0 ${props => props.theme.primaryDark};
line-height: 1em;
`;
export const Tagline = styled.span`
text-decoration: underline;
font-size: 14px;
padding-top: 6px;
display: flex;
align-items: center;
justify-content: center;
`;

View file

@ -1,10 +1,11 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useTheme } from '@emotion/react';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import { ToggleField, SelectField } from 'components';
import { useSettingsStore } from 'stores';
import { useSettingsStore, useLocaleUpdateStore } from 'stores';
import {
OpenButton,
@ -13,11 +14,27 @@ import {
Cover,
} from './settingsStyle';
import localeImports from 'res/dayjs_locales';
const Settings = () => {
const theme = useTheme();
const store = useSettingsStore();
const [isOpen, setIsOpen] = useState(false);
const { t, i18n } = useTranslation('common');
const setLocale = useLocaleUpdateStore(state => state.setLocale);
useEffect(() => {
if (Object.keys(localeImports).includes(i18n.language)) {
localeImports[i18n.language]().then(() => {
dayjs.locale(i18n.language);
setLocale(dayjs.locale());
document.documentElement.setAttribute('lang', i18n.language);
});
} else {
setLocale('en');
document.documentElement.setAttribute('lang', 'en')
}
}, [i18n.language, setLocale]);
return (
<>

View file

@ -18,3 +18,4 @@ export { default as Settings } from './Settings/Settings';
export { default as Egg } from './Egg/Egg';
export { default as Footer } from './Footer/Footer';
export { default as Recents } from './Recents/Recents';
export { default as Logo } from './Logo/Logo';

View file

@ -21,6 +21,6 @@ i18n
backend: {
loadPath: '/i18n/{{lng}}/{{ns}}.json',
},
});
}).then(() => document.documentElement.setAttribute('lang', i18n.language));
export default i18n;

View file

@ -1,4 +1,3 @@
import { Link } from 'react-router-dom';
import { useForm } from 'react-hook-form';
import { useState, useEffect } from 'react';
import { useTranslation, Trans } from 'react-i18next';
@ -10,7 +9,6 @@ import customParseFormat from 'dayjs/plugin/customParseFormat';
import relativeTime from 'dayjs/plugin/relativeTime';
import {
Center,
Footer,
TextField,
SelectField,
@ -18,12 +16,12 @@ import {
AvailabilityViewer,
AvailabilityEditor,
Error,
Logo,
} from 'components';
import { StyledMain } from '../Home/homeStyle';
import {
StyledMain,
Logo,
Title,
EventName,
EventDate,
LoginForm,
@ -37,9 +35,7 @@ import {
import api from 'services';
import { useSettingsStore, useRecentsStore, useLocaleUpdateStore } from 'stores';
import logo from 'res/logo.svg';
import timezones from 'res/timezones.json';
import localeImports from 'res/dayjs_locales';
dayjs.extend(utc);
dayjs.extend(timezone);
@ -51,10 +47,9 @@ const Event = (props) => {
const weekStart = useSettingsStore(state => state.weekStart);
const addRecent = useRecentsStore(state => state.addRecent);
const setLocale = useLocaleUpdateStore(state => state.setLocale);
const locale = useLocaleUpdateStore(state => state.locale);
const { t, i18n } = useTranslation(['common', 'event']);
const { t } = useTranslation(['common', 'event']);
const { register, handleSubmit } = useForm();
const { id } = props.match.params;
@ -77,15 +72,6 @@ const Event = (props) => {
const [copied, setCopied] = useState(null);
useEffect(() => {
if (Object.keys(localeImports).includes(i18n.language)) {
localeImports[i18n.language]().then(() => {
dayjs.locale(i18n.language);
setLocale(dayjs.locale());
});
}
}, [i18n.language, setLocale]);
useEffect(() => {
const fetchEvent = async () => {
try {
@ -290,13 +276,7 @@ const Event = (props) => {
return (
<>
<StyledMain>
<Link to="/" style={{ textDecoration: 'none' }}>
<Center>
<Logo src={logo} alt="" />
<Title>CRAB FIT</Title>
</Center>
<Center style={{ textDecoration: 'underline', fontSize: 14, paddingTop: 6 }}>{t('common:tagline')}</Center>
</Link>
<Logo />
{(!!event || isLoading) ? (
<>

View file

@ -1,26 +1,5 @@
import styled from '@emotion/styled';
export const StyledMain = styled.div`
width: 600px;
margin: 20px auto;
max-width: calc(100% - 60px);
`;
export const Logo = styled.img`
width: 2.5rem;
margin-right: 16px;
`;
export const Title = styled.span`
display: block;
font-size: 2rem;
color: ${props => props.theme.primary};
font-family: 'Molot', sans-serif;
font-weight: 400;
text-shadow: 0 2px 0 ${props => props.theme.primaryDark};
line-height: 1em;
`;
export const EventName = styled.h1`
text-align: center;
font-weight: 800;

View file

@ -7,21 +7,21 @@ import {
Center,
Footer,
AvailabilityViewer,
Logo,
} from 'components';
import {
StyledMain,
Logo,
Title,
StyledMain,
AboutSection,
P,
} from '../Home/homeStyle';
import {
Step,
FakeCalendar,
FakeTimeRange,
} from './helpStyle';
import logo from 'res/logo.svg';
const Help = () => {
const { push } = useHistory();
const { t } = useTranslation(['common', 'help']);
@ -33,13 +33,7 @@ const Help = () => {
return (
<>
<StyledMain>
<Link to="/" style={{ textDecoration: 'none' }}>
<Center>
<Logo src={logo} alt="" />
<Title>CRAB FIT</Title>
</Center>
<Center style={{ textDecoration: 'underline', fontSize: 14, paddingTop: 6 }}>{t('common:tagline')}</Center>
</Link>
<Logo />
</StyledMain>
<StyledMain>

View file

@ -1,37 +1,5 @@
import styled from '@emotion/styled';
export const StyledMain = styled.div`
width: 600px;
margin: 20px auto;
max-width: calc(100% - 60px);
`;
export const Logo = styled.img`
width: 2.5rem;
margin-right: 16px;
`;
export const Title = styled.span`
display: block;
font-size: 2rem;
color: ${props => props.theme.primary};
font-family: 'Molot', sans-serif;
font-weight: 400;
text-shadow: 0 2px 0 ${props => props.theme.primaryDark};
line-height: 1em;
`;
export const AboutSection = styled.section`
margin: 30px 0 0;
background-color: ${props => props.theme.primaryBackground};
padding: 20px 0;
`;
export const P = styled.p`
font-weight: 500;
line-height: 1.6em;
`;
export const Step = styled.h2`
text-decoration-color: ${props => props.theme.primary};
text-decoration-style: solid;

View file

@ -222,11 +222,11 @@ const Home = ({ offline }) => {
<h2>{t('home:about.name')}</h2>
<Stats>
<Stat>
<StatNumber>{stats.eventCount ?? '300+'}</StatNumber>
<StatNumber>{stats.eventCount ?? '350+'}</StatNumber>
<StatLabel>{t('home:about.events')}</StatLabel>
</Stat>
<Stat>
<StatNumber>{stats.personCount ?? '400+'}</StatNumber>
<StatNumber>{stats.personCount ?? '500+'}</StatNumber>
<StatLabel>{t('home:about.availabilities')}</StatLabel>
</Stat>
</Stats>

View file

@ -1,22 +1,19 @@
import { useEffect } from 'react';
import { Link, useHistory } from 'react-router-dom';
import { useHistory } from 'react-router-dom';
import { useTranslation, Trans } from 'react-i18next';
import {
Button,
Center,
Footer,
Logo,
} from 'components';
import {
StyledMain,
Logo,
Title,
AboutSection,
P,
} from '../Help/helpStyle';
import logo from 'res/logo.svg';
} from '../Home/homeStyle';
const Privacy = () => {
const { push } = useHistory();
@ -29,13 +26,7 @@ const Privacy = () => {
return (
<>
<StyledMain>
<Link to="/" style={{ textDecoration: 'none' }}>
<Center>
<Logo src={logo} alt="" />
<Title>CRAB FIT</Title>
</Center>
<Center style={{ textDecoration: 'underline', fontSize: 14, paddingTop: 6 }}>{t('common:tagline')}</Center>
</Link>
<Logo />
</StyledMain>
<StyledMain>

View file

@ -41,6 +41,6 @@ export const useTWAStore = create(set => ({
}));
export const useLocaleUpdateStore = create(set => ({
locale: undefined,
locale: 'en',
setLocale: locale => set({ locale }),
}));