Skip to content

Commit f9bb84d

Browse files
committed
Prettier
1 parent a6b06be commit f9bb84d

File tree

16 files changed

+279
-188
lines changed

16 files changed

+279
-188
lines changed

src/app/components/body-units/body-units.tsx

+40-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type CTAData = {
1919
description: string;
2020
button_href: string;
2121
button_text: string;
22-
}
22+
};
2323

2424
function CTA({data}: {data: CTAData}) {
2525
const alignment = convertAlignment(data.alignment);
@@ -45,7 +45,7 @@ type AImageData = {
4545
original: {
4646
src: string;
4747
alt: string;
48-
}
48+
};
4949
};
5050
alignment: string;
5151
alt_text: string;
@@ -71,7 +71,7 @@ function AlignedImage({data}: {data: AImageData}) {
7171
type PQData = {
7272
quote: string;
7373
attribution: string;
74-
}
74+
};
7575

7676
function PullQuote({data}: {data: PQData}) {
7777
const model = {
@@ -82,13 +82,14 @@ function PullQuote({data}: {data: PQData}) {
8282
return <Quote model={model} />;
8383
}
8484

85-
8685
export type DocumentData = {
8786
download_url: string;
88-
}
87+
};
8988

9089
function Document({data}: {data: DocumentData}) {
91-
return <JITLoad importFn={() => import('./import-pdf-unit.js')} data={data} />;
90+
return (
91+
<JITLoad importFn={() => import('./import-pdf-unit.js')} data={data} />
92+
);
9293
}
9394

9495
// Using CMS tags, which are not camel-case
@@ -104,25 +105,39 @@ const bodyUnits = {
104105

105106
export type UnitType = {
106107
id: string;
107-
} & ({
108-
type: 'paragraph' | 'aligned_html';
109-
value: string;
110-
} | {
111-
type: 'aligned_image';
112-
value: AImageData;
113-
} | {
114-
type: 'pullquote';
115-
value: PQData;
116-
} | {
117-
type: 'document';
118-
value: DocumentData;
119-
} | {
120-
type: 'blog_cta';
121-
value: CTAData;
122-
})
108+
} & (
109+
| {
110+
type: 'paragraph' | 'aligned_html';
111+
value: string;
112+
}
113+
| {
114+
type: 'aligned_image';
115+
value: AImageData;
116+
}
117+
| {
118+
type: 'pullquote';
119+
value: PQData;
120+
}
121+
| {
122+
type: 'document';
123+
value: DocumentData;
124+
}
125+
| {
126+
type: 'blog_cta';
127+
value: CTAData;
128+
}
129+
);
123130

124131
export default function BodyUnit({unit}: {unit: UnitType}) {
125-
const Unit = bodyUnits[unit.type] as ({data}: {data: typeof unit.value}) => React.JSX.Element;
126-
127-
return Unit ? <Unit data={unit.value} /> : <Unknown data={unit.value} type={unit.type} />;
132+
const Unit = bodyUnits[unit.type] as ({
133+
data
134+
}: {
135+
data: typeof unit.value;
136+
}) => React.JSX.Element;
137+
138+
return Unit ? (
139+
<Unit data={unit.value} />
140+
) : (
141+
<Unknown data={unit.value} type={unit.type} />
142+
);
128143
}

src/app/components/body-units/pdf-unit.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ function toggleFullscreen(
6666
if (!fsFn) {
6767
return;
6868
}
69-
elem.requestFullscreen = elem[fsFn as keyof typeof elem] as () => Promise<void>;
69+
elem.requestFullscreen = elem[
70+
fsFn as keyof typeof elem
71+
] as () => Promise<void>;
7072

7173
if (!document.fullscreenElement) {
7274
elem.requestFullscreen().catch((err) => {
@@ -123,7 +125,9 @@ export default function Document({data}: {data: DocumentData}) {
123125
>
124126
<PDF
125127
file={data.download_url}
126-
onLoadSuccess={({numPages: n}: {numPages: number}) => setNumPages(n)}
128+
onLoadSuccess={({numPages: n}: {numPages: number}) =>
129+
setNumPages(n)
130+
}
127131
inputRef={ref}
128132
>
129133
<div className="pages-side-by-side">

src/app/components/body-units/quote.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import React from 'react';
22
import RawHTML from '~/components/jsx-helpers/raw-html';
33

4-
export default function Quote({model}: {
4+
export default function Quote({
5+
model
6+
}: {
57
model: {
68
content: string;
79
attribution: string;
8-
}
10+
};
911
}) {
1012
return (
11-
<div className='quote'>
13+
<div className="quote">
1214
<blockquote>
1315
<RawHTML html={model.content} />
14-
{
15-
Boolean(model.attribution) &&
16-
<div className="attribution">{model.attribution}</div>
17-
}
16+
{Boolean(model.attribution) && (
17+
<div className="attribution">{model.attribution}</div>
18+
)}
1819
</blockquote>
1920
</div>
2021
);

src/app/components/paginator/paginator-context.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@ import buildContext from '~/components/jsx-helpers/build-context';
44
type ContextParams = {
55
resultsPerPage?: number;
66
initialPage?: number;
7-
}
7+
};
88

9-
function useContextValue(params: ContextParams={}) {
10-
const {resultsPerPage=1, initialPage=1} = params;
9+
function useContextValue(params: ContextParams = {}) {
10+
const {resultsPerPage = 1, initialPage = 1} = params;
1111
const [currentPage, setCurrentPage] = useState(initialPage);
1212
const firstOnPage = (currentPage - 1) * resultsPerPage;
1313
const lastOnPage = firstOnPage + resultsPerPage - 1;
1414
const isVisible = useCallback(
15-
(childIndex: number) => childIndex >= firstOnPage && childIndex <= lastOnPage,
15+
(childIndex: number) =>
16+
childIndex >= firstOnPage && childIndex <= lastOnPage,
1617
[firstOnPage, lastOnPage]
1718
);
1819
const visibleChildren = useCallback(
19-
(children: React.ReactNode[]) => children.slice(firstOnPage, lastOnPage + 1),
20+
(children: React.ReactNode[]) =>
21+
children.slice(firstOnPage, lastOnPage + 1),
2022
[firstOnPage, lastOnPage]
2123
);
2224

23-
return {currentPage, setCurrentPage, resultsPerPage, firstOnPage, lastOnPage, isVisible, visibleChildren};
25+
return {
26+
currentPage,
27+
setCurrentPage,
28+
resultsPerPage,
29+
firstOnPage,
30+
lastOnPage,
31+
isVisible,
32+
visibleChildren
33+
};
2434
}
2535

2636
const {useContext, ContextProvider} = buildContext({useContextValue});
2737

28-
export {
29-
useContext as default,
30-
ContextProvider as PaginatorContextProvider
31-
};
38+
export {useContext as default, ContextProvider as PaginatorContextProvider};

src/app/components/paginator/search-results/paginator.tsx

+25-13
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function getPageIndicators(pages: number, currentPage: number) {
1515
if (pages - currentPage < 3) {
1616
result[0] = pages - indicatorCount + 1;
1717
} else {
18-
result[0] = (currentPage > 3) ? currentPage - 2 : 1;
18+
result[0] = currentPage > 3 ? currentPage - 2 : 1;
1919
}
2020
for (let i = 1; i < indicatorCount; ++i) {
21-
result[i] = result[i-1] + 1;
21+
result[i] = result[i - 1] + 1;
2222
}
2323
return result.map(propsFor);
2424
}
@@ -37,20 +37,30 @@ function PageButtonBar({pages}: {pages: number}) {
3737
}
3838

3939
return (
40-
<nav aria-label='pagination'>
41-
<ul className='no-bullets button-bar'>
42-
<li><button disabled={disablePrevious} onClick={prevPage}>Previous</button></li>
43-
{
44-
pageIndicators.map((indicator) =>
45-
<li key={indicator.page}><button
40+
<nav aria-label="pagination">
41+
<ul className="no-bullets button-bar">
42+
<li>
43+
<button disabled={disablePrevious} onClick={prevPage}>
44+
Previous
45+
</button>
46+
</li>
47+
{pageIndicators.map((indicator) => (
48+
<li key={indicator.page}>
49+
<button
4650
disabled={indicator.disabled}
4751
aria-current={indicator.selected ? 'page' : 'false'}
4852
aria-label={indicator.page}
4953
onClick={() => setCurrentPage(indicator.label)}
50-
>{indicator.label}</button></li>
51-
)
52-
}
53-
<li><button disabled={disableNext} onClick={nextPage}>Next</button></li>
54+
>
55+
{indicator.label}
56+
</button>
57+
</li>
58+
))}
59+
<li>
60+
<button disabled={disableNext} onClick={nextPage}>
61+
Next
62+
</button>
63+
</li>
5464
</ul>
5565
</nav>
5666
);
@@ -62,7 +72,9 @@ export function PaginatorControls({items}: {items: number}) {
6272
const firstIndex = (currentPage - 1) * resultsPerPage;
6373
const endBefore = Math.min(firstIndex + resultsPerPage, items);
6474
const resultRange = `${firstIndex + 1}-${endBefore}`;
65-
const searchTerm = new window.URLSearchParams(window.location.search).get('q');
75+
const searchTerm = new window.URLSearchParams(window.location.search).get(
76+
'q'
77+
);
6678

6779
return (
6880
<div className="paginator">

src/app/components/progress-ring/progress-ring.tsx

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
import React from 'react';
22
import './progress-ring.scss';
33

4-
export default function ProgressRing({message, radius, progress, stroke}: {
4+
export default function ProgressRing({
5+
message,
6+
radius,
7+
progress,
8+
stroke
9+
}: {
510
message?: number;
611
radius: number;
712
progress: number;
813
stroke: number;
914
}) {
1015
const normalizedRadius = radius - stroke * 2;
1116
const circumference = normalizedRadius * 2 * Math.PI;
12-
const basicCircleProps = React.useMemo(
13-
() => {
14-
return ({
15-
cx: radius,
16-
cy: radius,
17-
fill: 'transparent',
18-
r: normalizedRadius,
19-
strokeDasharray: circumference,
20-
strokeWidth: stroke
21-
});
22-
},
23-
[radius, normalizedRadius, circumference, stroke]
24-
);
25-
const strokeDashoffset = circumference - progress / 100 * circumference;
17+
const basicCircleProps = React.useMemo(() => {
18+
return {
19+
cx: radius,
20+
cy: radius,
21+
fill: 'transparent',
22+
r: normalizedRadius,
23+
strokeDasharray: circumference,
24+
strokeWidth: stroke
25+
};
26+
}, [radius, normalizedRadius, circumference, stroke]);
27+
const strokeDashoffset = circumference - (progress / 100) * circumference;
2628

2729
return (
2830
<div className="progress-ring">
29-
<div className="message">
30-
{message} min read
31-
</div>
31+
<div className="message">{message} min read</div>
3232
<svg height={radius * 2} width={radius * 2}>
33-
<circle
34-
{...basicCircleProps}
35-
className="unfinished" />
33+
<circle {...basicCircleProps} className="unfinished" />
3634
<circle
3735
{...basicCircleProps}
3836
className="finished"
39-
strokeDashoffset={strokeDashoffset} />
37+
strokeDashoffset={strokeDashoffset}
38+
/>
4039
</svg>
4140
</div>
4241
);

0 commit comments

Comments
 (0)