-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from NEU-DSG/cm/audio-ux
Clean up contributor audio user experience
- Loading branch information
Showing
12 changed files
with
483 additions
and
367 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
79 changes: 79 additions & 0 deletions
79
website/src/components/edit-word-audio/contributor-audio-panel.tsx
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,79 @@ | ||
import cx from "classnames" | ||
import { ReactElement, ReactNode } from "react" | ||
import { IconType } from "react-icons" | ||
import * as Dailp from "src/graphql/dailp" | ||
import { CollapsiblePanel } from "src/panel-layout" | ||
import * as css from "../../panel-layout.css" | ||
import { | ||
contributeAudioContainer, | ||
statusMessage, | ||
statusMessageError, | ||
} from "./contributor.css" | ||
import { useAudioUpload } from "./utils" | ||
|
||
export function ContributeAudioPanel(p: { | ||
panelTitle: string | ||
Icon: IconType | ||
Component: ContributeAudioComponent | ||
word: Dailp.FormFieldsFragment | ||
}) { | ||
return ( | ||
<CollapsiblePanel | ||
title={p.panelTitle} | ||
content={<ContributeAudioSection word={p.word} Component={p.Component} />} | ||
icon={<p.Icon size={24} className={css.wordPanelButton.colpleft} />} | ||
/> | ||
) | ||
} | ||
|
||
type ContributeAudioComponent = (p: { | ||
uploadAudio: (blob: Blob) => Promise<boolean> | ||
}) => ReactElement | ||
|
||
/** | ||
* This wrapper component provides upload functionality and feedback for an | ||
* audio contribution component. | ||
*/ | ||
function ContributeAudioSection(p: { | ||
word: Dailp.FormFieldsFragment | ||
Component: ContributeAudioComponent | ||
}): ReactElement { | ||
const [uploadAudio, uploadState, clearUploadError] = useAudioUpload(p.word.id) | ||
|
||
return ( | ||
<div className={contributeAudioContainer}> | ||
<p.Component uploadAudio={uploadAudio} /> | ||
|
||
{uploadState === "uploading" && ( | ||
<StatusMessage> | ||
<p>Uploading...</p> | ||
</StatusMessage> | ||
)} | ||
|
||
{uploadState === "error" && ( | ||
<StatusMessage error> | ||
<p> | ||
Something went wrong with the upload{" "} | ||
<button onClick={() => clearUploadError()}>Try again</button> | ||
</p> | ||
</StatusMessage> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
function StatusMessage({ | ||
children, | ||
error = false, | ||
}: { | ||
children: ReactNode | ||
error?: boolean | ||
}) { | ||
return ( | ||
<div | ||
className={error ? cx(statusMessage, statusMessageError) : statusMessage} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} |
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
Oops, something went wrong.