🎥 Make videos programmatically with React
real location
Jonny Burger2d07ca0419cc
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsxindex 365284391e..515b7c22ee 100644--- a/packages/docs/src/components/Demo/Demo.tsx+++ b/packages/docs/src/components/Demo/Demo.tsx@@ -1,11 +1,25 @@import {useColorMode} from '@docusaurus/theme-common';import {Player} from '@remotion/player';-import React from 'react';+import React, {useEffect, useState} from 'react';+import type {Location} from '../../remotion/HomepageVideo/Comp';import {HomepageVideoComp} from '../../remotion/HomepageVideo/Comp';import {ActionRow} from './ActionRow';export const Demo: React.FC = () => {const {colorMode} = useColorMode();+ const [location, setLocation] = useState<Location | null>(null);++ useEffect(() => {+ fetch('https://bugs-git-homepage-player-remotion.vercel.app/api/location')+ .then((res) => res.json())+ .then((data: Location) => {+ setLocation(data);+ })+ .catch((err) => {+ console.error(err);+ });+ }, []);+return (<div><br />@@ -29,6 +43,7 @@ export const Demo: React.FC = () => {}}inputProps={{theme: colorMode,+ location,}}loop/>diff --git a/packages/docs/src/remotion/HomepageVideo/Card.tsx b/packages/docs/src/remotion/HomepageVideo/Card.tsxindex a1b0355383..fc39d0422c 100644--- a/packages/docs/src/remotion/HomepageVideo/Card.tsx+++ b/packages/docs/src/remotion/HomepageVideo/Card.tsx@@ -4,6 +4,7 @@ import {CurrentCountry} from './CurrentCountry';import {Temperature} from './Temperature';import {TrendingRepos} from './TrendingRepos';import styles from './player-styles.module.css';+import type {Location} from './types';export const paddingAndMargin = 20;const height = 360;@@ -297,7 +298,8 @@ export const Cards: React.FC<{readonly onUpdate: (newIndices: number[]) => void;readonly indices: number[];readonly theme: 'dark' | 'light';-}> = ({onUpdate, indices, theme}) => {+ readonly location: Location;+}> = ({onUpdate, indices, theme, location}) => {const [refs] = useState(() => {return new Array(4).fill(true).map(() => {return createRef<HTMLDivElement>();@@ -317,7 +319,7 @@ export const Cards: React.FC<{) : index === 1 ? (<Temperature theme={theme} />) : index === 2 ? (- <CurrentCountry theme={theme} />+ <CurrentCountry location={location} theme={theme} />) : ('🐹');diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsxindex ce37321f39..5b17d620a0 100644--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx@@ -2,14 +2,17 @@ import React, {useCallback, useState} from 'react';import {AbsoluteFill} from 'remotion';import {z} from 'zod';import {Cards} from './Card';+import type {Location} from './types';export const schema = z.object({theme: z.enum(['light', 'dark']),});-export const HomepageVideoComp: React.FC<z.infer<typeof schema>> = ({- theme,-}) => {+export const HomepageVideoComp: React.FC<+ z.infer<typeof schema> & {+ readonly location: Location;+ }+> = ({theme, location}) => {const [state, setRerenders] = useState({rerenders: 0,indices: [0, 1, 2, 3],@@ -22,6 +25,10 @@ export const HomepageVideoComp: React.FC<z.infer<typeof schema>> = ({}));}, []);+ if (!location) {+ return null;+ }+return (<AbsoluteFillstyle={{@@ -33,6 +40,7 @@ export const HomepageVideoComp: React.FC<z.infer<typeof schema>> = ({onUpdate={onUpdate}indices={state.indices}theme={theme}+ location={location}/></AbsoluteFill>);diff --git a/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx b/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsxindex e5ca00ef37..b8340e608c 100644--- a/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx+++ b/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx@@ -2,12 +2,13 @@ import {getBoundingBox, resetPath} from '@remotion/paths';import React from 'react';import {AbsoluteFill} from 'remotion';import {ISO_3166_ALPHA_2_MAPPINGS, countriesPaths} from './paths';+import type {Location} from './types';export const CurrentCountry: React.FC<{readonly theme: 'dark' | 'light';-}> = ({theme}) => {- const country = 'FR';- const paths = countriesPaths.filter((c) => c.class === country);+ readonly location: Location;+}> = ({theme, location}) => {+ const paths = countriesPaths.filter((c) => c.class === location.country);const joined = paths.map((p) => p.d).join(' ');const reset = resetPath(joined);const boundingBox = getBoundingBox(reset);@@ -24,7 +25,6 @@ export const CurrentCountry: React.FC<{<path fill={theme === 'light' ? '#bbb' : '#222'} d={reset} /></svg></AbsoluteFill>- <AbsoluteFill /><AbsoluteFillstyle={{alignItems: 'center',@@ -43,7 +43,7 @@ export const CurrentCountry: React.FC<{marginTop: -10,}}>- Your location+ Your country</div><divstyle={{@@ -55,7 +55,7 @@ export const CurrentCountry: React.FC<{color: theme === 'dark' ? 'white' : 'black',}}>- {ISO_3166_ALPHA_2_MAPPINGS[country]}+ {ISO_3166_ALPHA_2_MAPPINGS[location.country]}</div></AbsoluteFill></AbsoluteFill>diff --git a/packages/docs/src/remotion/HomepageVideo/types.ts b/packages/docs/src/remotion/HomepageVideo/types.tsnew file mode 100644index 0000000000..71e632b6b8--- /dev/null+++ b/packages/docs/src/remotion/HomepageVideo/types.ts@@ -0,0 +1,4 @@+export type Location = {+ country: string;+ city: string;+};