mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-07 07:56:12 +02:00
refact: extract duplicated File/Folder types
This commit is contained in:
@@ -1,42 +1,10 @@
|
|||||||
import { graphql, useStaticQuery } from "gatsby"
|
import { graphql, useStaticQuery } from "gatsby"
|
||||||
import React, { memo } from "react"
|
import React, { memo } from "react"
|
||||||
import "react-perfect-scrollbar/dist/css/styles.css"
|
import "react-perfect-scrollbar/dist/css/styles.css"
|
||||||
|
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
import useBuildTree from "./useBuildTree"
|
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`
|
const ALL_RESOURCES = graphql`
|
||||||
query {
|
query {
|
||||||
allFile(filter: { sourceInstanceName: { eq: "resources" } }) {
|
allFile(filter: { sourceInstanceName: { eq: "resources" } }) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import chain from "ramda/es/chain"
|
import chain from "ramda/es/chain"
|
||||||
import partition from "ramda/es/partition"
|
import partition from "ramda/es/partition"
|
||||||
|
|
||||||
import { traversePathsToFiles } from "../../utils"
|
|
||||||
import {
|
import {
|
||||||
IAllResourcesQuery,
|
IAllResourcesQuery,
|
||||||
IFile,
|
IFile,
|
||||||
IFileOrFolder,
|
IFileOrFolder,
|
||||||
IFileQuery,
|
IFileQuery,
|
||||||
IFolder,
|
IFolder,
|
||||||
} from "./index"
|
} from "../../types"
|
||||||
|
import { traversePathsToFiles } from "../../utils"
|
||||||
|
|
||||||
function generateFolder({
|
function generateFolder({
|
||||||
title,
|
title,
|
||||||
|
|||||||
@@ -4,44 +4,12 @@ import Scrollbar from "react-perfect-scrollbar"
|
|||||||
import "react-perfect-scrollbar/dist/css/styles.css"
|
import "react-perfect-scrollbar/dist/css/styles.css"
|
||||||
import TriangleDown from "../../icons/triangle-down.svg"
|
import TriangleDown from "../../icons/triangle-down.svg"
|
||||||
import Banner from "../../images/tph-banner.svg"
|
import Banner from "../../images/tph-banner.svg"
|
||||||
|
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
||||||
import { ThemeToggler } from "../ThemeToggler"
|
import { ThemeToggler } from "../ThemeToggler"
|
||||||
import useSidebar from "./../../hooks/useSidebar"
|
import useSidebar from "./../../hooks/useSidebar"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
import useBuildTree from "./useBuildTree"
|
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`
|
const ALL_RESOURCES = graphql`
|
||||||
query {
|
query {
|
||||||
allFile(filter: { sourceInstanceName: { eq: "resources" } }) {
|
allFile(filter: { sourceInstanceName: { eq: "resources" } }) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import chain from "ramda/es/chain"
|
import chain from "ramda/es/chain"
|
||||||
import partition from "ramda/es/partition"
|
import partition from "ramda/es/partition"
|
||||||
|
|
||||||
import { traversePaths } from "../../utils"
|
|
||||||
import {
|
import {
|
||||||
IAllResourcesQuery,
|
IAllResourcesQuery,
|
||||||
IFile,
|
IFile,
|
||||||
IFileOrFolder,
|
IFileOrFolder,
|
||||||
IFileQuery,
|
IFileQuery,
|
||||||
IFolder,
|
IFolder,
|
||||||
} from "./index"
|
} from "../../types"
|
||||||
|
import { traversePaths } from "../../utils"
|
||||||
|
|
||||||
function generateFolder({
|
function generateFolder({
|
||||||
title,
|
title,
|
||||||
|
|||||||
Vendored
+32
@@ -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[]
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { IFile, IFileOrFolder } from "../components/ResourcesSidebar/index"
|
import { IFileOrFolder } from "../types"
|
||||||
|
|
||||||
export function traversePaths(
|
export function traversePaths(
|
||||||
[head, ...tail]: string[],
|
[head, ...tail]: string[],
|
||||||
|
|||||||
Reference in New Issue
Block a user