From bae6487afd5e6eec9f04b38b235bbac24042ca62 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 6 Oct 2021 13:17:43 +0200 Subject: feat: filter dailes (#68) --- pages/index.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'pages/index.tsx') diff --git a/pages/index.tsx b/pages/index.tsx index 4f01de8..a40f942 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -89,6 +89,7 @@ export function GraphPage() { const linksByNodeIdRef = useRef({}) const tagsRef = useRef([]) const graphRef = useRef(null) + const variablesRef = useRef<{ [variable: string]: string }>({}) const currentGraphDataRef = useRef({ nodes: [], links: [] }) @@ -358,6 +359,10 @@ export function GraphPage() { switch (message.type) { case 'graphdata': return updateGraphData(message.data) + case 'variables': + variablesRef.current = message.data + console.log(message.data) + return case 'theme': return setEmacsTheme(['custom', message.data]) case 'command': @@ -432,6 +437,7 @@ export function GraphPage() { nodeById={nodeByIdRef.current!} linksByNodeId={linksByNodeIdRef.current!} webSocket={WebSocketRef.current} + variables={variablesRef.current} {...{ physics, graphData, @@ -466,6 +472,7 @@ export interface GraphProps { setScope: any webSocket: any tagColors: { [tag: string]: string } + variables: { [variable: string]: string } } export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { @@ -484,8 +491,10 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { setScope, webSocket, tagColors, + variables, } = props + const { dailyDir, roamDir } = variables // react-force-graph does not track window size // https://github.com/vasturiano/react-force-graph/issues/233 // does not work below a certain width @@ -605,14 +614,14 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { const node = nodeArg as OrgRoamNode if ( filter.tagsBlacklist.length && - filter.tagsBlacklist.some((tag) => node.tags.indexOf(tag) > -1) + filter.tagsBlacklist.some((tag) => node?.tags?.indexOf(tag) > -1) ) { hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } return false } if ( filter.tagsWhitelist.length > 0 && - !filter.tagsWhitelist.some((tag) => node.tags.indexOf(tag) > -1) + !filter.tagsWhitelist.some((tag) => node?.tags?.indexOf(tag) > -1) ) { hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } return false @@ -625,6 +634,11 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } return false } + + if (filter.dailies && dailyDir?.length !== 0 && node.file.includes(dailyDir)) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false + } return true }) .filter((node) => { -- cgit v1.2.3