mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
refact: prefer function over lambdas
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import React, { PropsWithChildren } from "react"
|
||||
import * as SC from "./styles"
|
||||
|
||||
const Container = ({
|
||||
function Container({
|
||||
children,
|
||||
...restProps
|
||||
}: PropsWithChildren<{}>): JSX.Element => (
|
||||
<SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper>
|
||||
)
|
||||
}: PropsWithChildren<{}>): JSX.Element {
|
||||
return <SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper>
|
||||
}
|
||||
|
||||
export default Container
|
||||
|
||||
@@ -12,7 +12,7 @@ import DocsSidebar from "../DocsSidebar"
|
||||
import Footer from "../Footer"
|
||||
import * as SC from "./styles"
|
||||
|
||||
const DocsLayout = ({ children }: PropsWithChildren<{}>) => {
|
||||
function DocsLayout({ children }: PropsWithChildren<{}>) {
|
||||
const data = useStaticQuery(graphql`
|
||||
query {
|
||||
site {
|
||||
|
||||
@@ -55,7 +55,7 @@ const ALL_DOCS = graphql`
|
||||
}
|
||||
`
|
||||
|
||||
const plantTree = (item: IFileOrFolder) => {
|
||||
function plantTree(item: IFileOrFolder) {
|
||||
if (item.type === "file") {
|
||||
return (
|
||||
<SC.PageLink to={item.path} activeClassName="active">
|
||||
@@ -84,7 +84,7 @@ function Folder({ item }: { item: IFolder }) {
|
||||
)
|
||||
}
|
||||
|
||||
const DocsSidebar = () => {
|
||||
function DocsSidebar() {
|
||||
const docs = useStaticQuery<IAllDocsQuery>(ALL_DOCS)
|
||||
const tree = useBuildTree(docs)
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
IFileQuery,
|
||||
} from "./index"
|
||||
|
||||
const traverse = (
|
||||
function traverse(
|
||||
[head, ...tail]: string[],
|
||||
basePath = "/docs"
|
||||
): IFileOrFolder => {
|
||||
): IFileOrFolder {
|
||||
const path = basePath + "/" + head
|
||||
const isFile = !tail.length
|
||||
if (isFile) {
|
||||
@@ -30,7 +30,7 @@ const traverse = (
|
||||
}
|
||||
}
|
||||
|
||||
const generateFolder = ({
|
||||
function generateFolder({
|
||||
title,
|
||||
path,
|
||||
targets,
|
||||
@@ -38,7 +38,7 @@ const generateFolder = ({
|
||||
title: IFolder["title"]
|
||||
path: IFile["path"]
|
||||
targets: IFolder[]
|
||||
}): IFolder => {
|
||||
}): IFolder {
|
||||
const children = join(R.chain(target => target.children, targets))
|
||||
|
||||
return {
|
||||
@@ -49,13 +49,13 @@ const generateFolder = ({
|
||||
}
|
||||
}
|
||||
|
||||
const generateFile = ({
|
||||
function generateFile({
|
||||
title,
|
||||
path,
|
||||
}: {
|
||||
title: IFile["title"]
|
||||
path: IFile["path"]
|
||||
}): IFile => {
|
||||
}): IFile {
|
||||
return {
|
||||
title,
|
||||
path,
|
||||
@@ -63,7 +63,7 @@ const generateFile = ({
|
||||
}
|
||||
}
|
||||
|
||||
const join = ([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] => {
|
||||
function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
|
||||
if (!head) return []
|
||||
|
||||
const [similarFs, remaining] = R.partition(
|
||||
|
||||
@@ -5,10 +5,10 @@ export interface DocsSidebarSectionProps {
|
||||
readonly title: string
|
||||
}
|
||||
|
||||
const DocsSidebarSection = ({
|
||||
function DocsSidebarSection({
|
||||
title,
|
||||
children,
|
||||
}: PropsWithChildren<DocsSidebarSectionProps>) => {
|
||||
}: PropsWithChildren<DocsSidebarSectionProps>) {
|
||||
return (
|
||||
<div>
|
||||
<SC.SidebarTitle>{title}</SC.SidebarTitle>
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from "react"
|
||||
import * as SC from "./styles"
|
||||
import Container from "../Container"
|
||||
|
||||
const Footer = () => {
|
||||
function Footer() {
|
||||
return (
|
||||
<SC.FooterWrapper>
|
||||
<Container>
|
||||
|
||||
@@ -16,7 +16,7 @@ import * as SC from "./styles"
|
||||
import Scrollbar from "react-perfect-scrollbar"
|
||||
import "react-perfect-scrollbar/dist/css/styles.css"
|
||||
|
||||
const Layout = ({ children }: PropsWithChildren<{}>) => {
|
||||
function Layout({ children }: PropsWithChildren<{}>) {
|
||||
const data = useStaticQuery(graphql`
|
||||
query {
|
||||
site {
|
||||
|
||||
@@ -10,13 +10,13 @@ interface SEOProps {
|
||||
readonly title: string
|
||||
}
|
||||
|
||||
const SEO = ({
|
||||
function SEO({
|
||||
description,
|
||||
lang = "en",
|
||||
meta = [],
|
||||
keywords = [],
|
||||
title,
|
||||
}: SEOProps) => {
|
||||
}: SEOProps) {
|
||||
const { site } = useStaticQuery(
|
||||
graphql`
|
||||
query {
|
||||
|
||||
@@ -11,7 +11,7 @@ function MenuItem({ children, to }: PropsWithChildren<{ to: string }>) {
|
||||
)
|
||||
}
|
||||
|
||||
const Sidebar = () => {
|
||||
function Sidebar() {
|
||||
return (
|
||||
<SC.SidebarWrapper>
|
||||
<SC.Logo src={logo} />
|
||||
|
||||
+9
-7
@@ -3,12 +3,14 @@ import React from "react"
|
||||
import Layout from "../components/Layout"
|
||||
import SEO from "../components/SEO"
|
||||
|
||||
const NotFoundPage = () => (
|
||||
<Layout>
|
||||
<SEO title="404: Not found" />
|
||||
<h1>NOT FOUND</h1>
|
||||
<p>You just hit a route that doesn't exist... the sadness.</p>
|
||||
</Layout>
|
||||
)
|
||||
function NotFoundPage() {
|
||||
return (
|
||||
<Layout>
|
||||
<SEO title="404: Not found" />
|
||||
<h1>NOT FOUND</h1>
|
||||
<p>You just hit a route that doesn't exist... the sadness.</p>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export default NotFoundPage
|
||||
|
||||
+8
-6
@@ -3,11 +3,13 @@ import React from "react"
|
||||
import DocsLayout from "../components/DocsLayout"
|
||||
import SEO from "../components/SEO"
|
||||
|
||||
const DocsPage = () => (
|
||||
<DocsLayout>
|
||||
<SEO title="Docs" />
|
||||
the docs
|
||||
</DocsLayout>
|
||||
)
|
||||
function DocsPage() {
|
||||
return (
|
||||
<DocsLayout>
|
||||
<SEO title="Docs" />
|
||||
the docs
|
||||
</DocsLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export default DocsPage
|
||||
|
||||
+12
-10
@@ -4,15 +4,17 @@ import { Link } from "gatsby"
|
||||
import Layout from "../components/Layout"
|
||||
import SEO from "../components/SEO"
|
||||
|
||||
const IndexPage = () => (
|
||||
<Layout>
|
||||
<SEO title="Home" />
|
||||
<h1>Hi people</h1>
|
||||
<p>Welcome to your new Gatsby site.</p>
|
||||
<p>Now go build something great.</p>
|
||||
<div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}></div>
|
||||
<Link to="/page-2/">Go to page 2</Link>
|
||||
</Layout>
|
||||
)
|
||||
function IndexPage() {
|
||||
return (
|
||||
<Layout>
|
||||
<SEO title="Home" />
|
||||
<h1>Hi people</h1>
|
||||
<p>Welcome to your new Gatsby site.</p>
|
||||
<p>Now go build something great.</p>
|
||||
<div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}></div>
|
||||
<Link to="/page-2/">Go to page 2</Link>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export default IndexPage
|
||||
|
||||
@@ -4,7 +4,7 @@ import SEO from "../components/SEO"
|
||||
import DocsLayout from "../components/DocsLayout"
|
||||
|
||||
// @todo maybe find alternative type for data
|
||||
const LanguagePost = ({ data }: any) => {
|
||||
function LanguagePost({ data }: any) {
|
||||
const { html, frontmatter } = data.file.post
|
||||
console.log(data)
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user