Skip to content

Commit 24ebb0d

Browse files
wip
1 parent 96eda2f commit 24ebb0d

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import { getSplitContentLines, type DiffFile } from "@git-diff-view/core";
2-
import { createSignal } from "solid-js";
1+
import { getSplitContentLines } from "@git-diff-view/core";
2+
import { createMemo, createSignal } from "solid-js";
3+
4+
import { useFontSize } from "../hooks";
5+
6+
import type { DiffFile, SplitSide } from "@git-diff-view/core";
37

48
export const DiffSplitViewWrap = (props: { diffFile: DiffFile }) => {
5-
const [] = createSignal(getSplitContentLines(props.diffFile));
9+
const [lines, setLines] = createSignal(getSplitContentLines(props.diffFile));
10+
11+
const [maxText, setMaxText] = createSignal(props.diffFile.splitLineLength.toString());
12+
13+
const [splitSideInfo, setSplitInfo] = createSignal<{ side?: SplitSide }>({ side: undefined });
614

7-
const [] = createSignal(props.diffFile.splitLineLength.toString());
15+
const fontSize = useFontSize();
816

9-
17+
const font = createMemo(() => ({ fontSize: `${fontSize() || 14}px`, fontFamily: "Menlo, Consolas, monospace" }));
1018

1119
return <div>12</div>;
1220
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createEffect, createSignal, onCleanup, useContext } from "solid-js";
2+
3+
import { DiffViewContext } from "../components/DiffViewContext";
4+
5+
import type { createDiffConfigStore } from "../components/tools";
6+
7+
type AllKey = keyof ReturnType<ReturnType<typeof createDiffConfigStore>["getReadonlyState"]>;
8+
9+
type Data = ReturnType<ReturnType<typeof createDiffConfigStore>["getReadonlyState"]>;
10+
11+
export const generateHook = <T extends AllKey, K extends Data[T] = Data[T]>(key: T) => {
12+
return () => {
13+
const reactiveHook = useContext(DiffViewContext);
14+
15+
const [state, setState] = createSignal<K>(reactiveHook?.getReadonlyState()[key] as K);
16+
17+
createEffect(() => {
18+
const unsubscribe = reactiveHook?.subscribe(
19+
(s) => s[key],
20+
() => {
21+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22+
// @ts-expect-error
23+
setState(reactiveHook?.getReadonlyState()[key]);
24+
}
25+
);
26+
27+
onCleanup(() => unsubscribe?.());
28+
});
29+
30+
return state;
31+
};
32+
};

packages/solid/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./useEnableWrap";
2+
export * from "./useFontSize";
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
import { createEffect, createSignal, onCleanup, useContext } from "solid-js";
1+
import { generateHook } from "./generate";
22

3-
import { DiffViewContext } from "../components/DiffViewContext";
4-
5-
export const useEnableWrap = () => {
6-
const reactiveHook = useContext(DiffViewContext);
7-
8-
const [enableWrap, setEnableWrap] = createSignal(reactiveHook?.getReadonlyState().enableWrap);
9-
10-
createEffect(() => {
11-
const unsubscribe = reactiveHook?.subscribe(
12-
(s) => s.enableWrap,
13-
() => {
14-
setEnableWrap(reactiveHook.getReadonlyState().enableWrap);
15-
}
16-
);
17-
18-
onCleanup(() => unsubscribe?.());
19-
});
20-
21-
return enableWrap;
22-
};
3+
export const useEnableWrap = generateHook("enableWrap");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { generateHook } from "./generate";
2+
3+
export const useFontSize = generateHook("fontSize");

0 commit comments

Comments
 (0)