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/upload #535

Open
wants to merge 23 commits into
base: mobile
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e766b2b
fix: [upload] wip multipart upload
dragos1195 May 27, 2024
bab167f
fix: [upload] wip
dragos1195 May 28, 2024
30cd518
fix: [upload] wip integration with backend
dragos1195 May 28, 2024
1d92df4
fix: [upload] wip
dragos1195 May 29, 2024
2e07493
fix: [upload] wip
dragos1195 May 29, 2024
e93a959
fix: [upload] wip
dragos1195 May 30, 2024
38a1c49
fix: [upload] wip
dragos1195 May 30, 2024
eab4289
fix: [upload] revert branch to filesystem implementation
dragos1195 May 31, 2024
d129d55
fix: [upload] remove unused import
dragos1195 May 31, 2024
996f023
Merge branch 'mobile' into fix/upload
dragos1195 May 31, 2024
374bc3a
fix: [upload]
dragos1195 May 31, 2024
d91112d
Fix getting corect image/video metadata
radulescuandrew May 31, 2024
719ffa9
fix: [upload] quick report implementation
dragos1195 May 31, 2024
39f120c
Merge branch 'fix/upload' of github.com:commitglobal/votemonitor into…
dragos1195 May 31, 2024
8134ef5
wip - upload offline
radulescuandrew May 31, 2024
471bf83
Merge branch 'fix/upload' of github.com:commitglobal/votemonitor into…
radulescuandrew May 31, 2024
2356ead
wip - upload attachments offline + progress
radulescuandrew Jun 1, 2024
4d7f4ec
wip - upload chunks - working photo/video
radulescuandrew Jun 2, 2024
3a0a79c
fix - upload audio
radulescuandrew Jun 2, 2024
1fe7884
fix:[upload[ add zustand for progress - wip
dragos1195 Jun 5, 2024
f37bac3
fix merge
dragos1195 Oct 8, 2024
798ce90
fix: [upload] remove zustand and make it run with linter
dragos1195 Oct 8, 2024
4dc8b9c
Merge branch 'mobile' into fix/upload
dragos1195 Oct 8, 2024
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
210 changes: 105 additions & 105 deletions mobile/app/(observer)/(app)/form-questionnaire/[questionId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useFormSubmissionMutation } from "../../../../services/mutations/form-s
import OptionsSheet from "../../../../components/OptionsSheet";
import AddAttachment from "../../../../components/AddAttachment";
import { FileMetadata, useCamera } from "../../../../hooks/useCamera";
import { addAttachmentMutation } from "../../../../services/mutations/attachments/add-attachment.mutation";
// import { addAttachmentMutation } from "../../../../services/mutations/attachments/add-attachment.mutation";
import QuestionAttachments from "../../../../components/QuestionAttachments";
import QuestionNotes from "../../../../components/QuestionNotes";
import * as DocumentPicker from "expo-document-picker";
Expand Down Expand Up @@ -311,108 +311,108 @@ const FormQuestionnaire = () => {
}
const { uploadCameraOrMedia } = useCamera();

const {
mutate: addAttachment,
isPending: isLoadingAddAttachmentt,
isPaused,
} = addAttachmentMutation(
`Attachment_${questionId}_${selectedPollingStation?.pollingStationId}_${formId}_${questionId}`,
);

const handleCameraUpload = async (type: "library" | "cameraPhoto") => {
setIsPreparingFile(true);
const cameraResult = await uploadCameraOrMedia(type);

if (!cameraResult) {
setIsPreparingFile(false);
return;
}

if (
activeElectionRound &&
selectedPollingStation?.pollingStationId &&
formId &&
activeQuestion.question.id
) {
addAttachment(
{
id: Crypto.randomUUID(),
electionRoundId: activeElectionRound.id,
pollingStationId: selectedPollingStation.pollingStationId,
formId,
questionId: activeQuestion.question.id,
fileMetadata: cameraResult,
},
{
onSettled: () => setIsOptionsSheetOpen(false),
onError: (err) => {
Sentry.captureException(err);
Toast.show({
type: "error",
text2: t("attachments.error"),
});
},
},
);

setIsPreparingFile(false);

if (!onlineManager.isOnline()) {
setIsOptionsSheetOpen(false);
}
}
};

const handleUploadAudio = async () => {
const doc = await DocumentPicker.getDocumentAsync({
type: "audio/*",
multiple: false,
});

if (doc?.assets?.[0]) {
const file = doc?.assets?.[0];

const fileMetadata: FileMetadata = {
name: file.name,
type: file.mimeType || "audio/mpeg",
uri: file.uri,
};

if (
activeElectionRound &&
selectedPollingStation?.pollingStationId &&
formId &&
activeQuestion.question.id
) {
addAttachment(
{
id: Crypto.randomUUID(),
electionRoundId: activeElectionRound.id,
pollingStationId: selectedPollingStation.pollingStationId,
formId,
questionId: activeQuestion.question.id,
fileMetadata,
},
{
onSettled: () => setIsOptionsSheetOpen(false),
onError: (err) => {
Sentry.captureException(err);
Toast.show({
type: "error",
text2: t("attachments.error"),
});
},
},
);

if (!onlineManager.isOnline()) {
setIsOptionsSheetOpen(false);
}
}
} else {
// Cancelled
}
};
// const {
// mutate: addAttachment,
// isPending: isLoadingAddAttachmentt,
// isPaused,
// } = addAttachmentMutation(
// `Attachment_${questionId}_${selectedPollingStation?.pollingStationId}_${formId}_${questionId}`,
// );

// const handleCameraUpload = async (type: "library" | "cameraPhoto") => {
// setIsPreparingFile(true);
// const cameraResult = await uploadCameraOrMedia(type);

// if (!cameraResult) {
// setIsPreparingFile(false);
// return;
// }

// if (
// activeElectionRound &&
// selectedPollingStation?.pollingStationId &&
// formId &&
// activeQuestion.question.id
// ) {
// addAttachment(
// {
// id: Crypto.randomUUID(),
// electionRoundId: activeElectionRound.id,
// pollingStationId: selectedPollingStation.pollingStationId,
// formId,
// questionId: activeQuestion.question.id,
// fileMetadata: cameraResult,
// },
// {
// onSettled: () => setIsOptionsSheetOpen(false),
// onError: (err) => {
// Sentry.captureException(err);
// Toast.show({
// type: "error",
// text2: t("attachments.error"),
// });
// },
// },
// );

// setIsPreparingFile(false);

// if (!onlineManager.isOnline()) {
// setIsOptionsSheetOpen(false);
// }
// }
// };

// const handleUploadAudio = async () => {
// const doc = await DocumentPicker.getDocumentAsync({
// type: "audio/*",
// multiple: false,
// });

// if (doc?.assets?.[0]) {
// const file = doc?.assets?.[0];

// const fileMetadata: FileMetadata = {
// name: file.name,
// type: file.mimeType || "audio/mpeg",
// uri: file.uri,
// };

// if (
// activeElectionRound &&
// selectedPollingStation?.pollingStationId &&
// formId &&
// activeQuestion.question.id
// ) {
// addAttachment(
// {
// id: Crypto.randomUUID(),
// electionRoundId: activeElectionRound.id,
// pollingStationId: selectedPollingStation.pollingStationId,
// formId,
// questionId: activeQuestion.question.id,
// fileMetadata,
// },
// {
// onSettled: () => setIsOptionsSheetOpen(false),
// onError: (err) => {
// Sentry.captureException(err);
// Toast.show({
// type: "error",
// text2: t("attachments.error"),
// });
// },
// },
// );

// if (!onlineManager.isOnline()) {
// setIsOptionsSheetOpen(false);
// }
// }
// } else {
// // Cancelled
// }
// };

// scroll view ref
const scrollViewRef = useRef(null);
Expand Down Expand Up @@ -537,7 +537,7 @@ const FormQuestionnaire = () => {
onPreviousButtonPress={onBackButtonPress}
/>
{/* //todo: remove this once tamagui fixes sheet issue #2585 */}
{isOptionsSheetOpen && (
{/* {isOptionsSheetOpen && (
<OptionsSheet
open
setOpen={(open) => {
Expand Down Expand Up @@ -611,7 +611,7 @@ const FormQuestionnaire = () => {
actionBtnText={t("warning_modal.unsaved_answer.actions.save")}
cancelBtnText={t("warning_modal.unsaved_answer.actions.cancel")}
/>
)}
)} */}
</Screen>
);
};
Expand Down
Loading
Loading