Skip to content

Commit

Permalink
Fix ref type for AudioPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
davidisaaclee committed Oct 24, 2024
1 parent bd90123 commit c73997a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/ui/src/components/AudioPost.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ElementRef, useCallback, useMemo, useRef } from 'react';
import { useCallback, useMemo, useRef } from 'react';
import { View } from 'tamagui';

import { RenderItemType } from '../contexts/componentsKits';
import { ChatAuthorRow } from './AuthorRow';
import { AudioPlayer } from './Embed/AudioEmbed';
import { AudioPlayer, AudioPlayerHandle } from './Embed/AudioEmbed';
import { convertContent } from './PostContent/contentUtils';

export const AudioPost: RenderItemType = (props) => {
Expand All @@ -15,7 +15,7 @@ export const AudioPost: RenderItemType = (props) => {
return null;
}, [props.post.content]);

const playerRef = useRef<ElementRef<typeof AudioPlayer>>(null);
const playerRef = useRef<AudioPlayerHandle>(null);

const togglePlayback = useCallback(async () => {
const player = playerRef.current;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/components/Embed/AudioEmbed.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { LoadingSpinner } from '../LoadingSpinner';
import * as shared from './AudioEmbedShared';
import { Embed } from './Embed';

export type { AudioPlayerHandle } from './AudioEmbedShared';

const AudioEmbed: shared.AudioEmbed = ({ url }: { url: string }) => {
const [showModal, setShowModal] = useState(false);
const playerRef = useRef<ElementRef<typeof AudioPlayer>>(null);
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/components/Embed/AudioEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { forwardRef } from 'react';

import * as shared from './AudioEmbedShared';

export type { AudioPlayerHandle } from './AudioEmbedShared';

const AudioEmbed: shared.AudioEmbed = ({ url }: { url: string }) => {
// TODO: This is a placeholder for web. Implement a better audio player.

Expand Down
20 changes: 10 additions & 10 deletions packages/ui/src/components/Embed/AudioEmbedShared.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ComponentType, ForwardRefExoticComponent } from 'react';
import { ComponentType, Ref } from 'react';

export type AudioEmbed = ComponentType<{ url: string }>;
export type AudioPlayer = ForwardRefExoticComponent<
{
url: string;
canUnload?: boolean | undefined;
} & React.RefAttributes<{
togglePlayPause: () => Promise<{ isPlaying: boolean }>;
stop: () => void;
}>
>;
export type AudioPlayerHandle = {
togglePlayPause: () => Promise<{ isPlaying: boolean }>;
stop: () => void;
};
export type AudioPlayer = ComponentType<{
url: string;
canUnload?: boolean | undefined;
ref?: Ref<AudioPlayerHandle>;
}>;

0 comments on commit c73997a

Please sign in to comment.