From 6807e961188edae98b46ca503ec950c6b421db17 Mon Sep 17 00:00:00 2001 From: Oliver Roick Date: Fri, 15 Nov 2024 13:58:03 +1100 Subject: [PATCH] Use ResizeOberver to fit size of terminal --- src/ImageBuilder.jsx | 42 +++++++++++++++++++++++----------- src/components/form/fields.jsx | 9 ++++---- src/form.css | 18 +-------------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/ImageBuilder.jsx b/src/ImageBuilder.jsx index f98b3a1..b773cb1 100644 --- a/src/ImageBuilder.jsx +++ b/src/ImageBuilder.jsx @@ -54,7 +54,10 @@ async function buildImage(repo, ref, term, fitAddon) { function ImageLogs({ setTerm, setFitAddon, name }) { const terminalId = `${name}--terminal`; + const observedElementRef = useRef(null); + useEffect(() => { + let observer; async function setup() { const { Terminal } = await import("xterm"); const { FitAddon } = await import("xterm-addon-fit"); @@ -75,12 +78,24 @@ function ImageLogs({ setTerm, setFitAddon, name }) { setTerm(term); setFitAddon(fitAddon); term.write("Logs will appear here when image is being built"); + + if (observedElementRef.current) { + observer = new ResizeObserver(() => { + console.log("resize"); + fitAddon.fit(); + }); + observer.observe(observedElementRef.current); + } } setup(); + + return () => { + if (observer) observer.disconnect(); + } }, []); return ( -
+
); @@ -147,21 +162,22 @@ export function ImageBuilder({ name, isActive }) { // don't generate the hidden input that posts the built image out. return ( <> -
-
- Provider +
+
+
Provider
-
GitHub
+
GitHub
-
- +
+
-
+
{}} // Hack to prevent a console error, while at the same time allowing for this field to be validatable, ie. not making it read-only /> -
-
- Build Logs +
+
+
Build Logs
-
+
{customImageError && (
diff --git a/src/components/form/fields.jsx b/src/components/form/fields.jsx index 741db52..421b251 100644 --- a/src/components/form/fields.jsx +++ b/src/components/form/fields.jsx @@ -21,11 +21,11 @@ function validateField(value, validateConfig, touched) { function Field({ id, label, hint, children, error }) { return ( -
-
- +
+
+
-
+
{children} {error &&
{error}
} {hint &&
{hint}
} @@ -88,6 +88,7 @@ function _TextField( return (