Print queries

This commit is contained in:
Ben Grant 2021-06-19 12:41:50 +10:00
parent fdb7f0ef67
commit b5db9334c8
15 changed files with 110 additions and 26 deletions

View file

@ -93,6 +93,7 @@ const App = () => {
styles={theme => ({ styles={theme => ({
html: { html: {
scrollBehavior: 'smooth', scrollBehavior: 'smooth',
'-webkit-print-color-adjust': 'exact',
}, },
body: { body: {
backgroundColor: theme.background, backgroundColor: theme.background,

View file

@ -29,6 +29,7 @@ import {
People, People,
Person, Person,
StyledMain, StyledMain,
Info,
} from './availabilityViewerStyle'; } from './availabilityViewerStyle';
import locales from 'res/dayjs_locales'; import locales from 'res/dayjs_locales';
@ -162,10 +163,10 @@ const AvailabilityViewer = ({
total={people.filter(p => p.availability.length > 0).length} total={people.filter(p => p.availability.length > 0).length}
onSegmentFocus={count => setFocusCount(count)} onSegmentFocus={count => setFocusCount(count)}
/> />
<Center style={{textAlign: 'center'}}>{t('event:group.info1')}</Center> <Info>{t('event:group.info1')}</Info>
{people.length > 1 && ( {people.length > 1 && (
<> <>
<Center style={{textAlign: 'center'}}>{t('event:group.info2')}</Center> <Info>{t('event:group.info2')}</Info>
<People> <People>
{people.map((person, i) => {people.map((person, i) =>
<Person <Person

View file

@ -220,3 +220,12 @@ export const Person = styled.button`
border-color: ${props.theme.primary}; border-color: ${props.theme.primary};
`} `}
`; `;
export const Info = styled.span`
display: block;
text-align: center;
@media print {
display: none;
}
`;

View file

@ -121,4 +121,14 @@ export const Pressable = styled.button`
transform: none; transform: none;
} }
`} `}
@media print {
${props => !props.secondary && `
box-shadow: 0 4px 0 0 ${props.secondaryColor || props.theme.primaryDark};
`}
&::before {
display: none;
}
}
`; `;

View file

@ -19,4 +19,8 @@ export const Wrapper = styled.footer`
margin-bottom: 20px; margin-bottom: 20px;
} }
`} `}
@media print {
display: none;
}
`; `;

View file

@ -62,4 +62,8 @@ export const Tagline = styled.span`
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@media print {
display: none;
}
`; `;

View file

@ -4,7 +4,7 @@ import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime'; import relativeTime from 'dayjs/plugin/relativeTime';
import { AboutSection, StyledMain } from '../../pages/Home/homeStyle'; import { AboutSection, StyledMain } from '../../pages/Home/homeStyle';
import { Recent } from './recentsStyle'; import { Wrapper, Recent } from './recentsStyle';
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
@ -14,17 +14,19 @@ const Recents = ({ target }) => {
const { t } = useTranslation(['home', 'common']); const { t } = useTranslation(['home', 'common']);
return !!recents.length && ( return !!recents.length && (
<AboutSection id="recents"> <Wrapper>
<StyledMain> <AboutSection id="recents">
<h2>{t('home:recently_visited')}</h2> <StyledMain>
{recents.map(event => ( <h2>{t('home:recently_visited')}</h2>
<Recent href={`/${event.id}`} target={target} key={event.id}> {recents.map(event => (
<span className="name">{event.name}</span> <Recent href={`/${event.id}`} target={target} key={event.id}>
<span locale={locale} className="date" title={dayjs.unix(event.created).format('D MMMM, YYYY')}>{t('common:created', { date: dayjs.unix(event.created).fromNow() })}</span> <span className="name">{event.name}</span>
</Recent> <span locale={locale} className="date" title={dayjs.unix(event.created).format('D MMMM, YYYY')}>{t('common:created', { date: dayjs.unix(event.created).fromNow() })}</span>
))} </Recent>
</StyledMain> ))}
</AboutSection> </StyledMain>
</AboutSection>
</Wrapper>
); );
}; };

View file

@ -1,5 +1,11 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export const Wrapper = styled.div`
@media print {
display: none;
}
`;
export const Recent = styled.a` export const Recent = styled.a`
text-decoration: none; text-decoration: none;
display: flex; display: flex;

View file

@ -33,6 +33,9 @@ export const OpenButton = styled.button`
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
transition: none; transition: none;
} }
@media print {
display: none;
}
`; `;
export const Cover = styled.div` export const Cover = styled.div`
@ -81,6 +84,9 @@ export const Modal = styled.div`
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
transition: none; transition: none;
} }
@media print {
display: none;
}
`; `;
export const Heading = styled.span` export const Heading = styled.span`

View file

@ -47,6 +47,7 @@ const Event = (props) => {
const weekStart = useSettingsStore(state => state.weekStart); const weekStart = useSettingsStore(state => state.weekStart);
const addRecent = useRecentsStore(state => state.addRecent); const addRecent = useRecentsStore(state => state.addRecent);
const removeRecent = useRecentsStore(state => state.removeRecent);
const locale = useLocaleUpdateStore(state => state.locale); const locale = useLocaleUpdateStore(state => state.locale);
const { t } = useTranslation(['common', 'event']); const { t } = useTranslation(['common', 'event']);
@ -86,6 +87,9 @@ const Event = (props) => {
document.title = `${response.data.name} | Crab Fit`; document.title = `${response.data.name} | Crab Fit`;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
if (e.status === 404) {
removeRecent(id);
}
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
@ -302,7 +306,7 @@ const Event = (props) => {
} }
title={!!navigator.clipboard ? t('event:nav.title') : ''} title={!!navigator.clipboard ? t('event:nav.title') : ''}
>{copied ?? `https://crab.fit/${id}`}</ShareInfo> >{copied ?? `https://crab.fit/${id}`}</ShareInfo>
<ShareInfo isLoading={isLoading}> <ShareInfo isLoading={isLoading} className="instructions">
{!!event?.name && {!!event?.name &&
<Trans i18nKey="event:nav.shareinfo">Copy the link to this page, or share via <a onClick={() => gtag('event', 'send_email', { 'event_category': 'event' })} href={`mailto:?subject=${encodeURIComponent(t('event:nav.email_subject', { event_name: event?.name }))}&body=${encodeURIComponent(`${t('event:nav.email_body')} https://crab.fit/${id}`)}`}>email</a>.</Trans> <Trans i18nKey="event:nav.shareinfo">Copy the link to this page, or share via <a onClick={() => gtag('event', 'send_email', { 'event_category': 'event' })} href={`mailto:?subject=${encodeURIComponent(t('event:nav.email_subject', { event_name: event?.name }))}&body=${encodeURIComponent(`${t('event:nav.email_body')} https://crab.fit/${id}`)}`}>email</a>.</Trans>
} }

View file

@ -38,6 +38,12 @@ export const EventDate = styled.span`
border-radius: 3px; border-radius: 3px;
} }
`} `}
@media print {
&::after {
content: ' - ' attr(title);
}
}
`; `;
export const LoginForm = styled.form` export const LoginForm = styled.form`
@ -61,6 +67,10 @@ export const LoginForm = styled.form`
export const LoginSection = styled.section` export const LoginSection = styled.section`
background-color: ${props => props.theme.primaryBackground}; background-color: ${props => props.theme.primaryBackground};
padding: 10px 0; padding: 10px 0;
@media print {
display: none;
}
`; `;
export const Info = styled.p` export const Info = styled.p`
@ -93,6 +103,12 @@ export const ShareInfo = styled.p`
color: ${props.theme.mode === 'light' ? props.theme.primaryDark : props.theme.primaryLight}; color: ${props.theme.mode === 'light' ? props.theme.primaryDark : props.theme.primaryLight};
} }
`} `}
@media print {
&.instructions {
display: none;
}
}
`; `;
export const Tabs = styled.div` export const Tabs = styled.div`
@ -100,6 +116,10 @@ export const Tabs = styled.div`
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin: 30px 0 20px; margin: 30px 0 20px;
@media print {
display: none;
}
`; `;
export const Tab = styled.a` export const Tab = styled.a`

View file

@ -20,6 +20,7 @@ import {
Step, Step,
FakeCalendar, FakeCalendar,
FakeTimeRange, FakeTimeRange,
ButtonArea,
} from './helpStyle'; } from './helpStyle';
const Help = () => { const Help = () => {
@ -82,11 +83,13 @@ const Help = () => {
/> />
</StyledMain> </StyledMain>
<AboutSection id="about"> <ButtonArea>
<StyledMain> <AboutSection id="about">
<Center><Button onClick={() => push('/')}>{t('common:cta')}</Button></Center> <StyledMain>
</StyledMain> <Center><Button onClick={() => push('/')}>{t('common:cta')}</Button></Center>
</AboutSection> </StyledMain>
</AboutSection>
</ButtonArea>
<Footer /> <Footer />
</> </>

View file

@ -108,3 +108,9 @@ export const FakeTimeRange = styled.div`
border-radius: 2px; border-radius: 2px;
} }
`; `;
export const ButtonArea = styled.div`
@media print {
display: none;
}
`;

View file

@ -14,7 +14,7 @@ import {
AboutSection, AboutSection,
P, P,
} from '../Home/homeStyle'; } from '../Home/homeStyle';
import { Note } from './privacyStyle'; import { Note, ButtonArea } from './privacyStyle';
const translationDisclaimer = 'While the translated document is provided for your convenience, the English version as displayed at https://crab.fit is legally binding.'; const translationDisclaimer = 'While the translated document is provided for your convenience, the English version as displayed at https://crab.fit is legally binding.';
@ -98,11 +98,13 @@ const Privacy = () => {
</div> </div>
</StyledMain> </StyledMain>
<AboutSection id="about"> <ButtonArea>
<StyledMain> <AboutSection>
<Center><Button onClick={() => push('/')}>{t('common:cta')}</Button></Center> <StyledMain>
</StyledMain> <Center><Button onClick={() => push('/')}>{t('common:cta')}</Button></Center>
</AboutSection> </StyledMain>
</AboutSection>
</ButtonArea>
<Footer /> <Footer />
</> </>

View file

@ -14,3 +14,9 @@ export const Note = styled.p`
color: ${props => props.theme.mode === 'light' ? props.theme.primaryDark : props.theme.primaryLight}; color: ${props => props.theme.mode === 'light' ? props.theme.primaryDark : props.theme.primaryLight};
} }
`; `;
export const ButtonArea = styled.div`
@media print {
display: none;
}
`;