Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/modal and button fixes on callpage #255

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/components/calls-page/calls-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,29 @@ export const CallsPage = () => {
const runExitAllCalls = async () => {
setProductionId(null);
navigate("/");
Object.entries(calls).forEach(([callId]) => {
if (callId) {
dispatch({
type: "REMOVE_CALL",
payload: { id: callId },
});
}
});
if (!isEmpty) {
Object.entries(calls).forEach(([callId]) => {
if (callId) {
dispatch({
type: "REMOVE_CALL",
payload: { id: callId },
});
}
});
}
};

return (
<Container>
<ButtonWrapper>
<NavigateToRootButton
resetOnExitRequest={() => setConfirmExitModalOpen(true)}
resetOnExitRequest={() => {
if (isEmpty) {
runExitAllCalls();
} else {
setConfirmExitModalOpen(true);
}
}}
/>
{confirmExitModalOpen && (
<Modal onClose={() => setConfirmExitModalOpen(false)}>
Expand Down
23 changes: 14 additions & 9 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ export const Header: FC = () => {
const navigate = useNavigate();
const location = useLocation();
const { playExitSound } = useAudioCue();
const isEmpty = Object.values(calls).length === 0;

const runExitAllCalls = () => {
setConfirmExitModalOpen(false);
navigate("/");
playExitSound();
Object.entries(calls).forEach(([callId]) => {
if (callId) {
dispatch({
type: "REMOVE_CALL",
payload: { id: callId },
});
}
});
if (!isEmpty) {
Object.entries(calls).forEach(([callId]) => {
if (callId) {
dispatch({
type: "REMOVE_CALL",
payload: { id: callId },
});
}
});
}
};

const returnToRoot = () => {
if (location.pathname.includes("/line")) {
if (location.pathname.includes("/line") && isEmpty) {
runExitAllCalls();
} else if (location.pathname.includes("/line")) {
setConfirmExitModalOpen(true);
} else {
navigate("/");
Expand Down
52 changes: 29 additions & 23 deletions src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,31 @@ export const ProductionLine = ({
sessionId,
} = callState;

const {
formState: { isValid, isDirty },
register,
handleSubmit,
watch,
} = useForm<FormValues>({
defaultValues: {
username: "",
productionId: paramProductionId || "",
lineId: paramLineId || undefined,
},
resetOptions: {
keepDirtyValues: true, // user-interacted input will be retained
keepErrors: true, // input errors will be retained with value update
},
});

// Watch all form values
const watchedValues = watch();
const audioInputTheSame =
joinProductionOptions?.audioinput === watchedValues.audioinput;
const audioOutputTheSame =
joinProductionOptions?.audiooutput === watchedValues.audiooutput;
const audioNotChanged = audioInputTheSame && audioOutputTheSame;

const [inputAudioStream, resetAudioInput] = useAudioInput({
audioInputId: joinProductionOptions?.audioinput ?? null,
audioOutputId: joinProductionOptions?.audiooutput ?? null,
Expand Down Expand Up @@ -346,22 +371,6 @@ export const ProductionLine = ({
dispatch,
});

const {
formState: { isValid, isDirty },
register,
handleSubmit,
} = useForm<FormValues>({
defaultValues: {
username: "",
productionId: paramProductionId || "",
lineId: paramLineId || undefined,
},
resetOptions: {
keepDirtyValues: true, // user-interacted input will be retained
keepErrors: true, // input errors will be retained with value update
},
});

const outputDevices = devices
? uniqBy(
devices.filter((d) => d.kind === "audiooutput"),
Expand All @@ -383,10 +392,7 @@ export const ProductionLine = ({

// Reset connection and re-connect to production-line
const onSubmit: SubmitHandler<FormValues> = async (payload) => {
const unchangedPayload =
payload.audioinput === joinProductionOptions?.audioinput &&
payload.audiooutput === joinProductionOptions?.audiooutput;
if (joinProductionOptions && !unchangedPayload) {
if (joinProductionOptions && !audioNotChanged) {
setConnectionActive(false);
resetAudioInput();
muteInput(true);
Expand Down Expand Up @@ -605,13 +611,13 @@ export const ProductionLine = ({
</StyledWarningMessage>
)}
<ButtonWrapper>
<PrimaryButton
<ActionButton
type="submit"
disabled={!isValid || !isDirty}
disabled={audioNotChanged || !isValid || !isDirty}
onClick={handleSubmit(onSubmit)}
>
Save
</PrimaryButton>
</ActionButton>
{!(isBrowserFirefox && !isMobile) && (
<ReloadDevicesButton
handleReloadDevices={() =>
Expand Down
Loading