Switch to useShouldShowPtt hook

This commit is contained in:
Robert Long 2022-05-03 10:32:06 -07:00
parent be01a4bd81
commit dbdb82bd74
4 changed files with 30 additions and 21 deletions

View file

@ -13,12 +13,13 @@ import { JoinExistingCallModal } from "./JoinExistingCallModal";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import { Headline, Title } from "../typography/Typography"; import { Headline, Title } from "../typography/Typography";
import { Form } from "../form/Form"; import { Form } from "../form/Form";
import { shouldShowPtt } from "../shouldShowPtt"; import { useShouldShowPtt } from "../useShouldShowPtt";
export function RegisteredView({ client }) { export function RegisteredView({ client }) {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(); const [error, setError] = useState();
const history = useHistory(); const history = useHistory();
const shouldShowPtt = useShouldShowPtt();
const onSubmit = useCallback( const onSubmit = useCallback(
(e) => { (e) => {
e.preventDefault(); e.preventDefault();
@ -99,14 +100,16 @@ export function RegisteredView({ client }) {
{loading ? "Loading..." : "Go"} {loading ? "Loading..." : "Go"}
</Button> </Button>
</FieldRow> </FieldRow>
{shouldShowPtt() && <FieldRow className={styles.fieldRow}> {shouldShowPtt && (
<FieldRow className={styles.fieldRow}>
<InputField <InputField
id="ptt" id="ptt"
name="ptt" name="ptt"
label="Push to Talk" label="Push to Talk"
type="checkbox" type="checkbox"
/> />
</FieldRow>} </FieldRow>
)}
{error && ( {error && (
<FieldRow className={styles.fieldRow}> <FieldRow className={styles.fieldRow}>
<ErrorMessage>{error.message}</ErrorMessage> <ErrorMessage>{error.message}</ErrorMessage>

View file

@ -15,9 +15,10 @@ import { Form } from "../form/Form";
import styles from "./UnauthenticatedView.module.css"; import styles from "./UnauthenticatedView.module.css";
import commonStyles from "./common.module.css"; import commonStyles from "./common.module.css";
import { generateRandomName } from "../auth/generateRandomName"; import { generateRandomName } from "../auth/generateRandomName";
import { shouldShowPtt } from "../shouldShowPtt"; import { useShouldShowPtt } from "../useShouldShowPtt";
export function UnauthenticatedView() { export function UnauthenticatedView() {
const shouldShowPtt = useShouldShowPtt();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(); const [error, setError] = useState();
const [{ privacyPolicyUrl, recaptchaKey }, register] = const [{ privacyPolicyUrl, recaptchaKey }, register] =
@ -113,14 +114,16 @@ export function UnauthenticatedView() {
autoComplete="off" autoComplete="off"
/> />
</FieldRow> </FieldRow>
{shouldShowPtt() && <FieldRow> {shouldShowPtt && (
<FieldRow>
<InputField <InputField
id="ptt" id="ptt"
name="ptt" name="ptt"
label="Push to Talk" label="Push to Talk"
type="checkbox" type="checkbox"
/> />
</FieldRow>} </FieldRow>
)}
<Caption> <Caption>
By clicking "Go", you agree to our{" "} By clicking "Go", you agree to our{" "}
<Link href={privacyPolicyUrl}>Terms and conditions</Link> <Link href={privacyPolicyUrl}>Terms and conditions</Link>

View file

@ -1,3 +0,0 @@
export function shouldShowPtt() {
return window.location.hash.startsWith('#ptt');
}

6
src/useShouldShowPtt.js Normal file
View file

@ -0,0 +1,6 @@
import { useLocation } from "react-router-dom";
export function useShouldShowPtt() {
const { hash } = useLocation();
return hash.startsWith("#ptt");
}