diff --git a/src/components/ResourcesList/index.tsx b/src/components/ResourcesList/index.tsx index 72ad9f6..7109ad1 100644 --- a/src/components/ResourcesList/index.tsx +++ b/src/components/ResourcesList/index.tsx @@ -1,42 +1,10 @@ import { graphql, useStaticQuery } from "gatsby" import React, { memo } from "react" import "react-perfect-scrollbar/dist/css/styles.css" +import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types" import * as SC from "./styles" import useBuildTree from "./useBuildTree" -export interface IFile { - title: string - type: "file" - path: string -} - -export interface IFolder { - title: string - type: "folder" - path: string - children: IFileOrFolder[] -} - -export type IFileOrFolder = IFile | IFolder - -export interface IFileQuery { - node: { - relativePath: string - childMarkdownRemark: { - frontmatter: { - author: string - date: string - } - } - } -} - -export interface IAllResourcesQuery { - allFile: { - edges: IFileQuery[] - } -} - const ALL_RESOURCES = graphql` query { allFile(filter: { sourceInstanceName: { eq: "resources" } }) { diff --git a/src/components/ResourcesList/useBuildTree.tsx b/src/components/ResourcesList/useBuildTree.tsx index 5adc513..8a26996 100644 --- a/src/components/ResourcesList/useBuildTree.tsx +++ b/src/components/ResourcesList/useBuildTree.tsx @@ -1,14 +1,14 @@ import chain from "ramda/es/chain" import partition from "ramda/es/partition" -import { traversePathsToFiles } from "../../utils" import { IAllResourcesQuery, IFile, IFileOrFolder, IFileQuery, IFolder, -} from "./index" +} from "../../types" +import { traversePathsToFiles } from "../../utils" function generateFolder({ title, diff --git a/src/components/ResourcesSidebar/index.tsx b/src/components/ResourcesSidebar/index.tsx index 0dca75c..75b82ad 100644 --- a/src/components/ResourcesSidebar/index.tsx +++ b/src/components/ResourcesSidebar/index.tsx @@ -4,44 +4,12 @@ import Scrollbar from "react-perfect-scrollbar" import "react-perfect-scrollbar/dist/css/styles.css" import TriangleDown from "../../icons/triangle-down.svg" import Banner from "../../images/tph-banner.svg" +import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types" import { ThemeToggler } from "../ThemeToggler" import useSidebar from "./../../hooks/useSidebar" import * as SC from "./styles" import useBuildTree from "./useBuildTree" -export interface IFile { - title: string - type: "file" - path: string -} - -export interface IFolder { - title: string - type: "folder" - path: string - children: IFileOrFolder[] -} - -export type IFileOrFolder = IFile | IFolder - -export interface IFileQuery { - node: { - relativePath: string - childMarkdownRemark: { - frontmatter: { - author: string - date: string - } - } - } -} - -export interface IAllResourcesQuery { - allFile: { - edges: IFileQuery[] - } -} - const ALL_RESOURCES = graphql` query { allFile(filter: { sourceInstanceName: { eq: "resources" } }) { diff --git a/src/components/ResourcesSidebar/useBuildTree.tsx b/src/components/ResourcesSidebar/useBuildTree.tsx index b038b2f..0e0b01a 100644 --- a/src/components/ResourcesSidebar/useBuildTree.tsx +++ b/src/components/ResourcesSidebar/useBuildTree.tsx @@ -1,14 +1,14 @@ import chain from "ramda/es/chain" import partition from "ramda/es/partition" -import { traversePaths } from "../../utils" import { IAllResourcesQuery, IFile, IFileOrFolder, IFileQuery, IFolder, -} from "./index" +} from "../../types" +import { traversePaths } from "../../utils" function generateFolder({ title, diff --git a/src/types/index.d.ts b/src/types/index.d.ts new file mode 100644 index 0000000..5d1a69c --- /dev/null +++ b/src/types/index.d.ts @@ -0,0 +1,32 @@ +export interface IFile { + title: string + type: "file" + path: string +} + +export interface IFolder { + title: string + type: "folder" + path: string + children: IFileOrFolder[] +} + +export type IFileOrFolder = IFile | IFolder + +export interface IFileQuery { + node: { + relativePath: string + childMarkdownRemark: { + frontmatter: { + author: string + date: string + } + } + } +} + +export interface IAllResourcesQuery { + allFile: { + edges: IFileQuery[] + } +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 0a9c680..3aced7c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,4 @@ -import { IFile, IFileOrFolder } from "../components/ResourcesSidebar/index" +import { IFileOrFolder } from "../types" export function traversePaths( [head, ...tail]: string[],