Skip to content

Commit f37bac3

Browse files
committed
fix merge
1 parent 1fe7884 commit f37bac3

5 files changed

Lines changed: 7 additions & 112 deletions

File tree

mobile/contexts/persist-query/PersistQueryContext.provider.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { ASYNC_STORAGE_KEYS } from "../../common/constants";
2626
import * as Sentry from "@sentry/react-native";
2727
import SuperJSON from "superjson";
2828
import { uploadAttachmentMutationFn } from "../../services/mutations/attachments/add-attachment.mutation";
29-
import useStore from "../../services/store/store";
3029

3130
const queryClient = new QueryClient({
3231
mutationCache: new MutationCache({
@@ -110,8 +109,7 @@ const PersistQueryContextProvider = ({ children }: React.PropsWithChildren) => {
110109

111110
queryClient.setMutationDefaults(AttachmentsKeys.addAttachmentMutation(), {
112111
mutationFn: async (payload: AddAttachmentStartAPIPayload) => {
113-
const { progresses: state, setProgresses } = useStore();
114-
return uploadAttachmentMutationFn(payload, setProgresses, state);
112+
return uploadAttachmentMutationFn(payload);
115113
},
116114
});
117115

@@ -203,9 +201,6 @@ const PersistQueryContextProvider = ({ children }: React.PropsWithChildren) => {
203201
// console.log("📍📍📍📍📍📍", SuperJSON.stringify(newPausedMutations));
204202

205203
if (pausedMutation?.length) {
206-
const { setProgresses } = useStore();
207-
// Reset Attachment Progress
208-
setProgresses(() => ({}));
209204
await queryClient.resumePausedMutations(); // Looks in the inmemory cache
210205
queryClient.invalidateQueries(); // Avoid using await, not to wait for queries to refetch (maybe not the case here as there are no active queries)
211206
console.log("✅ Resume Paused Mutation & Invalidate Quries");

mobile/services/mutations/attachments/add-attachment.mutation.ts

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import * as FileSystem from "expo-file-system";
1212
import { MULTIPART_FILE_UPLOAD_SIZE } from "../../../common/constants";
1313
import * as Sentry from "@sentry/react-native";
1414
import { Buffer } from "buffer";
15-
import useStore from "../../store/store";
16-
import { AttachmentProgressStatusEnum } from "../../store/attachment-upload-state/attachment-upload-slice";
17-
1815
// export const handleChunkUpload = async (
1916
// filePath: string,
2017
// uploadUrls: Record<string, string>,
@@ -54,18 +51,7 @@ import { AttachmentProgressStatusEnum } from "../../store/attachment-upload-stat
5451
// return etags;
5552
// };
5653

57-
export const uploadAttachmentMutationFn = async (
58-
payload: AddAttachmentStartAPIPayload,
59-
setProgress: (fn: (prev: Record<string, any>) => Record<string, any>) => void,
60-
state: any,
61-
) => {
62-
setProgress((state) => ({
63-
...state,
64-
[payload.id]: {
65-
progress: 0,
66-
status: AttachmentProgressStatusEnum.STARTING,
67-
},
68-
}));
54+
export const uploadAttachmentMutationFn = async (payload: AddAttachmentStartAPIPayload) => {
6955
const start = await addAttachmentMultipartStart(payload);
7056
try {
7157
let etags: Record<number, string> = {};
@@ -78,18 +64,7 @@ export const uploadAttachmentMutationFn = async (
7864
encoding: FileSystem.EncodingType.Base64,
7965
});
8066
const buffer = Buffer.from(chunk, "base64");
81-
const progress = Math.round(((index + 1) / urls.length) * 100 * 10) / 10;
82-
83-
setProgress((state) => ({
84-
...state,
85-
[payload.id]: {
86-
progress: progress,
87-
status:
88-
progress === 100
89-
? AttachmentProgressStatusEnum.COMPLETED
90-
: AttachmentProgressStatusEnum.INPROGRESS,
91-
},
92-
}));
67+
// const progress = Math.round(((index + 1) / urls.length) * 100 * 10) / 10;
9368

9469
const data = await uploadS3Chunk(url, buffer);
9570

@@ -102,14 +77,6 @@ export const uploadAttachmentMutationFn = async (
10277
id: payload.id,
10378
});
10479

105-
setProgress((state) => ({
106-
...state,
107-
[payload.id]: {
108-
progress: 100,
109-
status: AttachmentProgressStatusEnum.COMPLETED,
110-
},
111-
}));
112-
11380
return completed;
11481
} catch (err) {
11582
Sentry.captureMessage("Upload failed, aborting!");
@@ -120,32 +87,24 @@ export const uploadAttachmentMutationFn = async (
12087
uploadId: start.uploadId,
12188
electionRoundId: payload.electionRoundId,
12289
});
123-
setProgress((state) => ({
124-
...state,
125-
[payload.id]: {
126-
progress: 0,
127-
status: AttachmentProgressStatusEnum.ABORTED,
128-
},
129-
}));
90+
13091
return aborted;
13192
}
13293
};
13394

13495
export type UploadAttachmentProgress = {
13596
progress: number;
136-
status: AttachmentProgressStatusEnum;
13797
};
13898

13999
export const useUploadAttachmentMutation = (scopeId: string) => {
140100
const queryClient = useQueryClient();
141-
const { progresses: state, setProgresses } = useStore();
101+
142102
return useMutation({
143103
mutationKey: AttachmentsKeys.addAttachmentMutation(),
144104
scope: {
145105
id: scopeId,
146106
},
147-
mutationFn: (payload: AddAttachmentStartAPIPayload) =>
148-
uploadAttachmentMutationFn(payload, setProgresses, state),
107+
mutationFn: (payload: AddAttachmentStartAPIPayload) => uploadAttachmentMutationFn(payload),
149108
onMutate: async (payload: AddAttachmentStartAPIPayload) => {
150109
const attachmentsQK = AttachmentsKeys.attachments(
151110
payload.electionRoundId,
@@ -176,6 +135,7 @@ export const useUploadAttachmentMutation = (scopeId: string) => {
176135
return { previousData, attachmentsQK };
177136
},
178137
onError: (err, payload, context) => {
138+
console.log("onError", err);
179139
const attachmentsQK = AttachmentsKeys.attachments(
180140
payload.electionRoundId,
181141
payload.pollingStationId,
@@ -184,12 +144,6 @@ export const useUploadAttachmentMutation = (scopeId: string) => {
184144
queryClient.setQueryData(attachmentsQK, context?.previousData);
185145
},
186146
onSettled: (_data, _err, variables) => {
187-
setProgresses((state) => {
188-
const { [variables.id]: toDelete, ...rest } = state;
189-
return {
190-
...rest,
191-
};
192-
});
193147
return queryClient.invalidateQueries({
194148
queryKey: AttachmentsKeys.attachments(
195149
variables.electionRoundId,

mobile/services/store/attachment-upload-state/attachment-upload-selector.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

mobile/services/store/attachment-upload-state/attachment-upload-slice.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

mobile/services/store/store.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)