Skip to content

Commit

Permalink
refactor(progress): fix typescript error
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Jan 8, 2023
1 parent f67cc88 commit d25e2db
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/components/progress.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useRef } from "react";
import React, { useCallback } from "react";
import { ReactComponent as IconLoading } from "../assets/loading.svg";

type ProgressBarProps = {
Expand All @@ -15,30 +15,24 @@ export function ProgressBar({
playedPercentage,
onSeek,
}: ProgressBarProps) {
const wrapperRef = useRef<HTMLDivElement>(null);

const handleMouseDown = useCallback(
(e: React.MouseEvent) => {
const barDimensions = wrapperRef.current?.getBoundingClientRect();
(e: React.MouseEvent<HTMLDivElement>) => {
const barDimensions = e.currentTarget.getBoundingClientRect();
const deltaX = e.clientX - barDimensions.x;
const percentage = deltaX / barDimensions?.width;
const percentage = deltaX / barDimensions.width;

onSeek?.(percentage);
},
[onSeek]
);

return (
<div
ref={wrapperRef}
className="aplayer-bar-wrap"
onMouseDown={handleMouseDown}
>
<div className="aplayer-bar-wrap" onMouseDown={handleMouseDown}>
<div className="aplayer-bar">
<div
className="aplayer-loaded"
style={{ width: `${bufferedPercentage * 100}%` }}
></div>
/>
<div
className="aplayer-played"
style={{
Expand Down

0 comments on commit d25e2db

Please sign in to comment.