Clean up unused codes
This commit is contained in:
parent
f1fb9e26e2
commit
08bf40fc35
25
lib/hooks.js
25
lib/hooks.js
@ -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
|
|
||||||
}
|
|
@ -5,7 +5,6 @@ module.exports = {
|
|||||||
fs: false,
|
fs: false,
|
||||||
buffer: false
|
buffer: false
|
||||||
};
|
};
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
import Layout, {siteTitle} from "../components/layout";
|
import Layout from "../components/layout";
|
||||||
import {getSinglePost, getGraphData, getDirectoryData, convertObject, getFlattenArray} from "../lib/utils";
|
import {getSinglePost, getDirectoryData, convertObject, getFlattenArray} from "../lib/utils";
|
||||||
import FolderTree from "../components/FolderTree";
|
import FolderTree from "../components/FolderTree";
|
||||||
import Alert from '@mui/material/Alert';
|
import Alert from '@mui/material/Alert';
|
||||||
import AlertTitle from '@mui/material/AlertTitle';
|
import AlertTitle from '@mui/material/AlertTitle';
|
||||||
|
|
||||||
export default function Home({content, graphdata, filenames, tree, flattenNodes, ...props}) {
|
export default function Home({content, tree, flattenNodes}) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout home>
|
<Layout home>
|
||||||
@ -28,12 +28,10 @@ export default function Home({content, graphdata, filenames, tree, flattenNodes,
|
|||||||
export function getStaticProps() {
|
export function getStaticProps() {
|
||||||
const tree = convertObject(getDirectoryData());
|
const tree = convertObject(getDirectoryData());
|
||||||
const contentData = getSinglePost("index");
|
const contentData = getSinglePost("index");
|
||||||
const graphdata = getGraphData();
|
|
||||||
const flattenNodes = getFlattenArray(tree)
|
const flattenNodes = getFlattenArray(tree)
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
content: contentData,
|
content: contentData,
|
||||||
graphdata: graphdata,
|
|
||||||
tree: tree,
|
tree: tree,
|
||||||
flattenNodes: flattenNodes
|
flattenNodes: flattenNodes
|
||||||
},
|
},
|
||||||
|
@ -1,60 +1,12 @@
|
|||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from 'next/link'
|
import Layout from "../../components/layout";
|
||||||
import { useRouter } from 'next/router'
|
|
||||||
import { useEffect,useRef } from "react";
|
|
||||||
import Layout, { siteTitle } from "../../components/layout";
|
|
||||||
import {getPostListData, getSinglePost, getGraphData, convertObject, getDirectoryData} from "../../lib/utils";
|
import {getPostListData, getSinglePost, getGraphData, convertObject, getDirectoryData} from "../../lib/utils";
|
||||||
import { Network } from "../../components/graph";
|
|
||||||
import FolderTree from "../../components/FolderTree";
|
import FolderTree from "../../components/FolderTree";
|
||||||
import {getFlattenArray} from "../../lib/utils";
|
import {getFlattenArray} from "../../lib/utils";
|
||||||
import Alert from '@mui/material/Alert';
|
import Alert from '@mui/material/Alert';
|
||||||
import AlertTitle from '@mui/material/AlertTitle';
|
import AlertTitle from '@mui/material/AlertTitle';
|
||||||
|
|
||||||
export default function Home({ note, graphdata,tree, flattenNodes, ...props }) {
|
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 (
|
return (
|
||||||
<Layout home>
|
<Layout home>
|
||||||
<Head>
|
<Head>
|
||||||
@ -72,34 +24,25 @@ export default function Home({ note, graphdata,tree, flattenNodes, ...props }) {
|
|||||||
<div dangerouslySetInnerHTML={{__html: note.data}}/>
|
<div dangerouslySetInnerHTML={{__html: note.data}}/>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const allPostsData = await getPostListData();
|
const allPostsData = getPostListData();
|
||||||
const paths = allPostsData.map(p => ({params: {id:p}}))
|
const paths = allPostsData.map(p => ({params: {id:p}}))
|
||||||
//console.log("paths", paths)
|
|
||||||
return {
|
return {
|
||||||
paths,
|
paths,
|
||||||
fallback:false
|
fallback:false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export async function getStaticProps({ params }) {
|
export async function getStaticProps({ params }) {
|
||||||
console.log("params1", params.id)
|
const note = getSinglePost(params.id);
|
||||||
const note = await getSinglePost(params.id);
|
|
||||||
//console.log("params2", note)
|
|
||||||
const graphdata = getGraphData();
|
|
||||||
//console.log("params3", params)
|
|
||||||
const tree = convertObject(getDirectoryData());
|
const tree = convertObject(getDirectoryData());
|
||||||
const flattenNodes = getFlattenArray(tree)
|
const flattenNodes = getFlattenArray(tree)
|
||||||
//console.log("note: ", params)
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
note,
|
note,
|
||||||
graphdata:graphdata,
|
|
||||||
tree: tree,
|
tree: tree,
|
||||||
flattenNodes: flattenNodes
|
flattenNodes: flattenNodes
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user