From dad03e3be5b0a7c1159e0207cce11540ca830359 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Mon, 3 Jan 2022 17:21:18 +0100 Subject: feat(filter): add option to filter by subdirectory (#190) --- pages/index.tsx | 321 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 174 insertions(+), 147 deletions(-) (limited to 'pages/index.tsx') diff --git a/pages/index.tsx b/pages/index.tsx index cf54e92..9b21f7b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -56,6 +56,7 @@ import { usePersistantState } from '../util/persistant-state' import { ThemeContext, ThemeContextProps } from '../util/themecontext' import { openNodeInEmacs } from '../util/webSocketFunctions' import { drawLabels } from '../components/Graph/drawLabels' +import { VariablesContext } from '../util/variablesContext' const d3promise = import('d3-force-3d') @@ -78,6 +79,7 @@ export interface EmacsVariables { dailyDir?: string katexMacros?: { [key: string]: string } attachDir?: string + subDirs: string[] } export type Tags = string[] export type Scope = { @@ -144,7 +146,7 @@ export function GraphPage() { const nodeByCiteRef = useRef({}) const tagsRef = useRef([]) const graphRef = useRef(null) - const variablesRef = useRef({}) + const [emacsVariables, setEmacsVariables] = useState({} as EmacsVariables) const clusterRef = useRef<{ [id: string]: number }>({}) const currentGraphDataRef = useRef({ nodes: [], links: [] }) @@ -433,8 +435,8 @@ export function GraphPage() { case 'graphdata': return updateGraphData(message.data) case 'variables': - variablesRef.current = message.data - console.log(message.data) + setEmacsVariables(message.data) + console.log(message) return case 'theme': return setEmacsTheme(['custom', message.data]) @@ -545,160 +547,169 @@ export function GraphPage() { windowWidth, ) + console.log(emacsVariables) return ( - - - - {graphData && ( - - )} - - - - - {/* - * - * {mainItem.icon} - * - * {mainItem.title} - * */} - - {scope.nodeIds.length > 0 && ( - + + + + + {graphData && ( + + )} + + + + + {/* + * + * {mainItem.icon} + * + * {mainItem.title} + * */} + + {scope.nodeIds.length > 0 && ( + + } + aria-label="Exit local mode" + onClick={() => + setScope((currentScope: Scope) => ({ + ...currentScope, + nodeIds: [], + })) + } + variant="subtle" + /> + + )} + } - aria-label="Exit local mode" - onClick={() => - setScope((currentScope: Scope) => ({ - ...currentScope, - nodeIds: [], - })) - } + // eslint-disable-next-line react/jsx-no-undef + icon={} + aria-label="Close file-viewer" variant="subtle" + onClick={isOpen ? onClose : onOpen} /> - )} - - } - aria-label="Close file-viewer" - variant="subtle" - onClick={isOpen ? onClose : onOpen} - /> - + - - + - - - - {contextMenu.isOpen && ( -
- + -
- )} - + + {contextMenu.isOpen && ( +
+ +
+ )} + + ) } @@ -842,6 +853,22 @@ export const Graph = function (props: GraphProps) { const filteredNodes = graphData?.nodes ?.filter((nodeArg) => { const node = nodeArg as OrgRoamNode + //dirs + if ( + filter.dirsBlocklist.length && + filter.dirsBlocklist.some((dir) => node?.file?.includes(dir)) + ) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false + } + if ( + filter.dirsAllowlist.length > 0 && + !filter.dirsAllowlist.some((dir) => node?.file?.includes(dir)) + ) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false + } + if ( filter.tagsBlacklist.length && filter.tagsBlacklist.some((tag) => node?.tags?.indexOf(tag) > -1) -- cgit v1.2.3