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 11 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
283 changes: 179 additions & 104 deletions mobile/app/(app)/form-questionnaire/[questionId].tsx

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions mobile/app/(app)/report-issue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import { Typography } from "../../components/Typography";
import { useAddQuickReport } from "../../services/mutations/quick-report/add-quick-report.mutation";
import * as Crypto from "expo-crypto";
import { FileMetadata, useCamera } from "../../hooks/useCamera";
import { addAttachmentQuickReportMutation } from "../../services/mutations/quick-report/add-attachment-quick-report.mutation";
import { QuickReportLocationType } from "../../services/api/quick-report/post-quick-report.api";
import * as DocumentPicker from "expo-document-picker";
import { onlineManager, useMutationState, useQueryClient } from "@tanstack/react-query";
import Card from "../../components/Card";
import { QuickReportKeys } from "../../services/queries/quick-reports.query";
import * as Sentry from "@sentry/react-native";
import { AddAttachmentQuickReportAPIPayload } from "../../services/api/quick-report/add-attachment-quick-report.api";
import { useTranslation } from "react-i18next";
import i18n from "../../common/config/i18n";
import { AddAttachmentQuickReportStartAPIPayload } from "../../services/api/quick-report/add-attachment-quick-report.api";
import { useUploadAttachmentQuickReportMutation } from "../../services/mutations/quick-report/add-attachment-quick-report.mutation";
import { MULTIPART_FILE_UPLOAD_SIZE } from "../../common/constants";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";

