add permission error, issue with useState, await requestPermission

This commit is contained in:
Loewy 2024-02-19 17:49:23 -08:00
parent f9edab8f36
commit 36fe81cb3e
3 changed files with 26 additions and 7 deletions

View File

@ -72,7 +72,7 @@ export const useVideoDetails = ({
const { hasPermission, requestPermission } = useCameraPermission(); const { hasPermission, requestPermission } = useCameraPermission();
const [sessionName, setSessionName] = useState<string>( const [sessionName, setSessionName] = useState<string>(
initialState.sessionName || "", initialState.sessionName,
); );
const closeAllDropdowns = useCallback(() => { const closeAllDropdowns = useCallback(() => {
@ -101,15 +101,24 @@ export const useVideoDetails = ({
closeAllDropdowns, closeAllDropdowns,
); );
const [TerminateUploadStream, { loading, error }] = const [terminateUploadStream, { loading, error }] =
gql.useTerminateUploadStreamMutation(); gql.useTerminateUploadStreamMutation();
const handleSubmit = async () => { const handleSubmit = async () => {
if (mode === "start-video" && !hasPermission) { // Check permissions
requestPermission(); if (!hasPermission) {
return showAlert("camera"); console.log("running");
try {
const permissionResult = await requestPermission();
if (permissionResult.status !== "granted") {
return showAlert("camera");
}
} catch (err) {
return showAlert("permissionError");
}
} }
// Navigate if starting flow, terminateUploadStream if completing flow
if (mode === "start-video") { if (mode === "start-video") {
const params: VideoFlowInputParams = { const params: VideoFlowInputParams = {
sessionName, sessionName,
@ -119,7 +128,7 @@ export const useVideoDetails = ({
navigation.push("Camera", params); navigation.push("Camera", params);
} else { } else {
try { try {
await TerminateUploadStream({ await terminateUploadStream({
variables: { variables: {
videoId, videoId,
videoName: sessionName, videoName: sessionName,

View File

@ -24,6 +24,11 @@ export const CAMERA_PERMISSION_DENIED: PermissionMessage = {
}, },
}; };
export const PERMISSION_ERROR: ApiError = {
title: "There was an issue accessing permissions. ",
message: "Please check you settings and try again",
};
export const TERMINATE_UPLOAD_ERROR: ApiError = { export const TERMINATE_UPLOAD_ERROR: ApiError = {
title: "There was an issue.", title: "There was an issue.",
message: "Please try again", message: "Please try again",

View File

@ -1,8 +1,13 @@
import { Alert, Platform } from "react-native"; import { Alert, Platform } from "react-native";
import { CAMERA_PERMISSION_DENIED, TERMINATE_UPLOAD_ERROR } from "./constants"; import {
CAMERA_PERMISSION_DENIED,
PERMISSION_ERROR,
TERMINATE_UPLOAD_ERROR,
} from "./constants";
const ALERT_TYPE = { const ALERT_TYPE = {
camera: CAMERA_PERMISSION_DENIED, camera: CAMERA_PERMISSION_DENIED,
permissionError: PERMISSION_ERROR,
terminateUpload: TERMINATE_UPLOAD_ERROR, terminateUpload: TERMINATE_UPLOAD_ERROR,
}; };