From 08bf40fc35d4890ed55a9360e1fd78a8dd377558 Mon Sep 17 00:00:00 2001 From: Tuan Cao Date: Thu, 31 Mar 2022 15:12:00 +0700 Subject: [PATCH] Clean up unused codes --- lib/hooks.js | 25 ------------------ next.config.js | 1 - pages/index.js | 8 +++--- pages/note/[id].js | 65 +++------------------------------------------- 4 files changed, 7 insertions(+), 92 deletions(-) delete mode 100644 lib/hooks.js diff --git a/lib/hooks.js b/lib/hooks.js deleted file mode 100644 index 26fdc64..0000000 --- a/lib/hooks.js +++ /dev/null @@ -1,25 +0,0 @@ -import React, { useState, useEffect, useRef } from "react"; - -export function useWindowWidth() { - const [screenSize, setScreenSize] = useState(window.innerWidth)// S | M | L - - const screenListener = () => { - const currentSize = window.innerWidth; - //if size (not width) is changed, then change state - if (screenSize != currentSize) { - setScreenSize(currentSize); - } - } - - useEffect(() => { - // Once screenSize changed this will be fired - window.addEventListener("resize", screenListener); - // for removing repeatedly rendering - return () => { - window.removeEventListener("resize", screenListener); - } - }) - - - return screenSize - } \ No newline at end of file diff --git a/next.config.js b/next.config.js index 07dcf26..6694928 100644 --- a/next.config.js +++ b/next.config.js @@ -5,7 +5,6 @@ module.exports = { fs: false, buffer: false }; - return config; }, } \ No newline at end of file diff --git a/pages/index.js b/pages/index.js index 719f0de..998a399 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,10 +1,10 @@ -import Layout, {siteTitle} from "../components/layout"; -import {getSinglePost, getGraphData, getDirectoryData, convertObject, getFlattenArray} from "../lib/utils"; +import Layout from "../components/layout"; +import {getSinglePost, getDirectoryData, convertObject, getFlattenArray} from "../lib/utils"; import FolderTree from "../components/FolderTree"; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; -export default function Home({content, graphdata, filenames, tree, flattenNodes, ...props}) { +export default function Home({content, tree, flattenNodes}) { return ( @@ -28,12 +28,10 @@ export default function Home({content, graphdata, filenames, tree, flattenNodes, export function getStaticProps() { const tree = convertObject(getDirectoryData()); const contentData = getSinglePost("index"); - const graphdata = getGraphData(); const flattenNodes = getFlattenArray(tree) return { props: { content: contentData, - graphdata: graphdata, tree: tree, flattenNodes: flattenNodes }, diff --git a/pages/note/[id].js b/pages/note/[id].js index 4174489..1f82227 100644 --- a/pages/note/[id].js +++ b/pages/note/[id].js @@ -1,60 +1,12 @@ import Head from "next/head"; -import Link from 'next/link' -import { useRouter } from 'next/router' -import { useEffect,useRef } from "react"; -import Layout, { siteTitle } from "../../components/layout"; +import Layout from "../../components/layout"; import {getPostListData, getSinglePost, getGraphData, convertObject, getDirectoryData} from "../../lib/utils"; -import { Network } from "../../components/graph"; import FolderTree from "../../components/FolderTree"; import {getFlattenArray} from "../../lib/utils"; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; export default function Home({ note, graphdata,tree, flattenNodes, ...props }) { - var jsnx = require('jsnetworkx'); - - //console.log("Note Page: ") - //console.log("Index Page Props: ", props /* backlinks, filenames*/) - - const backlinks = graphdata.filter(g => g.data.target === note.id) - - const ref = useRef(null); - const router = useRouter() - const routeQuery = router.query.id - const routeHandler = (r) => router.push(r) - //console.log("route", router) - - var G; - useEffect(() => { - if (ref && ref.current){ - G = Network({ - el:ref.current, - graphdata, - current:note.id, - routeHandler, - allNodes:false - }) - } -}, [routeQuery]) - - useEffect(() => { - if (backlinks.length > 0){ - const sideBox = document.getElementById("side-graph-box"); - const Backlink = (data) => ( -
- - - {data.title ? data.title : data.id} - - -
- ) - - //sideBox - } - },[]) - - return ( @@ -72,34 +24,25 @@ export default function Home({ note, graphdata,tree, flattenNodes, ...props }) {
- - -
); } export async function getStaticPaths() { - const allPostsData = await getPostListData(); + const allPostsData = getPostListData(); const paths = allPostsData.map(p => ({params: {id:p}})) - //console.log("paths", paths) return { paths, fallback:false }; } export async function getStaticProps({ params }) { - console.log("params1", params.id) - const note = await getSinglePost(params.id); - //console.log("params2", note) - const graphdata = getGraphData(); - //console.log("params3", params) + const note = getSinglePost(params.id); const tree = convertObject(getDirectoryData()); const flattenNodes = getFlattenArray(tree) - //console.log("note: ", params) + return { props: { note, - graphdata:graphdata, tree: tree, flattenNodes: flattenNodes },