File tree Expand file tree Collapse file tree 7 files changed +118
-14
lines changed
01.solution.vite-plugin/app
02.solution.loader-rsc/app
03.solution.rsc-route/app
04.solution.server-fns/app
05.solution.use-client/app Expand file tree Collapse file tree 7 files changed +118
-14
lines changed Original file line number Diff line number Diff line change 1- import { Activity , useState } from 'react'
1+ import { Activity , useEffect , useState } from 'react'
22import { type Movie } from '#app/movies-data.ts'
33
44export function MovieTrailer ( { movie } : { movie : Movie } ) {
55 const [ showTrailer , setShowTrailer ] = useState ( false )
6+ useAutoplay ( showTrailer )
67
78 return (
89 < div className = "mb-6" >
@@ -18,7 +19,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
1819 src = { movie . videoUrl }
1920 title = { movie . title }
2021 autoPlay
21- muted
2222 loop
2323 controls
2424 />
@@ -27,3 +27,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2727 </ div >
2828 )
2929}
30+
31+ function useAutoplay ( showTrailer : boolean ) {
32+ useEffect ( ( ) => {
33+ const video = document . querySelector ( 'video' )
34+ if ( ! ( video instanceof HTMLVideoElement ) ) return
35+ if ( ! showTrailer ) {
36+ void video . pause ( )
37+ return
38+ }
39+
40+ video . volume = 1
41+ void video . play ( )
42+ return ( ) => {
43+ void video . pause ( )
44+ }
45+ } , [ showTrailer ] )
46+ }
Original file line number Diff line number Diff line change 1- // import { unstable_reactRouterRSC as reactRouterRSC } from '@react-router/dev/vite'
2- import { reactRouter } from '@react-router/dev/vite'
1+ import {
2+ reactRouter ,
3+ // unstable_reactRouterRSC as reactRouterRSC,
4+ } from '@react-router/dev/vite'
35import tailwindcss from '@tailwindcss/vite'
46// import rsc from '@vitejs/plugin-rsc'
57import { defineConfig } from 'vite'
Original file line number Diff line number Diff line change 1- import { Activity , useState } from 'react'
1+ import { Activity , useEffect , useState } from 'react'
22import { type Movie } from '#app/movies-data.ts'
33
44export function MovieTrailer ( { movie } : { movie : Movie } ) {
55 const [ showTrailer , setShowTrailer ] = useState ( false )
6+ useAutoplay ( showTrailer )
67
78 return (
89 < div className = "mb-6" >
@@ -18,7 +19,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
1819 src = { movie . videoUrl }
1920 title = { movie . title }
2021 autoPlay
21- muted
2222 loop
2323 controls
2424 />
@@ -27,3 +27,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2727 </ div >
2828 )
2929}
30+
31+ function useAutoplay ( showTrailer : boolean ) {
32+ useEffect ( ( ) => {
33+ const video = document . querySelector ( 'video' )
34+ if ( ! ( video instanceof HTMLVideoElement ) ) return
35+ if ( ! showTrailer ) {
36+ void video . pause ( )
37+ return
38+ }
39+
40+ video . volume = 1
41+ void video . play ( )
42+ return ( ) => {
43+ void video . pause ( )
44+ }
45+ } , [ showTrailer ] )
46+ }
Original file line number Diff line number Diff line change 1- import { Activity , useState } from 'react'
1+ import { Activity , useEffect , useState } from 'react'
22import { type Movie } from '#app/movies-data.ts'
33
44export function MovieTrailer ( { movie } : { movie : Movie } ) {
55 const [ showTrailer , setShowTrailer ] = useState ( false )
6+ useAutoplay ( showTrailer )
67
78 return (
89 < div className = "mb-6" >
@@ -18,7 +19,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
1819 src = { movie . videoUrl }
1920 title = { movie . title }
2021 autoPlay
21- muted
2222 loop
2323 controls
2424 />
@@ -27,3 +27,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2727 </ div >
2828 )
2929}
30+
31+ function useAutoplay ( showTrailer : boolean ) {
32+ useEffect ( ( ) => {
33+ const video = document . querySelector ( 'video' )
34+ if ( ! ( video instanceof HTMLVideoElement ) ) return
35+ if ( ! showTrailer ) {
36+ void video . pause ( )
37+ return
38+ }
39+
40+ video . volume = 1
41+ void video . play ( )
42+ return ( ) => {
43+ void video . pause ( )
44+ }
45+ } , [ showTrailer ] )
46+ }
Original file line number Diff line number Diff line change 1- import { Activity , useState } from 'react'
1+ import { Activity , useEffect , useState } from 'react'
22import { type Movie } from '#app/movies-data.ts'
33
44export function MovieTrailer ( { movie } : { movie : Movie } ) {
55 const [ showTrailer , setShowTrailer ] = useState ( false )
6+ useAutoplay ( showTrailer )
67
78 return (
89 < div className = "mb-6" >
@@ -18,7 +19,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
1819 src = { movie . videoUrl }
1920 title = { movie . title }
2021 autoPlay
21- muted
2222 loop
2323 controls
2424 />
@@ -27,3 +27,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2727 </ div >
2828 )
2929}
30+
31+ function useAutoplay ( showTrailer : boolean ) {
32+ useEffect ( ( ) => {
33+ const video = document . querySelector ( 'video' )
34+ if ( ! ( video instanceof HTMLVideoElement ) ) return
35+ if ( ! showTrailer ) {
36+ void video . pause ( )
37+ return
38+ }
39+
40+ video . volume = 1
41+ void video . play ( )
42+ return ( ) => {
43+ void video . pause ( )
44+ }
45+ } , [ showTrailer ] )
46+ }
Original file line number Diff line number Diff line change 1- import { Activity , useState } from 'react'
1+ import { Activity , useEffect , useState } from 'react'
22import { type Movie } from '#app/movies-data.ts'
33
44export function MovieTrailer ( { movie } : { movie : Movie } ) {
55 const [ showTrailer , setShowTrailer ] = useState ( false )
6+ useAutoplay ( showTrailer )
67
78 return (
89 < div className = "mb-6" >
@@ -18,7 +19,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
1819 src = { movie . videoUrl }
1920 title = { movie . title }
2021 autoPlay
21- muted
2222 loop
2323 controls
2424 />
@@ -27,3 +27,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2727 </ div >
2828 )
2929}
30+
31+ function useAutoplay ( showTrailer : boolean ) {
32+ useEffect ( ( ) => {
33+ const video = document . querySelector ( 'video' )
34+ if ( ! ( video instanceof HTMLVideoElement ) ) return
35+ if ( ! showTrailer ) {
36+ void video . pause ( )
37+ return
38+ }
39+
40+ video . volume = 1
41+ void video . play ( )
42+ return ( ) => {
43+ void video . pause ( )
44+ }
45+ } , [ showTrailer ] )
46+ }
Original file line number Diff line number Diff line change 11'use client'
22
3- import { Activity , useState } from 'react'
3+ import { Activity , useEffect , useState } from 'react'
44import { type Movie } from '#app/movies-data.ts'
55
66export function MovieTrailer ( { movie } : { movie : Movie } ) {
77 const [ showTrailer , setShowTrailer ] = useState ( false )
8+ useAutoplay ( showTrailer )
89
910 return (
1011 < div className = "mb-6" >
@@ -20,7 +21,6 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2021 src = { movie . videoUrl }
2122 title = { movie . title }
2223 autoPlay
23- muted
2424 loop
2525 controls
2626 />
@@ -29,3 +29,20 @@ export function MovieTrailer({ movie }: { movie: Movie }) {
2929 </ div >
3030 )
3131}
32+
33+ function useAutoplay ( showTrailer : boolean ) {
34+ useEffect ( ( ) => {
35+ const video = document . querySelector ( 'video' )
36+ if ( ! ( video instanceof HTMLVideoElement ) ) return
37+ if ( ! showTrailer ) {
38+ void video . pause ( )
39+ return
40+ }
41+
42+ video . volume = 1
43+ void video . play ( )
44+ return ( ) => {
45+ void video . pause ( )
46+ }
47+ } , [ showTrailer ] )
48+ }
You can’t perform that action at this time.
0 commit comments