Skip to content

Commit 02ebbe8

Browse files
committed
Reduce rerenders in the metadata tab
This patch rewrites the Metadata component. This accomplishes: - Stop the whole Metadata component from rerendering each time redux state is updated. This was causing ui elements to become unresponsive in certain cases (e.g. having tens of thousands of series in your Opencast). - Makes the code in the Metadata component far less difficult to read.
1 parent 9cced82 commit 02ebbe8

9 files changed

Lines changed: 478 additions & 640 deletions

File tree

src/cssStyles.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ type MyOptionType = {
171171
value: string;
172172
};
173173

174-
type IsMulti = false;
175-
176-
export function selectFieldStyle(theme: Theme): StylesConfig<MyOptionType, IsMulti> {
174+
export function selectFieldStyle<IsMulti extends boolean, >(theme: Theme): StylesConfig<MyOptionType, IsMulti> {
177175
return {
178176
control: (provided, state) => ({
179177
...provided,

src/main/Cutting.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { LuMoveHorizontal } from "react-icons/lu";
3030
import { css } from "@emotion/react";
3131
import VideoPlayers from "./VideoPlayers";
3232
import VideoControls from "./VideoControls";
33+
import { fetchMetadata, selectGetStatus as selectMetadataGetStatus } from "../redux/metadataSlice";
3334

3435
const Cutting: React.FC = () => {
3536

@@ -45,6 +46,7 @@ const Cutting: React.FC = () => {
4546
const theme = useTheme();
4647
const errorReason = useAppSelector((state: { videoState: { errorReason: httpRequestState["errorReason"]; }; }) =>
4748
state.videoState.errorReason);
49+
const metadataGetStatus = useAppSelector(selectMetadataGetStatus);
4850

4951
// Try to fetch URL from external API
5052
useEffect(() => {
@@ -76,6 +78,13 @@ const Cutting: React.FC = () => {
7678
}
7779
}, [videoURLStatus, dispatch, error, t, errorReason, duration]);
7880

81+
// Already try fetching Metadata to reduce wait time
82+
useEffect(() => {
83+
if (metadataGetStatus === "idle") {
84+
dispatch(fetchMetadata());
85+
}
86+
}, [metadataGetStatus, dispatch]);
87+
7988
// Style
8089
const cuttingStyle = css({
8190
display: "flex",

0 commit comments

Comments
 (0)