Skip to content

Commit 6889d60

Browse files
committed
Commit: Add userStyle to Graph component and useUserStyle to getTheme
1 parent 90b3d3d commit 6889d60

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

app/src/components/Graph.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { cytoscape } from "../lib/cytoscape";
2020
import { getDoc, setMetaImmer, subscribeToDoc } from "../lib/docHelpers";
2121
import { getGetSize, TGetSize } from "../lib/getGetSize";
2222
import { getLayout } from "../lib/getLayout";
23-
import { getUserStyle } from "../lib/getTheme";
23+
import { getUserStyle, useUserStyle } from "../lib/getTheme";
2424
import { DEFAULT_GRAPH_PADDING } from "../lib/graphOptions";
2525
import {
2626
useBackgroundColor,
@@ -67,6 +67,7 @@ export default function Graph({ shouldResize }: { shouldResize: number }) {
6767
const themeKey = useThemeKey();
6868
const theme = useCurrentTheme(themeKey) as unknown as Theme;
6969
const bg = useBackgroundColor(theme);
70+
const userStyle = useUserStyle();
7071

7172
const getSize = useRef<TGetSize>(getGetSize(theme));
7273
const parser = useParser();
@@ -115,8 +116,8 @@ export default function Graph({ shouldResize }: { shouldResize: number }) {
115116

116117
// Apply theme
117118
useEffect(() => {
118-
getStyleUpdater({ cy, errorCatcher, bg })(theme);
119-
}, [bg, theme]);
119+
getStyleUpdater({ cy, errorCatcher, bg, userStyle })(theme);
120+
}, [bg, theme, userStyle]);
120121

121122
const throttleUpdate = useMemo(
122123
() =>
@@ -316,17 +317,18 @@ function getStyleUpdater({
316317
cy,
317318
errorCatcher,
318319
bg,
320+
userStyle = [],
319321
}: {
320322
cy: React.MutableRefObject<cytoscape.Core | undefined>;
321323
errorCatcher: React.MutableRefObject<cytoscape.Core | undefined>;
322324
bg?: string;
325+
userStyle: cytoscape.StylesheetStyle[];
323326
}) {
324327
return throttle((theme: Theme) => {
325328
if (!cy.current) return;
326329
if (!errorCatcher.current) return;
327330
try {
328-
// Prepare Styles
329-
const style = buildStylesForGraph(theme, getUserStyle(), bg);
331+
const style = buildStylesForGraph(theme, userStyle, bg);
330332

331333
// Test Error First
332334
errorCatcher.current.json({ style });

app/src/lib/getTheme.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StylesheetStyle } from "cytoscape";
22

3-
import { getDoc } from "./docHelpers";
3+
import { getDoc, useDocMeta } from "./docHelpers";
44

55
/**
66
* Get the user style from the document metadata.
@@ -9,6 +9,6 @@ export function getUserStyle() {
99
return (getDoc().meta?.style ?? []) as StylesheetStyle[];
1010
}
1111

12-
// const theme = useGraphTheme(options.graphOptions.theme);
13-
// That's how we're currently grabbing the theme from the name
14-
// Believe it does some async loading behind the scenes
12+
export function useUserStyle() {
13+
return (useDocMeta().style ?? []) as StylesheetStyle[];
14+
}

0 commit comments

Comments
 (0)