Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More small screen responsiveness #1160

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/cssStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import React from "react";
import emotionNormalize from "emotion-normalize";
import { createTheme } from "@mui/material/styles";
import { Theme, useTheme } from "./themes";
import {
DEFAULT_CONFIG as APPKIT_CONFIG,
} from "@opencast/appkit";
import { StylesConfig } from "react-select";

/**
Expand Down Expand Up @@ -35,8 +38,8 @@ export const globalStyle = (theme: Theme) => css({


// When to switch behaviour based on screen width
export const BREAKPOINT_SMALL = 450;
export const BREAKPOINT_MEDIUM = 650;
/** Breakpoint values */
export const BREAKPOINTS = APPKIT_CONFIG.breakpoints;

/**
* CSS for buttons
Expand Down Expand Up @@ -433,3 +436,9 @@ export const backgroundBoxStyle = (theme: Theme) => css(({
padding: "20px",
gap: "25px",
}));

export const undisplay = (maxWidth: number) => css({
[`@media (max-width: ${maxWidth}px)`]: {
display: "none",
},
});
55 changes: 55 additions & 0 deletions src/img/opencast-editor-narrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/main/CuttingActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { basicButtonStyle, customIconStyle } from "../cssStyles";
import { BREAKPOINTS, basicButtonStyle, customIconStyle, undisplay } from "../cssStyles";

import { IconType } from "react-icons";
import { LuScissors, LuChevronLeft, LuChevronRight, LuTrash, LuMoveHorizontal } from "react-icons/lu";
Expand Down Expand Up @@ -110,6 +110,8 @@ const CuttingActions: React.FC = () => {
flexDirection: "row" as const,
justifyContent: "center",
alignItems: "center",

flexWrap: "wrap",
});

const verticalLineStyle = css({
Expand Down Expand Up @@ -246,7 +248,7 @@ const CuttingActionsButton: React.FC<cuttingActionsButtonInterface> = ({
}}
>
<Icon />
<span>{actionName}</span>
<span css={undisplay(BREAKPOINTS.medium)}>{actionName}</span>
</div>
</ThemedTooltip>
);
Expand Down Expand Up @@ -291,8 +293,10 @@ const MarkAsDeletedButton: React.FC<markAsDeleteButtonInterface> = ({
}
}}
>
{isCurrentSegmentAlive ? <LuTrash /> : <TrashRestore css={customIconStyle} />}
<div>{isCurrentSegmentAlive ? t("cuttingActions.delete-button") : t("cuttingActions.restore-button")}</div>
{isCurrentSegmentAlive ? <LuTrash /> : <TrashRestore css={customIconStyle} /> }
<span css={undisplay(BREAKPOINTS.medium)}>
{isCurrentSegmentAlive ? t("cuttingActions.delete-button") : t("cuttingActions.restore-button")}
</span>
</div>
</ThemedTooltip>
);
Expand Down
27 changes: 18 additions & 9 deletions src/main/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@
import { HiOutlineTranslate } from "react-icons/hi";
import { LuKeyboard } from "react-icons/lu";
import { MainMenuStateNames } from "../types";
import { basicButtonStyle, BREAKPOINT_MEDIUM, BREAKPOINT_SMALL } from "../cssStyles";
import { basicButtonStyle, BREAKPOINTS, undisplay } from "../cssStyles";

import { selectIsEnd } from "../redux/endSlice";
import { checkboxMenuItem, HeaderMenuItemDef, ProtoButton, useColorScheme, WithHeaderMenu } from "@opencast/appkit";
import {
checkboxMenuItem,
HeaderMenuItemDef,
ProtoButton,
screenWidthAtMost,
useColorScheme,
WithHeaderMenu,
} from "@opencast/appkit";
import { IconType } from "react-icons";
import i18next from "i18next";
import useWindowDimensions from "../util/utilityFunctions";
import { languages as lngs } from "../i18n/lngs-generated";

function Header() {
Expand Down Expand Up @@ -68,6 +76,10 @@
backgroundColor: theme.header_button_hover_bg,
color: `${theme.header_text}`,
},

[screenWidthAtMost(BREAKPOINTS.medium)]: {
fontSize: 0,
},
});

return (
Expand Down Expand Up @@ -112,6 +124,7 @@

const { t } = useTranslation();
const { scheme } = useColorScheme();
const { width } = useWindowDimensions();

Check warning on line 127 in src/main/Header.tsx

View workflow job for this annotation

GitHub Actions / test

'width' is assigned a value but never used. Allowed unused vars must match /^_/u

const logo = css({
paddingLeft: "8px",
Expand Down Expand Up @@ -184,7 +197,7 @@
menu={{
label,
items: menuItems,
breakpoint: BREAKPOINT_SMALL,
breakpoint: BREAKPOINTS.small,
}}
>
<HeaderButton Icon={HiOutlineTranslate} label={label} />
Expand All @@ -210,7 +223,7 @@
menu={{
label: t("theme.appearance"),
items: menuItems,
breakpoint: BREAKPOINT_MEDIUM,
breakpoint: BREAKPOINTS.medium,
}}>
<HeaderButton
Icon={scheme === "light" || scheme === "light-high-contrast" ? LuMoon : LuSun}
Expand Down Expand Up @@ -268,11 +281,7 @@
css={[basicButtonStyle(theme), themeSelectorButtonStyle]}
>
<Icon css={iconStyle} />
<span css={{
[`@media (max-width: ${BREAKPOINT_MEDIUM}px)`]: {
display: "none",
},
}}>{label}</span>
<span css={undisplay(BREAKPOINTS.medium)}>{label}</span>
</ProtoButton>
);
});
Expand Down
22 changes: 19 additions & 3 deletions src/main/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setPageNumber } from "../redux/finishSlice";

import { MainMenuStateNames } from "../types";
import { settings } from "../config";
import { basicButtonStyle } from "../cssStyles";
import { basicButtonStyle, BREAKPOINTS } from "../cssStyles";
import { setIsPlaying } from "../redux/videoSlice";

import { useTranslation } from "react-i18next";
Expand All @@ -22,6 +22,7 @@ import { resetPostRequestState } from "../redux/workflowPostSlice";
import { setIsDisplayEditView } from "../redux/subtitleSlice";

import { useTheme } from "../themes";
import { screenWidthAtMost } from "@opencast/appkit";

/**
* A container for selecting the functionality shown in the main part of the app
Expand All @@ -43,6 +44,10 @@ const MainMenu: React.FC = () => {
overflowY: "auto",
background: `${theme.menu_background}`,
gap: "30px",
[screenWidthAtMost(BREAKPOINTS.large)]: {
minWidth: "60px",
padding: "20px 10px",
},
});

return (
Expand Down Expand Up @@ -144,6 +149,10 @@ export const MainMenuButton: React.FC<mainMenuButtonInterface> = ({
boxShadow: `${theme.boxShadow}`,
},
flexDirection: "column",
[screenWidthAtMost(BREAKPOINTS.large)]: {
height: "60px",
minHeight: "40px",
},
});

return (
Expand All @@ -161,8 +170,15 @@ export const MainMenuButton: React.FC<mainMenuButtonInterface> = ({
fontSize: 36,
width: "36px",
height: "auto",
}} />
{bottomText && <div>{bottomText}</div>}
}}/>
{bottomText &&
<div css={{
[screenWidthAtMost(BREAKPOINTS.large)]: {
display: "none",
},
}}>
{bottomText}
</div>}
</li>
);
};
Expand Down
9 changes: 8 additions & 1 deletion src/main/Metadata.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from "react";

import { css } from "@emotion/react";
import { calendarStyle, errorBoxStyle, selectFieldStyle, titleStyle, titleStyleBold } from "../cssStyles";
import { BREAKPOINTS, calendarStyle, errorBoxStyle, selectFieldStyle, titleStyle, titleStyleBold } from "../cssStyles";

import { useAppDispatch, useAppSelector } from "../redux/store";
import {
Expand Down Expand Up @@ -30,6 +30,7 @@ import { useTheme } from "../themes";
import { ThemeProvider } from "@mui/material/styles";
import { cloneDeep } from "lodash";
import { ParseKeys } from "i18next";
import { screenWidthAtMost } from "@opencast/appkit";

/**
* Creates a Metadata form
Expand Down Expand Up @@ -101,6 +102,12 @@ const Metadata: React.FC = () => {
marginRight: "auto",
minWidth: "50%",
display: "grid",
[screenWidthAtMost(1550)]: {
minWidth: "70%",
},
[screenWidthAtMost(BREAKPOINTS.medium)]: {
minWidth: "90%",
},
});

const catalogStyle = css({
Expand Down
11 changes: 6 additions & 5 deletions src/main/VideoControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../redux/videoSlice";

import { convertMsToReadableString } from "../util/utilityFunctions";
import { basicButtonStyle } from "../cssStyles";
import { BREAKPOINTS, basicButtonStyle, undisplay } from "../cssStyles";

import { KEYMAP, rewriteKeys } from "../globalKeys";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -175,8 +175,9 @@ const PreviewMode: React.FC<{
if (event.key === " ") {
switchPlayPreview(undefined);
}
}}>
<div css={previewModeTextStyle(theme)}>
}}
>
<div css={[previewModeTextStyle(theme), undisplay(BREAKPOINTS.medium)]}>
{t("video.previewButton")}
</div>
{isPlayPreview ? <FaToggleOn css={[basicButtonStyle(theme), switchIconStyle]} />
Expand Down Expand Up @@ -360,9 +361,9 @@ const TimeDisplay: React.FC<{
{new Date((currentlyAt ? currentlyAt : 0)).toISOString().substr(11, 10)}
</time>
</ThemedTooltip>
{" / "}
<div css={undisplay(BREAKPOINTS.medium)}>{" / "}</div>
<ThemedTooltip title={t("video.time-duration-tooltip")}>
<div css={timeTextStyle(theme)}
<div css={[timeTextStyle(theme), undisplay(BREAKPOINTS.medium)]}
tabIndex={0} aria-label={t("video.duration-aria") + ": " + convertMsToReadableString(duration)}>
{new Date((duration ? duration : 0)).toISOString().substr(11, 10)}
</div>
Expand Down
32 changes: 31 additions & 1 deletion src/util/utilityFunctions.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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/
Expand Down
Loading