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 [sessionName, setSessionName] = useState<string>(
initialState.sessionName || "",
initialState.sessionName,
);
const closeAllDropdowns = useCallback(() => {
@ -101,15 +101,24 @@ export const useVideoDetails = ({
closeAllDropdowns,
);
const [TerminateUploadStream, { loading, error }] =
const [terminateUploadStream, { loading, error }] =
gql.useTerminateUploadStreamMutation();
const handleSubmit = async () => {
if (mode === "start-video" && !hasPermission) {
requestPermission();
return showAlert("camera");
// Check permissions
if (!hasPermission) {
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") {
const params: VideoFlowInputParams = {
sessionName,
@ -119,7 +128,7 @@ export const useVideoDetails = ({
navigation.push("Camera", params);
} else {
try {
await TerminateUploadStream({
await terminateUploadStream({
variables: {
videoId,
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 = {
title: "There was an issue.",
message: "Please try again",

View File

@ -1,8 +1,13 @@
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 = {
camera: CAMERA_PERMISSION_DENIED,
permissionError: PERMISSION_ERROR,
terminateUpload: TERMINATE_UPLOAD_ERROR,
};