Skip to content

Commit

Permalink
Implement the previous button
Browse files Browse the repository at this point in the history
  • Loading branch information
demccormack committed Oct 23, 2023
1 parent cdf7635 commit 1cf7867
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suspense, useState } from 'react';
import { Suspense, useRef, useState } from 'react';
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import axios from 'axios';

Expand All @@ -18,12 +18,16 @@ function App() {
const videoSource = queue[queuePosition];

const addToQueue = (url: string) => setQueue((prev) => [...prev, url]);
const skipToNext = () => setQueuePosition((prev) => ++prev % queue.length);
const skipToPrevious = () =>
setQueuePosition((prev) => (prev - 1 < 0 ? queue.length - 1 : prev - 1));
const skipToNext = () =>
setQueuePosition((prev) => (prev + 1) % queue.length);

return (
<div className="h-screen text-gray-400">
<MainPanel
videoSource={videoSource}
skipToPrevious={skipToPrevious}
skipToNext={skipToNext}
/>
<SideBar
Expand All @@ -36,15 +40,31 @@ function App() {

function MainPanel({
videoSource,
skipToPrevious,
skipToNext,
}: {
videoSource: string;
skipToPrevious: () => void;
skipToNext: () => void;
}) {
const videoRef = useRef<HTMLVideoElement | null>(null);

const onPreviousClick = () => {
if (videoRef.current === null) return;
const currentTime = videoRef.current.currentTime;

if (currentTime < 5) {
skipToPrevious();
} else {
videoRef.current.currentTime = 0;
}
};

return (
<main className="fixed right-0 w-3/4 text-center">
<h1 className="p-10 text-4xl font-bold">Pi Player</h1>
<video
ref={videoRef}
className="m-auto w-7/12 border-4 border-gray-400"
src={`${MEDIA_ROOT}${videoSource}`}
onEnded={skipToNext}
Expand All @@ -54,7 +74,10 @@ function MainPanel({
Video should play here
</video>
<div className="flex justify-center gap-32 pt-10 text-6xl">
<button className="h-12 w-12 overflow-hidden rounded-full">
<button
className="h-12 w-12 overflow-hidden rounded-full"
onClick={onPreviousClick}
>
<div className="-ml-2 -mt-1.5"></div>
</button>
<button
Expand Down

0 comments on commit 1cf7867

Please sign in to comment.