-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add edit version of PronunciationsCell (#2615)
Also: Split Pronunciations component into Backend, Frontend components
- Loading branch information
1 parent
feb92ec
commit 4ecb7bd
Showing
24 changed files
with
535 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { memo, ReactElement } from "react"; | ||
|
||
import { getAudioUrl } from "backend"; | ||
import AudioPlayer from "components/Pronunciations/AudioPlayer"; | ||
import AudioRecorder from "components/Pronunciations/AudioRecorder"; | ||
|
||
interface PronunciationsBackendProps { | ||
playerOnly?: boolean; | ||
overrideMemo?: boolean; | ||
pronunciationFiles: string[]; | ||
wordId: string; | ||
deleteAudio: (fileName: string) => void; | ||
uploadAudio?: (audioFile: File) => void; | ||
} | ||
|
||
/** Audio recording/playing component for backend audio. */ | ||
export function PronunciationsBackend( | ||
props: PronunciationsBackendProps | ||
): ReactElement { | ||
if (props.playerOnly && props.uploadAudio) { | ||
console.warn("uploadAudio is defined but unused since playerOnly is true"); | ||
} | ||
if (!props.playerOnly && !props.uploadAudio) { | ||
console.warn("uploadAudio undefined; playerOnly should be set to true"); | ||
} | ||
|
||
const audioButtons: ReactElement[] = props.pronunciationFiles.map( | ||
(fileName) => ( | ||
<AudioPlayer | ||
fileName={fileName} | ||
key={fileName} | ||
pronunciationUrl={getAudioUrl(props.wordId, fileName)} | ||
deleteAudio={props.deleteAudio} | ||
/> | ||
) | ||
); | ||
|
||
return ( | ||
<> | ||
{!props.playerOnly && !!props.uploadAudio && ( | ||
<AudioRecorder wordId={props.wordId} uploadAudio={props.uploadAudio} /> | ||
)} | ||
{audioButtons} | ||
</> | ||
); | ||
} | ||
|
||
// Memoize to decrease unnecessary fetching of audio files. | ||
// https://dmitripavlutin.com/use-react-memo-wisely/#11-custom-equality-check-of-props | ||
function propsAreEqual( | ||
prev: PronunciationsBackendProps, | ||
next: PronunciationsBackendProps | ||
): boolean { | ||
if (next.overrideMemo) { | ||
return false; | ||
} | ||
return ( | ||
prev.wordId === next.wordId && | ||
JSON.stringify(prev.pronunciationFiles) === | ||
JSON.stringify(next.pronunciationFiles) | ||
); | ||
} | ||
|
||
export default memo(PronunciationsBackend, propsAreEqual); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ReactElement } from "react"; | ||
|
||
import AudioPlayer from "components/Pronunciations/AudioPlayer"; | ||
import AudioRecorder from "components/Pronunciations/AudioRecorder"; | ||
|
||
interface PronunciationFrontendProps { | ||
pronunciationFiles: string[]; | ||
elemBetweenRecordAndPlay?: ReactElement; | ||
deleteAudio: (fileName: string) => void; | ||
uploadAudio: (audioFile: File) => void; | ||
} | ||
|
||
/** Audio recording/playing component for audio being recorded and held in the frontend. */ | ||
export default function PronunciationsFrontend( | ||
props: PronunciationFrontendProps | ||
): ReactElement { | ||
const audioButtons: ReactElement[] = props.pronunciationFiles.map( | ||
(fileName) => ( | ||
<AudioPlayer | ||
fileName={fileName} | ||
key={fileName} | ||
pronunciationUrl={fileName} | ||
deleteAudio={props.deleteAudio} | ||
/> | ||
) | ||
); | ||
|
||
return ( | ||
<> | ||
<AudioRecorder wordId={""} uploadAudio={props.uploadAudio} /> | ||
{props.elemBetweenRecordAndPlay} | ||
{audioButtons} | ||
</> | ||
); | ||
} |
Oops, something went wrong.