consent context vibe

This commit is contained in:
Igor Loskutov
2025-06-17 17:47:04 -04:00
parent 91c7c8b83a
commit 2ac92b2d67
6 changed files with 52 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ import useMp3 from "../../useMp3";
import WaveformLoading from "../../waveformLoading";
import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react";
import LiveTrancription from "../../liveTranscription";
import AudioConsentDialog from "../../components/AudioConsentDialog";
import AudioConsentDialog from "../../../rooms/audioConsentDialog";
import useApi from "../../../../lib/useApi";
type TranscriptDetails = {

View File

@@ -133,6 +133,8 @@ const ShareModal = (props: ShareModalProps) => {
setStream(val.toString());
}}
placeholder="Pick a stream"
onBlur={() => {}}
onFocus={() => {}}
/>
</div>
@@ -145,6 +147,8 @@ const ShareModal = (props: ShareModalProps) => {
value={topic}
onChange={(val) => setTopic(val.toString())}
placeholder="Pick a topic"
onBlur={() => {}}
onFocus={() => {}}
/>
</div>
)}

View File

@@ -177,6 +177,8 @@ const TranscriptCreate = () => {
value={targetLanguage}
onChange={onLanguageChange}
placeholder="Choose your language"
onBlur={() => {}}
onFocus={() => {}}
/>
</Box>
{isClient && !loading ? (

View File

@@ -9,6 +9,7 @@ import { notFound } from "next/navigation";
import useSessionStatus from "../lib/useSessionStatus";
import AudioConsentDialog from "../(app)/rooms/audioConsentDialog";
import { DomainContext } from "../domainContext";
import { useRecordingConsent } from "../recordingConsentContext";
import useSessionAccessToken from "../lib/useSessionAccessToken";
import useSessionUser from "../lib/useSessionUser";
@@ -25,7 +26,8 @@ export default function Room(details: RoomDetails) {
const router = useRouter();
const { isLoading, isAuthenticated } = useSessionStatus();
const [showConsentDialog, setShowConsentDialog] = useState(false);
const [consentGiven, setConsentGiven] = useState<boolean | null>(null);
const [consentLoading, setConsentLoading] = useState(false);
const { state: consentState, touch, hasConsent } = useRecordingConsent();
const { api_url } = useContext(DomainContext);
const { accessToken } = useSessionAccessToken();
const { id: userId } = useSessionUser();
@@ -35,6 +37,8 @@ export default function Room(details: RoomDetails) {
? meeting?.response?.host_room_url
: meeting?.response?.room_url;
const meetingId = meeting?.response?.id;
const handleLeave = useCallback(() => {
router.push("/browse");
}, [router]);
@@ -48,9 +52,9 @@ export default function Room(details: RoomDetails) {
return null;
}, [isAuthenticated, userId]);
const handleConsent = useCallback(async (given: boolean) => {
setConsentGiven(given);
setShowConsentDialog(false); // Close dialog after consent is given
const handleConsent = useCallback(async (meetingId: string, given: boolean) => {
setConsentLoading(true);
setShowConsentDialog(false); // Close dialog immediately
if (meeting?.response?.id && api_url) {
try {
@@ -73,14 +77,20 @@ export default function Room(details: RoomDetails) {
body: JSON.stringify(requestBody),
});
if (!response.ok) {
if (response.ok) {
touch(meetingId);
} else {
console.error('Failed to submit consent');
}
} catch (error) {
console.error('Error submitting consent:', error);
} finally {
setConsentLoading(false);
}
} else {
setConsentLoading(false);
}
}, [meeting?.response?.id, api_url, accessToken]);
}, [meeting?.response?.id, api_url, accessToken, touch, getUserIdentifier]);
useEffect(() => {
@@ -94,12 +104,18 @@ export default function Room(details: RoomDetails) {
}
}, [isLoading, meeting?.error]);
// Show consent dialog when meeting is loaded and consent hasn't been given yet
// Show consent dialog when meeting is loaded and consent hasn't been answered yet
useEffect(() => {
if (meeting?.response?.id && consentGiven === null && !showConsentDialog) {
if (
consentState.ready &&
meetingId &&
!hasConsent(meetingId) &&
!showConsentDialog &&
!consentLoading
) {
setShowConsentDialog(true);
}
}, [meeting?.response?.id, consentGiven, showConsentDialog]);
}, [consentState.ready, meetingId, hasConsent, showConsentDialog, consentLoading]);
useEffect(() => {
if (isLoading || !isAuthenticated || !roomUrl) return;
@@ -142,11 +158,13 @@ export default function Room(details: RoomDetails) {
style={{ width: "100vw", height: "100vh" }}
/>
)}
<AudioConsentDialog
isOpen={showConsentDialog}
onClose={() => {}} // No-op: ESC should not close without consent
onConsent={handleConsent}
/>
{meetingId && consentState.ready && !hasConsent(meetingId) && !consentLoading && (
<AudioConsentDialog
isOpen={showConsentDialog}
onClose={() => {}} // No-op: ESC should not close without consent
onConsent={b => handleConsent(meetingId, b)}
/>
)}
</>
);
}

View File

@@ -4,6 +4,7 @@ import SessionProvider from "./lib/SessionProvider";
import { ErrorProvider } from "./(errors)/errorContext";
import ErrorMessage from "./(errors)/errorMessage";
import { DomainContextProvider } from "./domainContext";
import { RecordingConsentProvider } from "./recordingConsentContext";
import { getConfig } from "./lib/edgeConfig";
import { ErrorBoundary } from "@sentry/nextjs";
import { Providers } from "./providers";
@@ -68,12 +69,14 @@ export default async function RootLayout({
<body className={"h-[100svh] w-[100svw] overflow-x-hidden relative"}>
<SessionProvider>
<DomainContextProvider config={config}>
<ErrorBoundary fallback={<p>"something went really wrong"</p>}>
<ErrorProvider>
<ErrorMessage />
<Providers>{children}</Providers>
</ErrorProvider>
</ErrorBoundary>
<RecordingConsentProvider>
<ErrorBoundary fallback={<p>"something went really wrong"</p>}>
<ErrorProvider>
<ErrorMessage />
<Providers>{children}</Providers>
</ErrorProvider>
</ErrorBoundary>
</RecordingConsentProvider>
</DomainContextProvider>
</SessionProvider>
</body>