const mapVisitsToSelectPollingStations = (visits: PollingStationVisitVM[] = []) => {
Expand Down Expand Up @@ -71,7 +72,7 @@ const ReportIssue = () => {
const [optionsSheetOpen, setOptionsSheetOpen] = useState(false);
const { t } = useTranslation("report_new_issue");

const [attachments, setAttachments] = useState<Array<{ fileMetadata: FileMetadata; id: string }>>(
const [attachments, setAttachments] = useState<Array<{ fileMetadata: FileMetadata; id: string, }>>(
[],
);

Expand All @@ -80,7 +81,8 @@ const ReportIssue = () => {
isPending: isPendingAddQuickReport,
isPaused: isPausedAddQuickReport,
} = useAddQuickReport();
const { mutateAsync: addAttachmentQReport } = addAttachmentQuickReportMutation();

const { mutateAsync: addAttachmentQReport } = useUploadAttachmentQuickReportMutation(`Quick_Report_${activeElectionRound?.id}}`);

const addAttachmentsMutationState = useMutationState({
filters: { mutationKey: QuickReportKeys.addAttachment() },
Expand Down Expand Up @@ -171,14 +173,17 @@ const ReportIssue = () => {
const uuid = Crypto.randomUUID();

// Use the attachments to optimistically update the UI
const optimisticAttachments: AddAttachmentQuickReportAPIPayload[] = [];
const optimisticAttachments: AddAttachmentQuickReportStartAPIPayload[] = [];

if (attachments.length > 0) {
const attachmentsMutations = attachments.map(
({ fileMetadata, id }: { fileMetadata: FileMetadata; id: string }) => {
const payload: AddAttachmentQuickReportAPIPayload = {
const payload: AddAttachmentQuickReportStartAPIPayload = {
id,
fileMetadata,
fileName: fileMetadata.name,
filePath: fileMetadata.uri,
contentType: fileMetadata.type,
numberOfUploadParts: Math.ceil(fileMetadata.size! / MULTIPART_FILE_UPLOAD_SIZE), // DRAGOS CHECK AGAIN
electionRoundId: activeElectionRound.id,
quickReportId: uuid,
};
Expand Down
7 changes: 7 additions & 0 deletions mobile/assets/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@
"attachments": {
"heading": "Uploaded media",
"loading": "Adding attachment... ",
"upload": {
"preparing": "Preparing attachment...",
"starting": "Starting the upload...",
"progress": "Upload progress:",
"completed": "Upload completed.",
"aborted": "Upload aborted."
},
"add": "Add notes and media",
"menu": {
"add_note": "Add note",
Expand Down
2 changes: 2 additions & 0 deletions mobile/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const SECURE_STORAGE_KEYS = {
};

export const I18N_LANGUAGE = "i18n-language";

export const MULTIPART_FILE_UPLOAD_SIZE = 10 * 1024 * 1024; // 10MB.
23 changes: 10 additions & 13 deletions mobile/contexts/persist-query/PersistQueryContext.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
import { notesKeys, pollingStationsKeys } from "../../services/queries.service";
import * as API from "../../services/definitions.api";
import { PersistGate } from "../../components/PersistGate";
import { AddAttachmentAPIPayload, addAttachment } from "../../services/api/add-attachment.api";
import { AddAttachmentStartAPIPayload, addAttachmentMultipartStart } from "../../services/api/add-attachment.api";
import { deleteAttachment } from "../../services/api/delete-attachment.api";
import { Note } from "../../common/models/note";
import { QuickReportKeys } from "../../services/queries/quick-reports.query";
import {
AddQuickReportAPIPayload,
addQuickReport,
} from "../../services/api/quick-report/post-quick-report.api";
import {
AddAttachmentQuickReportAPIPayload,
addAttachmentQuickReport,
} from "../../services/api/quick-report/add-attachment-quick-report.api";
import { AddAttachmentQuickReportStartAPIPayload, addAttachmentQuickReportMultipartStart } from "../../services/api/quick-report/add-attachment-quick-report.api";
import { AttachmentApiResponse } from "../../services/api/get-attachments.api";
import { AttachmentsKeys } from "../../services/queries/attachments.query";
import { ASYNC_STORAGE_KEYS } from "../../common/constants";
Expand All @@ -27,7 +24,7 @@ const queryClient = new QueryClient({
mutationCache: new MutationCache({
// There is also QueryCache
onSuccess: (data: unknown) => {
console.log("MutationCache ", data);
// console.log("MutationCache ", data);
},
onError: (error: Error, _vars, _context, mutation) => {
console.log("MutationCache error ", error);
Expand Down Expand Up @@ -104,14 +101,14 @@ const PersistQueryContextProvider = ({ children }: React.PropsWithChildren) => {
});

queryClient.setMutationDefaults(AttachmentsKeys.addAttachmentMutation(), {
mutationFn: async (payload: AddAttachmentAPIPayload) => {
return addAttachment(payload);
mutationFn: async (payload: AddAttachmentStartAPIPayload) => {
return addAttachmentMultipartStart(payload);
},
});

queryClient.setMutationDefaults(AttachmentsKeys.deleteAttachment(), {
mutationFn: async (payload: AttachmentApiResponse) => {
return payload.isNotSynched ? () => {} : deleteAttachment(payload);
return payload.isNotSynched ? () => { } : deleteAttachment(payload);
},
});

Expand All @@ -129,22 +126,22 @@ const PersistQueryContextProvider = ({ children }: React.PropsWithChildren) => {

queryClient.setMutationDefaults(notesKeys.deleteNote(), {
mutationFn: async (payload: Note) => {
return payload.isNotSynched ? () => {} : API.deleteNote(payload);
return payload.isNotSynched ? () => { } : API.deleteNote(payload);
},
});

queryClient.setMutationDefaults(QuickReportKeys.add(), {
mutationFn: async ({
attachments: _,
...payload
}: AddQuickReportAPIPayload & { attachments: AddAttachmentQuickReportAPIPayload[] }) => {
}: AddQuickReportAPIPayload & { attachments: AddAttachmentQuickReportStartAPIPayload[] }) => {
return addQuickReport(payload);
},
});

queryClient.setMutationDefaults(QuickReportKeys.addAttachment(), {
mutationFn: async (payload: AddAttachmentQuickReportAPIPayload) => {
return addAttachmentQuickReport(payload);
mutationFn: async (payload: AddAttachmentQuickReportStartAPIPayload) => {
return addAttachmentQuickReportMultipartStart(payload);
},
});

Expand Down
5 changes: 4 additions & 1 deletion mobile/hooks/useCamera.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ImagePicker from "expo-image-picker";
import Toast from "react-native-toast-message";
import { Video, Image } from "react-native-compressor";
import { Video, Image, getVideoMetaData } from "react-native-compressor";
import * as Sentry from "@sentry/react-native";

/**
Expand Down Expand Up @@ -41,6 +41,7 @@ export type FileMetadata = {
uri: string;
name: string;
type: string;
size?: number;
};

export const useCamera = () => {
Expand Down Expand Up @@ -105,11 +106,13 @@ export const useCamera = () => {
}

const filename = resultCompression.split("/").pop() || "";
const metaData = await getVideoMetaData(resultCompression);

const toReturn = {
uri: resultCompression,
name: filename,
type: file.mimeType || "",
size: metaData.size,
};
return toReturn;
}
Expand Down
55 changes: 51 additions & 4 deletions mobile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@tanstack/react-query": "^5.36.0",
"@tanstack/react-query-persist-client": "^5.36.0",
"axios": "^1.6.8",
"buffer": "^6.0.3",
"expo": "~50.0.17",
"expo-application": "~5.8.4",
"expo-build-properties": "~0.11.1",
Expand Down
Loading
Loading