Skip to content

Commit

Permalink
fix up missing recording buttons in sm layout (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee committed Mar 29, 2024
1 parent 2e061fc commit e777a8e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion enjoy/src/renderer/components/audios/audio-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const AudioPlayer = (props: { id?: string; md5?: string }) => {

<div className={`${layout.lowerWrapper} flex flex-col`}>
<div className={`${layout.playerWrapper} py-2 px-6`}>
<MediaCurrentRecording height={layout.playerHeight} />
<MediaCurrentRecording />
</div>

<div className={`${layout.playerWrapper} py-2 px-6`}>
Expand Down
33 changes: 27 additions & 6 deletions enjoy/src/renderer/components/medias/media-current-recording.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import { t } from "i18next";
import { formatDuration } from "@renderer/lib/utils";
import { useHotkeys } from "react-hotkeys-hook";

export const MediaCurrentRecording = (props: { height?: number }) => {
const { height } = props;
export const MediaCurrentRecording = () => {
const {
layout,
isRecording,
Expand Down Expand Up @@ -238,11 +237,12 @@ export const MediaCurrentRecording = (props: { height?: number }) => {
if (!ref.current) return;
if (isRecording) return;
if (!currentRecording?.src) return;
if (!layout?.playerHeight) return;

const ws = WaveSurfer.create({
container: ref.current,
url: currentRecording.src,
height,
height: layout.playerHeight,
barWidth: 2,
cursorWidth: 1,
autoCenter: true,
Expand Down Expand Up @@ -288,7 +288,7 @@ export const MediaCurrentRecording = (props: { height?: number }) => {
return () => {
ws?.destroy();
};
}, [ref, currentRecording, isRecording, height]);
}, [ref, currentRecording, isRecording, layout?.playerHeight]);

useEffect(() => {
setIsComparing(false);
Expand Down Expand Up @@ -406,7 +406,7 @@ export const MediaCurrentRecording = (props: { height?: number }) => {
[player]
);

if (isRecording) return <MediaRecorder height={height} />;
if (isRecording) return <MediaRecorder />;
if (!currentRecording?.src)
return (
<div className="h-full w-full flex items-center space-x-4">
Expand Down Expand Up @@ -477,7 +477,7 @@ export const MediaCurrentRecording = (props: { height?: number }) => {
/>

{
height >= 192 && <>
layout?.name === 'lg' && <>
<Button
variant={isComparing ? "secondary" : "outline"}
size="icon"
Expand Down Expand Up @@ -516,6 +516,27 @@ export const MediaCurrentRecording = (props: { height?: number }) => {
</DropdownMenuTrigger>

<DropdownMenuContent>
{
layout?.name === 'sm' && (
<>
<DropdownMenuItem
className="cursor-pointer"
onClick={toggleCompare}
>
<GitCompareIcon className="w-4 h-4 mr-4" />
<span>{t("compare")}</span>
</DropdownMenuItem>

<DropdownMenuItem
className="cursor-pointer"
onClick={() => setIsSelectingRegion(!isSelectingRegion)}
>
<TextCursorInputIcon className="w-4 h-4 mr-4" />
<span>{t("selectRegion")}</span>
</DropdownMenuItem>
</>
)
}
<DropdownMenuItem
className="cursor-pointer"
onClick={() => setDetailIsOpen(true)}
Expand Down
11 changes: 6 additions & 5 deletions enjoy/src/renderer/components/medias/media-recorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { toast } from "@renderer/components/ui";
import { MediaRecordButton } from "@renderer/components";
import { FFMPEG_CONVERT_WAV_OPTIONS } from "@/constants";

export const MediaRecorder = (props: { height?: number }) => {
const { height = 192 } = props;
export const MediaRecorder = () => {
const {
layout,
media,
isRecording,
setIsRecording,
Expand Down Expand Up @@ -80,11 +80,12 @@ export const MediaRecorder = (props: { height?: number }) => {
if (!access) return;
if (!isRecording) return;
if (!ref.current) return;
if (!layout?.playerHeight) return;

const ws = WaveSurfer.create({
container: ref.current,
fillParent: true,
height,
height: layout.playerHeight,
autoCenter: false,
normalize: false,
});
Expand Down Expand Up @@ -123,9 +124,9 @@ export const MediaRecorder = (props: { height?: number }) => {
return () => {
clearInterval(interval);
record.stopRecording();
ws.destroy();
ws?.destroy();
};
}, [ref, isRecording, access]);
}, [ref, isRecording, access, layout?.playerHeight]);

useEffect(() => {
askForMediaAccess();
Expand Down
2 changes: 1 addition & 1 deletion enjoy/src/renderer/components/videos/video-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const VideoPlayer = (props: { id?: string; md5?: string }) => {

<div className={`${layout.lowerWrapper} flex flex-col`}>
<div className={`${layout.playerWrapper} py-2 px-6`}>
<MediaCurrentRecording height={layout.playerHeight} />
<MediaCurrentRecording />
</div>

<div className={`${layout.playerWrapper} py-2 px-6`}>
Expand Down

0 comments on commit e777a8e

Please sign in to comment.