Clean up unused codes

This commit is contained in:
Tuan Cao 2022-03-31 15:12:00 +07:00
parent f1fb9e26e2
commit 08bf40fc35
4 changed files with 7 additions and 92 deletions

View File

@ -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
}

View File

@ -5,7 +5,6 @@ module.exports = {
fs: false,
buffer: false
};
return config;
},
}

View File

@ -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 (
<Layout home>
@ -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
},

View File

@ -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) => (
<div className="backlink-box">
<Link href={data.id === "index" ? "/" : `/note/${data.id}`}>
<a>
{data.title ? data.title : data.id}
</a>
</Link>
</div>
)
//sideBox
}
},[])
return (
<Layout home>
<Head>
@ -72,34 +24,25 @@ export default function Home({ note, graphdata,tree, flattenNodes, ...props }) {
<div dangerouslySetInnerHTML={{__html: note.data}}/>
</main>
</div>
</Layout>
);
}
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
},