aboutsummaryrefslogtreecommitdiff
path: root/src/console/hooks
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-04-04 23:06:00 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-04-05 22:21:33 +0900
commit9041bae89f54efce14239768e642f99d1f0b35d1 (patch)
tree47f6910761b0db63c3afac4dc819f1510b9191a2 /src/console/hooks
parent3a7e55fd292196f600c11fad36425014677a1351 (diff)
Make resize to a custom hook
Diffstat (limited to 'src/console/hooks')
-rw-r--r--src/console/hooks/useAutoResize.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/console/hooks/useAutoResize.ts b/src/console/hooks/useAutoResize.ts
new file mode 100644
index 0000000..4253606
--- /dev/null
+++ b/src/console/hooks/useAutoResize.ts
@@ -0,0 +1,28 @@
+import React from "react";
+import ConsoleFrameClient from "../clients/ConsoleFrameClient";
+
+const useAutoResize = () => {
+ const [prevWidth, setPrevWidth] = React.useState(-1);
+ const [prevHeight, setPrevHeight] = React.useState(-1);
+
+ const consoleFrameClient = React.useMemo(() => {
+ return new ConsoleFrameClient();
+ }, []);
+
+ React.useLayoutEffect(() => {
+ const {
+ scrollWidth: width,
+ scrollHeight: height,
+ } = document.getElementById("vimvixen-console")!;
+ consoleFrameClient.resize(width, height);
+
+ if (width === prevWidth && height === prevHeight) {
+ return;
+ }
+
+ setPrevWidth(width);
+ setPrevHeight(height);
+ });
+};
+
+export default useAutoResize;