Merge pull request #256 from the-programmers-hangout/style-format-code

style: format codebase
This commit is contained in:
Jean-Philippe Sirois
2020-05-19 23:50:50 -04:00
committed by GitHub
38 changed files with 147 additions and 139 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"arrowParens": "avoid", "arrowParens": "always",
"bracketSpacing": true, "bracketSpacing": true,
"endOfLine": "lf", "endOfLine": "lf",
"jsxBracketSameLine": false, "jsxBracketSameLine": false,
+1 -1
View File
@@ -85,7 +85,7 @@ export const PossibleCorrections: FC<IPossibleCorrections> = ({
// filter based on distance // filter based on distance
// levenshtein distance of x means how 'off' it was // levenshtein distance of x means how 'off' it was
const displayArray = linkArray.filter(value => { const displayArray = linkArray.filter((value) => {
return ( return (
levenshteinDistance( levenshteinDistance(
search.toLowerCase(), search.toLowerCase(),
+2 -2
View File
@@ -40,14 +40,14 @@ function Tree({ item }: { item: IFileOrFolder }) {
) )
} }
export const ArchivesSidebar: FC<HTMLAttributes<HTMLDivElement>> = props => { export const ArchivesSidebar: FC<HTMLAttributes<HTMLDivElement>> = (props) => {
const archives = useStaticQuery<IAllArchivesQuery>(ALL_ARCHIVES) const archives = useStaticQuery<IAllArchivesQuery>(ALL_ARCHIVES)
const tree = useBuildTree(archives, "/archives") const tree = useBuildTree(archives, "/archives")
const sortedTree = sort((a, b) => a.title.localeCompare(b.title), tree) const sortedTree = sort((a, b) => a.title.localeCompare(b.title), tree)
return ( return (
<Sidebar {...props}> <Sidebar {...props}>
{sortedTree.map(node => ( {sortedTree.map((node) => (
<Tree item={node} /> <Tree item={node} />
))} ))}
</Sidebar> </Sidebar>
+4 -4
View File
@@ -6,13 +6,13 @@ export const PageLink = styled(Link)`
display: block; display: block;
padding: 4px 0 0; padding: 4px 0 0;
margin-bottom: 4px; margin-bottom: 4px;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
align-self: flex-start; align-self: flex-start;
text-decoration: none; text-decoration: none;
border-bottom: 2px solid transparent; border-bottom: 2px solid transparent;
&:hover { &:hover {
border-color: ${props => border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)}; transparentize(0.7, props.theme.sidebar.foreground)};
} }
@@ -22,10 +22,10 @@ export const PageLink = styled(Link)`
&.active { &.active {
font-weight: 700; font-weight: 700;
color: ${props => props.theme.sidebar.active}; color: ${(props) => props.theme.sidebar.active};
} }
&.active:hover { &.active:hover {
border-color: ${props => transparentize(0.7, props.theme.sidebar.active)}; border-color: ${(props) => transparentize(0.7, props.theme.sidebar.active)};
} }
` `
+1 -1
View File
@@ -53,7 +53,7 @@ export function Breadcrumb({ relativePath, basePath }: IBreadcrumbProps) {
<ChevronUp /> <ChevronUp />
</SC.LinkWrapper> </SC.LinkWrapper>
{breadcrumbItems.map(item => { {breadcrumbItems.map((item) => {
if (item.type === "folder") { if (item.type === "folder") {
foldersDepth++ foldersDepth++
if (foldersDepth > 1) { if (foldersDepth > 1) {
+2 -2
View File
@@ -25,12 +25,12 @@ export const LinkWrapper = styled.div`
} }
svg path { svg path {
fill: ${props => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")}; fill: ${(props) => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")};
} }
` `
export const StyledLink = styled(Link)` export const StyledLink = styled(Link)`
color: ${props => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")}; color: ${(props) => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")};
cursor: pointer; cursor: pointer;
font-weight: 700; font-weight: 700;
text-decoration: underline; text-decoration: underline;
+2 -2
View File
@@ -10,7 +10,7 @@ export const DiscordButtonWrapper = styled.a`
font-weight: 700; font-weight: 700;
text-decoration: none; text-decoration: none;
text-transform: uppercase; text-transform: uppercase;
background: ${props => props.theme.discord.base}; background: ${(props) => props.theme.discord.base};
color: #fff; color: #fff;
padding: 18px 28px; padding: 18px 28px;
border-radius: 5px; border-radius: 5px;
@@ -19,7 +19,7 @@ export const DiscordButtonWrapper = styled.a`
box-shadow: 0 3px 18px rgba(0, 0, 0, 0.3); box-shadow: 0 3px 18px rgba(0, 0, 0, 0.3);
&:hover { &:hover {
background: ${props => props.theme.discord.darker}; background: ${(props) => props.theme.discord.darker};
} }
` `
+1 -1
View File
@@ -6,7 +6,7 @@ export const FooterWrapper = styled.footer`
& a { & a {
display: inline; display: inline;
font-weight: 700; font-weight: 700;
color: ${props => props.theme.main.foreground}; color: ${(props) => props.theme.main.foreground};
text-decoration: none; text-decoration: none;
position: relative; position: relative;
+1 -1
View File
@@ -49,7 +49,7 @@ export const Header: React.FC<IHeaderProps> = ({
{authors.length} contributor{authors.length > 1 && "s"} {authors.length} contributor{authors.length > 1 && "s"}
<SC.Popover> <SC.Popover>
{authors {authors
.map(author => `${author.name}#${author.hash}`) .map((author) => `${author.name}#${author.hash}`)
.join(", ")} .join(", ")}
</SC.Popover> </SC.Popover>
</SC.PopoverToggler> </SC.PopoverToggler>
+4 -4
View File
@@ -15,7 +15,7 @@ export const Meta = styled.div`
display: flex; display: flex;
white-space: nowrap; white-space: nowrap;
align-items: center; align-items: center;
color: ${props => transparentize(0.1, props.theme.main.foreground)}; color: ${(props) => transparentize(0.1, props.theme.main.foreground)};
& + &::before { & + &::before {
content: "•"; content: "•";
@@ -41,7 +41,7 @@ export const Popover = styled.div`
padding: 8px; padding: 8px;
border-radius: 4px; border-radius: 4px;
backdrop-filter: blur(14px); backdrop-filter: blur(14px);
background: ${props => transparentize(0.3, props.theme.main.background)}; background: ${(props) => transparentize(0.3, props.theme.main.background)};
&::before { &::before {
position: absolute; position: absolute;
@@ -54,7 +54,7 @@ export const Popover = styled.div`
border-style: solid; border-style: solid;
border-width: 0 3.5px 4px 3.5px; border-width: 0 3.5px 4px 3.5px;
border-color: transparent transparent border-color: transparent transparent
${props => transparentize(0.3, props.theme.main.background)} transparent; ${(props) => transparentize(0.3, props.theme.main.background)} transparent;
} }
` `
@@ -63,7 +63,7 @@ export const PopoverToggler = styled.div`
align-items: center; align-items: center;
position: relative; position: relative;
border-bottom: 1px dashed border-bottom: 1px dashed
${props => transparentize(0.1, props.theme.main.foreground)}; ${(props) => transparentize(0.1, props.theme.main.foreground)};
&:hover ${Popover} { &:hover ${Popover} {
display: block; display: block;
+1 -1
View File
@@ -10,7 +10,7 @@ interface IHeaderBareboneProps {
className?: string className?: string
} }
export const HeaderBarebone: React.FC<IHeaderBareboneProps> = props => { export const HeaderBarebone: React.FC<IHeaderBareboneProps> = (props) => {
return ( return (
<SC.HeaderWrapper className={props.className}> <SC.HeaderWrapper className={props.className}>
<SC.BackgroundWrapper> <SC.BackgroundWrapper>
+4 -4
View File
@@ -40,7 +40,7 @@ export const BackgroundWrapper = styled.div`
@media screen and (max-width: 767px) { @media screen and (max-width: 767px) {
height: calc(100% - 67px); height: calc(100% - 67px);
background: ${props => darken(0.2, props.theme.main.background)}; background: ${(props) => darken(0.2, props.theme.main.background)};
} }
` `
@@ -57,7 +57,7 @@ export const StyledCircles = styled(Circles)`
` `
export const StyledWavesTop = styled(WavesTop)` export const StyledWavesTop = styled(WavesTop)`
opacity: ${props => (props.theme.name === "dark" ? 0.8 : 0.2)}; opacity: ${(props) => (props.theme.name === "dark" ? 0.8 : 0.2)};
top: -10%; top: -10%;
transform: scaleX(-1); transform: scaleX(-1);
@@ -67,7 +67,7 @@ export const StyledWavesTop = styled(WavesTop)`
` `
export const StyledWavesBottom = styled(WavesBottom)` export const StyledWavesBottom = styled(WavesBottom)`
opacity: ${props => (props.theme.name === "dark" ? 0.8 : 0.2)}; opacity: ${(props) => (props.theme.name === "dark" ? 0.8 : 0.2)};
bottom: -30%; bottom: -30%;
transform: scaleX(-1); transform: scaleX(-1);
@@ -82,7 +82,7 @@ export const Box = styled.div`
position: absolute; position: absolute;
bottom: 40px; bottom: 40px;
margin-left: -16px; margin-left: -16px;
background: ${props => transparentize(0.3, props.theme.main.background)}; background: ${(props) => transparentize(0.3, props.theme.main.background)};
padding: 16px; padding: 16px;
backdrop-filter: blur(14px); backdrop-filter: blur(14px);
max-width: 650px; max-width: 650px;
+1 -1
View File
@@ -10,7 +10,7 @@ export const HomeWrapper = styled.header`
width: 100%; width: 100%;
position: relative; position: relative;
min-height: 100vh; min-height: 100vh;
background: ${props => props.theme.main.background}; background: ${(props) => props.theme.main.background};
overflow: hidden; overflow: hidden;
` `
+1 -1
View File
@@ -5,7 +5,7 @@ const linkStyle = css`
display: inline-block; display: inline-block;
font-weight: 700; font-weight: 700;
color: #fff; color: #fff;
color: ${props => props.theme.main.foreground}; color: ${(props) => props.theme.main.foreground};
font-weight: 700; font-weight: 700;
text-decoration: none; text-decoration: none;
position: relative; position: relative;
+5 -5
View File
@@ -73,11 +73,11 @@ export const MarkdownWrapper = styled.div`
h4 .anchor svg, h4 .anchor svg,
h5 .anchor svg, h5 .anchor svg,
h6 .anchor svg { h6 .anchor svg {
fill: ${props => props.theme.main.foreground}; fill: ${(props) => props.theme.main.foreground};
} }
code { code {
background: ${props => props.theme.code.background}; background: ${(props) => props.theme.code.background};
padding: 4px 8px; padding: 4px 8px;
display: inline; display: inline;
border-radius: 3px; border-radius: 3px;
@@ -88,7 +88,7 @@ export const MarkdownWrapper = styled.div`
:not(pre) > code[class*="language-"], :not(pre) > code[class*="language-"],
pre[class*="language-"] { pre[class*="language-"] {
overflow-x: auto; overflow-x: auto;
background: ${props => props.theme.code.background}; background: ${(props) => props.theme.code.background};
} }
pre > code[class*="language-"] { pre > code[class*="language-"] {
@@ -122,7 +122,7 @@ export const MarkdownWrapper = styled.div`
} }
blockquote { blockquote {
border-left: 2px solid ${props => props.theme.main.foreground}; border-left: 2px solid ${(props) => props.theme.main.foreground};
margin-top: ${BASE_LINE_HEIGHT}px; margin-top: ${BASE_LINE_HEIGHT}px;
margin-bottom: ${BASE_LINE_HEIGHT}px; margin-bottom: ${BASE_LINE_HEIGHT}px;
margin-right: ${BASE_LINE_HEIGHT * 2}px; margin-right: ${BASE_LINE_HEIGHT * 2}px;
@@ -134,7 +134,7 @@ export const MarkdownWrapper = styled.div`
display: inline-block; display: inline-block;
position: relative; position: relative;
font-weight: 700; font-weight: 700;
color: ${props => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")}; color: ${(props) => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")};
text-decoration: none; text-decoration: none;
word-break: break-word; word-break: break-word;
cursor: pointer; cursor: pointer;
+2 -2
View File
@@ -5,7 +5,7 @@ import Logo from "../../images/tph-logo.svg"
export const MobileHeaderWrapper = styled.div` export const MobileHeaderWrapper = styled.div`
z-index: 50; z-index: 50;
background: ${props => transparentize(0.6, props.theme.main.background)}; background: ${(props) => transparentize(0.6, props.theme.main.background)};
backdrop-filter: blur(14px); backdrop-filter: blur(14px);
position: fixed; position: fixed;
top: 0; top: 0;
@@ -52,7 +52,7 @@ export const Burger = styled.div`
content: ""; content: "";
height: 2px; height: 2px;
width: 16px; width: 16px;
background: ${props => props.theme.main.foreground}; background: ${(props) => props.theme.main.foreground};
margin: 0 auto; margin: 0 auto;
} }
+10 -3
View File
@@ -36,7 +36,7 @@ export const PageContent: FC<IPageContentProps> = ({
{recommendedReading && ( {recommendedReading && (
<SC.RecommendedReading> <SC.RecommendedReading>
<SC.SidebarHeader>Recommended reading</SC.SidebarHeader> <SC.SidebarHeader>Recommended reading</SC.SidebarHeader>
{recommendedReading.map(item => { {recommendedReading.map((item) => {
return <PageSidebarLink key={item} href={item} type="internal" /> return <PageSidebarLink key={item} href={item} type="internal" />
})} })}
</SC.RecommendedReading> </SC.RecommendedReading>
@@ -45,8 +45,15 @@ export const PageContent: FC<IPageContentProps> = ({
{externalResources && ( {externalResources && (
<SC.ExternalResources> <SC.ExternalResources>
<SC.SidebarHeader>External Resources</SC.SidebarHeader> <SC.SidebarHeader>External Resources</SC.SidebarHeader>
{externalResources.map(item => { {externalResources.map((item) => {
return <PageSidebarLink key={item.href} href={item.href} text={item.text} type="external" /> return (
<PageSidebarLink
key={item.href}
href={item.href}
text={item.text}
type="external"
/>
)
})} })}
</SC.ExternalResources> </SC.ExternalResources>
)} )}
+2 -2
View File
@@ -16,8 +16,8 @@ export const Content = styled.div`
export const Sidebar = styled.div` export const Sidebar = styled.div`
width: 240px; width: 240px;
flex: 0 0 240px; flex: 0 0 240px;
border-left: 1px solid ${props => darken(0.1, props.theme.main.background)}; border-left: 1px solid ${(props) => darken(0.1, props.theme.main.background)};
color: ${props => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")}; color: ${(props) => (props.theme.name === "dark" ? "#f9f9f9" : "#172129")};
margin: 64px 0; margin: 64px 0;
padding: 0 32px; padding: 0 32px;
position: sticky; position: sticky;
+1 -1
View File
@@ -3,7 +3,7 @@ import styled, { css } from "styled-components"
import { Link } from "gatsby" import { Link } from "gatsby"
const extraLink = css` const extraLink = css`
color: ${props => props.theme.main.foreground}; color: ${(props) => props.theme.main.foreground};
text-decoration: none; text-decoration: none;
word-break: break-word; word-break: break-word;
+3 -3
View File
@@ -34,7 +34,7 @@ function plantTree(item: IFileOrFolder, index?: number) {
return ( return (
<SC.PageLink key={item.title} to={path}> <SC.PageLink key={item.title} to={path}>
{cleanedUpPath.map(node => ( {cleanedUpPath.map((node) => (
// TODO: use helper to format path // TODO: use helper to format path
<SC.NodePart key={node}>{humanize(node)}</SC.NodePart> <SC.NodePart key={node}>{humanize(node)}</SC.NodePart>
))} ))}
@@ -49,7 +49,7 @@ const Language = memo(({ item }: { item: IFolder; index: number }) => {
return ( return (
<SC.TreeWrapper> <SC.TreeWrapper>
<SC.LanguageLabel>{humanize(item.title)}</SC.LanguageLabel> <SC.LanguageLabel>{humanize(item.title)}</SC.LanguageLabel>
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children> <SC.Children>{item.children.map((node) => plantTree(node))}</SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>
) )
}) })
@@ -58,7 +58,7 @@ interface IResourcesList extends HTMLAttributes<HTMLDivElement> {
relativeDirectory?: string relativeDirectory?: string
} }
export const ResourcesList: FC<IResourcesList> = props => { export const ResourcesList: FC<IResourcesList> = (props) => {
const resources = useStaticQuery<IAllResourcesQuery>(ALL_RESOURCES) const resources = useStaticQuery<IAllResourcesQuery>(ALL_RESOURCES)
const filteredResources = { const filteredResources = {
+7 -7
View File
@@ -4,7 +4,7 @@ import styled from "styled-components"
export const ResourcesListWrapper = styled.div` export const ResourcesListWrapper = styled.div`
box-sizing: border-box; box-sizing: border-box;
color: ${props => props.theme.main.foreground}; color: ${(props) => props.theme.main.foreground};
` `
export const Children = styled.div` export const Children = styled.div`
@@ -28,7 +28,7 @@ export const Label = styled.div`
align-self: flex-start; align-self: flex-start;
&:hover { &:hover {
border-color: ${props => border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)}; transparentize(0.7, props.theme.sidebar.foreground)};
} }
@@ -47,7 +47,7 @@ export const LanguageLabel = styled.div`
box-sizing: border-box; box-sizing: border-box;
padding: 4px 15px 4px 0; padding: 4px 15px 4px 0;
font-weight: 700; font-weight: 700;
color: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; color: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
svg { svg {
margin-left: auto; margin-left: auto;
@@ -55,7 +55,7 @@ export const LanguageLabel = styled.div`
transition: transform 0.3s; transition: transform 0.3s;
path { path {
fill: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; fill: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
} }
} }
` `
@@ -72,20 +72,20 @@ export const TreeWrapper = styled.div`
} }
& > ${Label} svg { & > ${Label} svg {
fill: ${props => props.theme.sidebar.foreground}; fill: ${(props) => props.theme.sidebar.foreground};
} }
` `
export const PageLink = styled(Link)` export const PageLink = styled(Link)`
display: block; display: block;
padding: 2px 0; padding: 2px 0;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
align-self: flex-start; align-self: flex-start;
text-decoration: none; text-decoration: none;
border-bottom: 1px solid transparent; border-bottom: 1px solid transparent;
&:hover { &:hover {
border-color: ${props => border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)}; transparentize(0.7, props.theme.sidebar.foreground)};
} }
+10 -10
View File
@@ -30,7 +30,7 @@ const ALL_RESOURCES = graphql`
` `
const childrenSort = sortWith<IFileOrFolder>([ const childrenSort = sortWith<IFileOrFolder>([
descend(f => { descend((f) => {
if (f.title === "intro") { if (f.title === "intro") {
return 1 return 1
} }
@@ -87,7 +87,7 @@ function Folder({ item }: { item: IFolder }) {
}) })
function toggleCollapse() { function toggleCollapse() {
setCollapse(prevState => !prevState) setCollapse((prevState) => !prevState)
} }
const sortedChildren = childrenSort(item.children) const sortedChildren = childrenSort(item.children)
@@ -98,8 +98,8 @@ function Folder({ item }: { item: IFolder }) {
<TriangleDown /> {humanize(item.title)} <TriangleDown /> {humanize(item.title)}
</SC.Label> </SC.Label>
<SC.Children> <SC.Children>
{sortedChildren.map(node => ( {sortedChildren.map((node) => (
<Tree key={node.title + '-tree'} item={node} /> <Tree key={node.title + "-tree"} item={node} />
))} ))}
</SC.Children> </SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>
@@ -119,8 +119,8 @@ const FirstLevelFolder = memo(({ item }: { item: IFolder }) => {
<SC.TreeWrapper className="firstLevel"> <SC.TreeWrapper className="firstLevel">
<SC.FirstLabel>{humanize(item.title)}</SC.FirstLabel> <SC.FirstLabel>{humanize(item.title)}</SC.FirstLabel>
<SC.Children> <SC.Children>
{sortedChildren.map(node => ( {sortedChildren.map((node) => (
<Tree key={node.title + '-tree'} item={node} /> <Tree key={node.title + "-tree"} item={node} />
))} ))}
</SC.Children> </SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>
@@ -135,7 +135,7 @@ const LanguageList: FC<{
return ( return (
<SC.StyledLanguageList> <SC.StyledLanguageList>
{items.map(item => ( {items.map((item) => (
<SC.Language <SC.Language
key={item.title} key={item.title}
className={current === item.title ? "active" : ""} className={current === item.title ? "active" : ""}
@@ -165,7 +165,7 @@ const AllLanguages: FC<{
return ( return (
<SC.ExpandLanguages> <SC.ExpandLanguages>
<SC.ExpandLanguagesHeader <SC.ExpandLanguagesHeader
onClick={() => setExpanded(prevState => !prevState)} onClick={() => setExpanded((prevState) => !prevState)}
> >
Expand languages {expanded ? <SC.CollapseIcon /> : <SC.ExpandIcon />} Expand languages {expanded ? <SC.CollapseIcon /> : <SC.ExpandIcon />}
</SC.ExpandLanguagesHeader> </SC.ExpandLanguagesHeader>
@@ -174,7 +174,7 @@ const AllLanguages: FC<{
) )
} }
export const ResourcesSidebar: FC<HTMLAttributes<HTMLDivElement>> = props => { export const ResourcesSidebar: FC<HTMLAttributes<HTMLDivElement>> = (props) => {
const [expandedLanguages, setExpandedLanguages] = useState(false) const [expandedLanguages, setExpandedLanguages] = useState(false)
const resources = useStaticQuery<IAllResourcesQuery>(ALL_RESOURCES) const resources = useStaticQuery<IAllResourcesQuery>(ALL_RESOURCES)
const languages = useBuildTree(resources, "/resources") const languages = useBuildTree(resources, "/resources")
@@ -184,7 +184,7 @@ export const ResourcesSidebar: FC<HTMLAttributes<HTMLDivElement>> = props => {
languages languages
) )
const currentLanguage = sortedLanguages.find(lang => lang.title === current) const currentLanguage = sortedLanguages.find((lang) => lang.title === current)
return ( return (
<Sidebar {...props}> <Sidebar {...props}>
+16 -16
View File
@@ -30,7 +30,7 @@ export const Label = styled.div`
align-self: flex-start; align-self: flex-start;
&:hover { &:hover {
border-color: ${props => border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)}; transparentize(0.7, props.theme.sidebar.foreground)};
} }
@@ -50,14 +50,14 @@ export const FirstLabel = styled.div`
box-sizing: border-box; box-sizing: border-box;
padding: 12px 15px 12px 0; padding: 12px 15px 12px 0;
font-weight: 700; font-weight: 700;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
cursor: pointer; cursor: pointer;
&:hover { &:hover {
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
svg path { svg path {
fill: ${props => props.theme.sidebar.foreground}; fill: ${(props) => props.theme.sidebar.foreground};
} }
} }
@@ -66,7 +66,7 @@ export const FirstLabel = styled.div`
transform: rotate(90deg); transform: rotate(90deg);
path { path {
fill: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; fill: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
} }
} }
` `
@@ -82,12 +82,12 @@ export const TreeWrapper = styled.div<{ collapsed?: boolean }>`
} }
${Children} { ${Children} {
display: ${props => (props.collapsed ? "none" : "flex")}; display: ${(props) => (props.collapsed ? "none" : "flex")};
} }
& > ${Label} svg { & > ${Label} svg {
transform: rotate(${props => (props.collapsed ? -90 : 0)}deg); transform: rotate(${(props) => (props.collapsed ? -90 : 0)}deg);
fill: ${props => props.theme.sidebar.foreground}; fill: ${(props) => props.theme.sidebar.foreground};
} }
` `
@@ -97,7 +97,7 @@ export const CollapseIcon = styled(Collapse)`
margin-left: auto; margin-left: auto;
path { path {
fill: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; fill: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
} }
` `
@@ -105,7 +105,7 @@ export const ExpandIcon = styled(Expand)`
margin-left: auto; margin-left: auto;
path { path {
fill: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; fill: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
} }
` `
@@ -113,7 +113,7 @@ export const ExpandLanguages = styled.div`
padding: 12px 15px 12px 0; padding: 12px 15px 12px 0;
border-bottom: 1px solid border-bottom: 1px solid
${props => transparentize(0.8, props.theme.sidebar.foreground)}; ${(props) => transparentize(0.8, props.theme.sidebar.foreground)};
margin-bottom: 8px; margin-bottom: 8px;
` `
@@ -122,7 +122,7 @@ export const ExpandLanguagesHeader = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
cursor: pointer; cursor: pointer;
color: ${props => transparentize(0.5, props.theme.sidebar.foreground)}; color: ${(props) => transparentize(0.5, props.theme.sidebar.foreground)};
font-weight: 700; font-weight: 700;
&:hover { &:hover {
@@ -141,14 +141,14 @@ export const StyledLanguageList = styled.div`
const item = css` const item = css`
display: block; display: block;
margin-bottom: 4px; margin-bottom: 4px;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
align-self: flex-start; align-self: flex-start;
text-decoration: none; text-decoration: none;
border-bottom: 2px solid transparent; border-bottom: 2px solid transparent;
cursor: pointer; cursor: pointer;
&:hover { &:hover {
border-color: ${props => border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)}; transparentize(0.7, props.theme.sidebar.foreground)};
} }
@@ -159,11 +159,11 @@ const item = css`
&.active { &.active {
font-weight: 700; font-weight: 700;
color: ${props => props.theme.sidebar.active}; color: ${(props) => props.theme.sidebar.active};
} }
&.active:hover { &.active:hover {
border-color: ${props => transparentize(0.7, props.theme.sidebar.active)}; border-color: ${(props) => transparentize(0.7, props.theme.sidebar.active)};
} }
` `
+3 -3
View File
@@ -17,9 +17,9 @@ const MenuItem: FC<IMenuItemProps> = ({ children, to }) => {
) )
} }
export const Sidebar: FC<PropsWithChildren< export const Sidebar: FC<PropsWithChildren<HTMLAttributes<HTMLDivElement>>> = (
HTMLAttributes<HTMLDivElement> props
>> = props => { ) => {
const { children, ...restProps } = props const { children, ...restProps } = props
return ( return (
+5 -5
View File
@@ -5,8 +5,8 @@ import { transparentize } from "polished"
export const SidebarWrapper = styled.div` export const SidebarWrapper = styled.div`
box-sizing: border-box; box-sizing: border-box;
flex: 0 0 320px; flex: 0 0 320px;
background: ${props => props.theme.sidebar.background}; background: ${(props) => props.theme.sidebar.background};
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
position: fixed; position: fixed;
top: 0; top: 0;
bottom: 0; bottom: 0;
@@ -30,7 +30,7 @@ export const SidebarWrapper = styled.div`
export const Title = styled(Link)` export const Title = styled(Link)`
display: block; display: block;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
font-size: 30px; font-size: 30px;
line-height: 34px; line-height: 34px;
font-weight: 700; font-weight: 700;
@@ -53,7 +53,7 @@ export const Menu = styled.nav`
padding-top: 20px; padding-top: 20px;
&.has-border { &.has-border {
border-top: ${props => border-top: ${(props) =>
`1px dashed ${transparentize(0.8, props.theme.sidebar.foreground)}`}; `1px dashed ${transparentize(0.8, props.theme.sidebar.foreground)}`};
} }
` `
@@ -61,7 +61,7 @@ export const Menu = styled.nav`
export const menuItemStyles = css` export const menuItemStyles = css`
padding: 4px 0; padding: 4px 0;
font-size: 20px; font-size: 20px;
color: ${props => props.theme.sidebar.foreground}; color: ${(props) => props.theme.sidebar.foreground};
text-decoration: none; text-decoration: none;
&:hover, &:hover,
+3 -3
View File
@@ -14,7 +14,7 @@ function containerWidth(count: number): number {
export const StackedAvatarsWrapper = styled.div<{ count: number }>` export const StackedAvatarsWrapper = styled.div<{ count: number }>`
display: flex; display: flex;
margin-right: 16px; margin-right: 16px;
width: ${props => containerWidth(props.count)}px; width: ${(props) => containerWidth(props.count)}px;
` `
export const AuthorAvatar = styled.img<{ index: number }>` export const AuthorAvatar = styled.img<{ index: number }>`
@@ -24,6 +24,6 @@ export const AuthorAvatar = styled.img<{ index: number }>`
flex: 0 0 ${AVATAR_SIZE}px; flex: 0 0 ${AVATAR_SIZE}px;
border: 2px solid #4c6780; border: 2px solid #4c6780;
border-radius: 50%; border-radius: 50%;
z-index: ${props => props.index}; z-index: ${(props) => props.index};
left: -${props => AVATAR_SIZE * OVERLAP_AMOUT * props.index}px; left: -${(props) => AVATAR_SIZE * OVERLAP_AMOUT * props.index}px;
` `
+1 -1
View File
@@ -10,6 +10,6 @@ export const Link = styled.span`
&:hover { &:hover {
border-bottom: 2px solid border-bottom: 2px solid
${props => transparentize(0.6, props.theme.sidebar.foreground)}; ${(props) => transparentize(0.6, props.theme.sidebar.foreground)};
} }
` `
+6 -2
View File
@@ -35,13 +35,17 @@ export const Toc: FC<ITocProps> = ({ header, items }) => {
return ( return (
<SC.TocWrapper> <SC.TocWrapper>
{header} {header}
{items.map(item => { {items.map((item) => {
const { prefix, title } = extractTitle(item.title) const { prefix, title } = extractTitle(item.title)
return ( return (
<SC.TocItem key={item.link} className={`depth-${item.depth}`}> <SC.TocItem key={item.link} className={`depth-${item.depth}`}>
{prefix} {prefix}
<PageSidebarLink href={`${pathname}${item.link}`} text={title} type="anchor" /> <PageSidebarLink
href={`${pathname}${item.link}`}
text={title}
type="anchor"
/>
</SC.TocItem> </SC.TocItem>
) )
})} })}
+2 -2
View File
@@ -1,10 +1,10 @@
import React, { FC } from "react" import React, { FC } from "react"
import * as SC from "./styles" import * as SC from "./styles"
export const WavesTop: FC = props => { export const WavesTop: FC = (props) => {
return <SC.StyledWavesTop {...props} /> return <SC.StyledWavesTop {...props} />
} }
export const WavesBottom: FC = props => { export const WavesBottom: FC = (props) => {
return <SC.StyledWavesBottom {...props} /> return <SC.StyledWavesBottom {...props} />
} }
@@ -12,7 +12,7 @@ title: Arrow functions
Brought into ES6, arrow functions are a new way to declare functions, and allow for shorter syntax. For example, below is a regular function, as usually seen before ES6. Brought into ES6, arrow functions are a new way to declare functions, and allow for shorter syntax. For example, below is a regular function, as usually seen before ES6.
```js ```js
const sayHello = function() { const sayHello = function () {
console.log("hello"); console.log("hello");
}; };
``` ```
@@ -36,7 +36,7 @@ const sayHello = (nameOne, nameTwo) => {
For a single parameter, the parentheses can be omitted: For a single parameter, the parentheses can be omitted:
```js ```js
const sayHello = name => { const sayHello = (name) => {
console.log("hello", name); console.log("hello", name);
}; };
``` ```
@@ -50,13 +50,13 @@ const sayHello = () => "hello";
The same is also true of functions returning an expression using parameters, too. The same is also true of functions returning an expression using parameters, too.
```js ```js
const sayHello = name => `hello ${name}`; const sayHello = (name) => `hello ${name}`;
``` ```
Or even... Or even...
```js ```js
const helloObject = name => ({ const helloObject = (name) => ({
isGreeting: true, isGreeting: true,
helloName: name, helloName: name,
}); });
@@ -73,7 +73,7 @@ The keyword `this` is handled differently in arrow functions. In an arrow functi
Using regular anonymous function, `this` is refers to the `HTMLButtonObject` that called it, and therefore the function outputs `[object HTMLButtonElement]` to the console. Using regular anonymous function, `this` is refers to the `HTMLButtonObject` that called it, and therefore the function outputs `[object HTMLButtonElement]` to the console.
```js ```js
document.querySelector("#btn").addEventListener("click", function() { document.querySelector("#btn").addEventListener("click", function () {
console.log(this); // outputs "[object HTMLButtonElement]" console.log(this); // outputs "[object HTMLButtonElement]"
}); });
``` ```
@@ -35,11 +35,11 @@ const users = [
]; ];
// functional way // functional way
const foundUser = users.find(user => user.name === "John"); const foundUser = users.find((user) => user.name === "John");
// iterative way // iterative way
let foundUser = null; let foundUser = null;
users.forEach(user => { users.forEach((user) => {
if (user.name === "John") { if (user.name === "John") {
foundUser = user; foundUser = user;
} }
@@ -71,11 +71,11 @@ const users = [
]; ];
// functional way // functional way
const youngerUsers = users.filter(user => user.age < 18); const youngerUsers = users.filter((user) => user.age < 18);
// iterative way // iterative way
const youngerUsers = []; const youngerUsers = [];
users.forEach(user => { users.forEach((user) => {
if (user.age < 18) { if (user.age < 18) {
youngerUsers.push(user); youngerUsers.push(user);
} }
@@ -105,11 +105,11 @@ const users = [
]; ];
// functional way // functional way
const userNames = users.map(user => user.name); const userNames = users.map((user) => user.name);
// iterative way // iterative way
const userNames = []; const userNames = [];
users.forEach(user => { users.forEach((user) => {
userNames.push(user.name); userNames.push(user.name);
}); });
@@ -140,7 +140,7 @@ const totalAge = users.reduce((acc, user) => acc + user.age, 0);
// iterative way // iterative way
let totalAge = 0; let totalAge = 0;
users.forEach(user => { users.forEach((user) => {
totalAge += user.age; totalAge += user.age;
}); });
@@ -166,7 +166,7 @@ const users = [
]; ];
// functional way // functional way
const hasYoungUsers = users.some(user => user.age < 18); const hasYoungUsers = users.some((user) => user.age < 18);
// iterative way // iterative way
let hasYoungUsers = false; let hasYoungUsers = false;
@@ -193,7 +193,7 @@ const users = [
]; ];
// functional way // functional way
const allUsersAreOldEnough = users.every(user => user.age < 18); const allUsersAreOldEnough = users.every((user) => user.age < 18);
// iterative way // iterative way
let allUsersAreOldEnough = true; let allUsersAreOldEnough = true;
@@ -219,7 +219,7 @@ const found = pets.includes("dog");
// iterative way // iterative way
let found = false; let found = false;
pets.forEach(pet => { pets.forEach((pet) => {
if (pet === "dog") { if (pet === "dog") {
found = true; found = true;
} }
@@ -130,13 +130,13 @@ Below is the same code implemented without using Async / Await as a comparision.
```js ```js
function getCharacters() { function getCharacters() {
return fetch(`https://rickandmortyapi.com/api/character`) return fetch(`https://rickandmortyapi.com/api/character`)
.then(response => response.json()) .then((response) => response.json())
.then(response => response.results); .then((response) => response.results);
} }
getCharacters() getCharacters()
.then(characters => { .then((characters) => {
console.log(characters); // (20) [{...}, {...}, {...}] console.log(characters); // (20) [{...}, {...}, {...}]
}) })
.catch(err => console.error(err)); .catch((err) => console.error(err));
``` ```
@@ -43,7 +43,7 @@ In order to access this information, we'll have to call the `.then` method on ou
to access the actual members like so. to access the actual members like so.
```js ```js
getMembers("The Programmers Hangout").then(members => { getMembers("The Programmers Hangout").then((members) => {
console.log(members); // (32k) [{...}, {...}, {...}] console.log(members); // (32k) [{...}, {...}, {...}]
}); });
``` ```
@@ -64,7 +64,7 @@ You may have tried doing something like this before.
```js ```js
// Incorrect code, don't copy! // Incorrect code, don't copy!
let results; let results;
getWeather("Los Angeles").then(weather => { getWeather("Los Angeles").then((weather) => {
results = weather; results = weather;
}); });
console.log(results); // undefined console.log(results); // undefined
@@ -80,7 +80,7 @@ you can watch [this amazing talk](https://youtu.be/8aGhZQkoFbQ) on it to learn m
In order to fix this problem we need to move the `console.log` inside the `.then` callback like so: In order to fix this problem we need to move the `console.log` inside the `.then` callback like so:
```js ```js
getWeather("Los Angeles").then(weather => { getWeather("Los Angeles").then((weather) => {
console.log(weather); // Sunny, probably console.log(weather); // Sunny, probably
}); });
``` ```
@@ -93,11 +93,11 @@ You can try it in your browser if you want to test it out.
```js ```js
function getCharacters() { function getCharacters() {
return fetch(`https://rickandmortyapi.com/api/character`) return fetch(`https://rickandmortyapi.com/api/character`)
.then(response => response.json()) .then((response) => response.json())
.then(response => response.results); .then((response) => response.results);
} }
getCharacters().then(characters => { getCharacters().then((characters) => {
console.log(characters); // (20) [{...}, {...}, {...}] console.log(characters); // (20) [{...}, {...}, {...}]
}); });
``` ```
@@ -9,9 +9,9 @@ The first naive attempt, using new Promise for something that already returns a
```js ```js
function doAsync(number) { function doAsync(number) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
doDatabase().then(function(dbResult) { doDatabase().then(function (dbResult) {
otherDbFunction(dbResult).then(function(secondResult) { otherDbFunction(dbResult).then(function (secondResult) {
resolve(secondResult + 10); resolve(secondResult + 10);
}); });
}); });
@@ -24,8 +24,8 @@ already returns a promise, you can just return the original thing.
```js ```js
function doAsync(number) { function doAsync(number) {
return doDatabase().then(function(dbResult) { return doDatabase().then(function (dbResult) {
otherDbFunction(dbResult).then(function(secondResult) { otherDbFunction(dbResult).then(function (secondResult) {
return secondResult + 10; return secondResult + 10;
}); });
}); });
@@ -38,10 +38,10 @@ is that they allow you to chain them sequentially.
```js ```js
function doAsync(number) { function doAsync(number) {
return doDatabase() return doDatabase()
.then(function(dbResult) { .then(function (dbResult) {
return otherDbFunction(dbResult); return otherDbFunction(dbResult);
}) })
.then(function(secondResult) { .then(function (secondResult) {
return secondResult + 10; return secondResult + 10;
}); });
} }
@@ -54,7 +54,7 @@ variable, you can pass in the entire function itself to the then block
function doAsync(number) { function doAsync(number) {
return doDatabase() return doDatabase()
.then(otherDbFunction) .then(otherDbFunction)
.then(function(secondResult) { .then(function (secondResult) {
return secondResult + 10; return secondResult + 10;
}); });
} }
@@ -63,10 +63,10 @@ function doAsync(number) {
And you don't need those returns if you just have ES6 arrow functions And you don't need those returns if you just have ES6 arrow functions
```js ```js
const doAsync = number => const doAsync = (number) =>
doDatabase() doDatabase()
.then(otherDbFunction) .then(otherDbFunction)
.then(secondResult => secondResult + 10); .then((secondResult) => secondResult + 10);
``` ```
Wow, that last one looks a lot cleaner to me than the first. Keeping that in mind, maybe we could be making some of our other functions cleaner as well Wow, that last one looks a lot cleaner to me than the first. Keeping that in mind, maybe we could be making some of our other functions cleaner as well
@@ -70,7 +70,7 @@ console.log([...a, ...b]); // [1, 2, 3, 4] - Merged!
Here's a real-world example. Imagine that you're making a function which accepts an `options` object as argument, but you also want to have default values for this object. Here's a not so good way to do it without spread operator: Here's a real-world example. Imagine that you're making a function which accepts an `options` object as argument, but you also want to have default values for this object. Here's a not so good way to do it without spread operator:
```js ```js
const f = opts => { const f = (opts) => {
const options = {}; const options = {};
options.foo = opts.foo || "default value"; options.foo = opts.foo || "default value";
options.bar = opts.bar || "default value"; options.bar = opts.bar || "default value";
@@ -82,7 +82,7 @@ const f = opts => {
This works, but here's a better way: This works, but here's a better way:
```js ```js
const f = opts => { const f = (opts) => {
const defaults = { const defaults = {
foo: "default value", foo: "default value",
bar: "default value", bar: "default value",
+2 -2
View File
@@ -4,8 +4,8 @@ export const Main = styled.div`
display: flex; display: flex;
width: 100%; width: 100%;
min-height: 100vh; min-height: 100vh;
background: ${props => props.theme.main.background}; background: ${(props) => props.theme.main.background};
color: ${props => props.theme.main.foreground}; color: ${(props) => props.theme.main.foreground};
` `
export const Overlay = styled.div` export const Overlay = styled.div`
+1 -1
View File
@@ -16,7 +16,7 @@ interface IBaseLayout extends IPageContext {
location: WindowLocation location: WindowLocation
} }
const BaseLayout: FC<IBaseLayout> = props => { const BaseLayout: FC<IBaseLayout> = (props) => {
const ResolvedLayout = useMemo(() => { const ResolvedLayout = useMemo(() => {
switch (props.pageContext.layout) { switch (props.pageContext.layout) {
case "resources": case "resources":
+5 -8
View File
@@ -11,10 +11,7 @@ function specificWordsToUpper(str: string): string {
const wordsToUpper = ["pdo", "c"] const wordsToUpper = ["pdo", "c"]
const toUpper = (word: string) => const toUpper = (word: string) =>
wordsToUpper.includes(word.toLowerCase()) ? word.toUpperCase() : word wordsToUpper.includes(word.toLowerCase()) ? word.toUpperCase() : word
return str return str.split(" ").map(toUpper).join(" ")
.split(" ")
.map(toUpper)
.join(" ")
} }
function removeDotMD(str: string): string { function removeDotMD(str: string): string {
@@ -93,7 +90,7 @@ function generateFolder({
path: IFile["path"] path: IFile["path"]
targets: IFolder[] targets: IFolder[]
}): IFolder { }): IFolder {
const children = join(chain(target => target.children, targets)) const children = join(chain((target) => target.children, targets))
const sortedChildren = sort((a, b) => { const sortedChildren = sort((a, b) => {
return a.title.split("/").length > b.title.split("/").length return a.title.split("/").length > b.title.split("/").length
? -1 ? -1
@@ -128,7 +125,7 @@ export function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
} }
const [similarFs, remaining] = partition( const [similarFs, remaining] = partition(
obj => obj.title === head.title && obj.type === head.type, (obj) => obj.title === head.title && obj.type === head.type,
tail tail
) )
const targets = [head, ...similarFs] const targets = [head, ...similarFs]
@@ -148,8 +145,8 @@ export function buildToc(headings: MarkdownRemark["headings"]): ITocItem[] {
} }
return headings return headings
.filter(h => h?.depth === 2) .filter((h) => h?.depth === 2)
.map(h => { .map((h) => {
return { return {
depth: h!.depth!, depth: h!.depth!,
link: `#${kebabCase(h!.value!)}`, link: `#${kebabCase(h!.value!)}`,