+ }}
+ >
+
{t("video.previewButton")}
{isPlayPreview ?
@@ -360,9 +361,9 @@ const TimeDisplay: React.FC<{
{new Date((currentlyAt ? currentlyAt : 0)).toISOString().substr(11, 10)}
- {" / "}
+
{" / "}
-
{new Date((duration ? duration : 0)).toISOString().substr(11, 10)}
diff --git a/src/util/utilityFunctions.ts b/src/util/utilityFunctions.ts
index 7bb075953..ed0d86288 100644
--- a/src/util/utilityFunctions.ts
+++ b/src/util/utilityFunctions.ts
@@ -1,7 +1,7 @@
import { nanoid } from "@reduxjs/toolkit";
import { WebVTTParser, WebVTTSerializer } from "webvtt-parser";
import { ExtendedSubtitleCue, SubtitleCue } from "../types";
-import { useEffect, useRef } from "react";
+import { useEffect, useState, useRef } from "react";
export const roundToDecimalPlace = (num: number, decimalPlace: number) => {
const decimalFactor = Math.pow(10, decimalPlace);
@@ -149,6 +149,36 @@ export function languageCodeToName(lang: string | undefined): string | undefined
}
}
+/**
+ * @returns the current window width and height
+ */
+function getWindowDimensions() {
+ const { innerWidth: width, innerHeight: height } = window;
+ return {
+ width,
+ height,
+ };
+}
+
+/**
+ * A hook for window dimensions
+ */
+export default function useWindowDimensions() {
+ const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
+
+ useEffect(() => {
+ function handleResize() {
+ setWindowDimensions(getWindowDimensions());
+ }
+
+ window.addEventListener("resize", handleResize);
+ return () => window.removeEventListener("resize", handleResize);
+ }, []);
+
+ return windowDimensions;
+
+}
+
// Runs a callback every delay milliseconds
// Pass delay = null to stop
// Based off: https://overreacted.io/making-setinterval-declarative-with-react-hooks/