Skip to content

🎥 Make videos programmatically with React

default rotation

Jonny Burger22da2b143aa8
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index e92ae9bd39..55896a1d18 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -11,7 +11,11 @@ import {webFileReader} from '@remotion/media-parser/web-file';
import {convertMedia, ConvertMediaContainer} from '@remotion/webcodecs';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ConvertState, Source} from '~/lib/convert-state';
-import {isConvertEnabledByDefault} from '~/lib/default-ui';
+import {
+ defaultRotateOrMirorState,
+ isConvertEnabledByDefault,
+ RotateOrMirrorState,
+} from '~/lib/default-ui';
import {isDroppingEverything, isReencoding} from '~/lib/is-reencoding';
import {RouteAction} from '~/seo';
import {ConversionDone} from './ConversionDone';
@@ -60,9 +64,8 @@ export default function ConvertUI({
const [enableConvert, setEnableConvert] = useState(() =>
isConvertEnabledByDefault(action),
);
- const [enableRotateOrMirrow, setEnableRotateOrMirror] = useState<
- 'rotate' | 'mirror' | null
- >(null);
+ const [enableRotateOrMirrow, setEnableRotateOrMirror] =
+ useState<RotateOrMirrorState>(() => defaultRotateOrMirorState(action));
const [rotation, setRotation] = useState(90);
diff --git a/packages/convert/app/lib/default-ui.ts b/packages/convert/app/lib/default-ui.ts
index c51ee8b515..4a5f1444c3 100644
--- a/packages/convert/app/lib/default-ui.ts
+++ b/packages/convert/app/lib/default-ui.ts
@@ -1,5 +1,27 @@
import {RouteAction} from '~/seo';
+export type RotateOrMirrorState = 'rotate' | 'mirror' | null;
+
+export const defaultRotateOrMirorState = (
+ action: RouteAction,
+): RotateOrMirrorState => {
+ if (action.type === 'convert') {
+ return null;
+ }
+
+ if (action.type === 'generic-convert') {
+ return null;
+ }
+
+ if (action.type === 'generic-rotate') {
+ return 'rotate';
+ }
+
+ throw new Error(
+ 'Rotate is not enabled by default ' + (action satisfies never),
+ );
+};
+
export const isConvertEnabledByDefault = (action: RouteAction) => {
if (action.type === 'convert') {
return true;