Skip to content

Commit 9120ac3

Browse files
committed
run prettier
1 parent 4c6bbe1 commit 9120ac3

File tree

11 files changed

+319
-244
lines changed

11 files changed

+319
-244
lines changed

frontend/src/api/fileUpload.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Dispatch, SetStateAction, useState } from "react";
2-
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
1+
import { Dispatch, SetStateAction, useState } from 'react';
2+
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
33

4-
import { SerializedException } from "@/pythonTypes";
4+
import { SerializedException } from '@/pythonTypes';
55

6-
import { APIError } from "./common";
6+
import { APIError } from './common';
77

88
export interface FileUploadProgress {
99
name: string;
@@ -34,8 +34,13 @@ export const fileUploadMutationOptions: UseMutationOptions<
3434
> = {
3535
mutationFn: async ({ files, targetDir, setProgress }) => {
3636
let uploadedBytesTotal = 0;
37-
const totalBytes = Array.from(files).reduce((acc, file) => acc + file.size, 0);
38-
console.log(`Uploading ${files.length} files, total size ${totalBytes} bytes`);
37+
const totalBytes = Array.from(files).reduce(
38+
(acc, file) => acc + file.size,
39+
0
40+
);
41+
console.log(
42+
`Uploading ${files.length} files, total size ${totalBytes} bytes`
43+
);
3944

4045
// init progress bars for each file
4146
// Note that you cannot use an object for the batch progress, because
@@ -98,7 +103,9 @@ export const fileUploadMutationOptions: UseMutationOptions<
98103
loaded: uploadedBytesTotal,
99104
};
100105
});
101-
console.debug(`Uploaded file ${i + 1}/${files.length}: ${file.name}`);
106+
console.debug(
107+
`Uploaded file ${i + 1}/${files.length}: ${file.name}`
108+
);
102109
}
103110

104111
const finished = performance.now();
@@ -115,7 +122,7 @@ export const fileUploadMutationOptions: UseMutationOptions<
115122
(finished - started) / 1000
116123
} seconds`
117124
);
118-
return { status: "ok" };
125+
return { status: 'ok' };
119126
},
120127
};
121128

@@ -131,20 +138,23 @@ async function uploadFile(
131138
): Promise<{ status: string }> {
132139
// Validate headers (filename and target dir) before uploading
133140
// Raises if invalid
134-
await fetch("/file_upload/validate", {
135-
method: "POST",
141+
await fetch('/file_upload/validate', {
142+
method: 'POST',
136143
headers: {
137-
"X-Filename": encodeURIComponent(file.name),
138-
"X-File-Target-Dir": targetDir,
144+
'X-Filename': encodeURIComponent(file.name),
145+
'X-File-Target-Dir': targetDir,
139146
},
140147
});
141148

142149
return new Promise<{ status: string }>((resolve, reject) => {
143150
const req = new XMLHttpRequest();
144-
req.responseType = "json";
145-
req.open("POST", "/api_v1/file_upload", true);
146-
req.setRequestHeader("X-Filename", encodeURIComponent(file.name));
147-
req.setRequestHeader("X-File-Target-Dir", encodeURIComponent(targetDir));
151+
req.responseType = 'json';
152+
req.open('POST', '/api_v1/file_upload', true);
153+
req.setRequestHeader('X-Filename', encodeURIComponent(file.name));
154+
req.setRequestHeader(
155+
'X-File-Target-Dir',
156+
encodeURIComponent(targetDir)
157+
);
148158
// req.setRequestHeader("Content-Length", String(file.size));
149159

150160
req.upload.onprogress = (event) => {
@@ -157,18 +167,18 @@ async function uploadFile(
157167
if (req.status >= 200 && req.status < 300) {
158168
// onprogress is not called automatically when finally done
159169
// onProgress?.({ total: file.size, loaded: file.size });
160-
console.log("File upload resolve");
161-
resolve({ status: "ok" });
170+
console.log('File upload resolve');
171+
resolve({ status: 'ok' });
162172
} else {
163173
const json_error = req.response as SerializedException;
164-
console.error("File upload error:", json_error);
174+
console.error('File upload error:', json_error);
165175
reject(new APIError(json_error, req.status));
166176
}
167177
};
168178

169179
req.onerror = () => {
170180
const json_error = req.response as SerializedException;
171-
console.error("File upload error:", req);
181+
console.error('File upload error:', req);
172182
reject(new APIError(json_error, req.status));
173183
};
174184
req.send(file);

frontend/src/components/common/hooks/useDrag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect, useState } from 'react';
22

33
type Entries<T> = {
44
[K in keyof T]: [K, T[K]];

frontend/src/components/common/inputs/cancle.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { XIcon } from "lucide-react";
2-
import { useImperativeHandle, useRef, useState } from "react";
3-
import { Button, ButtonProps } from "@mui/material";
1+
import { XIcon } from 'lucide-react';
2+
import { useImperativeHandle, useRef, useState } from 'react';
3+
import { Button, ButtonProps } from '@mui/material';
44

55
export interface CancelButtonRef {
66
cancel: () => void;
@@ -30,7 +30,7 @@ export function CancelButton({
3030
}: {
3131
ref?: React.Ref<CancelButtonRef>;
3232
onCancel: () => void;
33-
} & Omit<ButtonProps, "onClick" | "ref">) {
33+
} & Omit<ButtonProps, 'onClick' | 'ref'>) {
3434
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
3535
const intervalRef = useRef<NodeJS.Timeout | null>(null);
3636
const [isCancelling, setIsCancelling] = useState(false);
@@ -87,7 +87,7 @@ export function CancelButton({
8787
// TODO: a class for animations would be useful
8888
{...props}
8989
>
90-
{isCancelling ? `Cancelling in ${remainingTime}s...` : "Cancel"}
90+
{isCancelling ? `Cancelling in ${remainingTime}s...` : 'Cancel'}
9191
</Button>
9292
);
9393
}

frontend/src/components/frontpage/navbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ const StyledTab = styled(createLink(Tab))<StyledTabProps>(({ theme }) => ({
105105
[theme.breakpoints.down('laptop')]: {
106106
marginTop: 0,
107107
height: NAVBAR_HEIGHT.mobile,
108-
display: "flex",
108+
display: 'flex',
109109
zIndex: 1,
110-
flexDirection: "column",
110+
flexDirection: 'column',
111111

112112
'& svg': {
113113
fontSize: 16,
@@ -198,7 +198,7 @@ export default function NavBar(props: BoxProps) {
198198
position: 'fixed',
199199
bottom: 0,
200200
zIndex: 2,
201-
width: "100dvw",
201+
width: '100dvw',
202202
height: NAVBAR_HEIGHT.mobile,
203203
display: 'flex',
204204
justifyContent: 'center',

frontend/src/components/inbox/fileUpload/context.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { createContext, useContext, useState } from "react";
2-
import React from "react";
3-
import { createPortal } from "react-dom";
4-
import { Box } from "@mui/material";
1+
import { createContext, useContext, useState } from 'react';
2+
import React from 'react';
3+
import { createPortal } from 'react-dom';
4+
import { Box } from '@mui/material';
55

6-
import { FileUploadState, useFileUpload } from "@/api/fileUpload";
7-
import { useDragAndDrop } from "@/components/common/hooks/useDrag";
6+
import { FileUploadState, useFileUpload } from '@/api/fileUpload';
7+
import { useDragAndDrop } from '@/components/common/hooks/useDrag';
88

9-
import { UploadDialog } from "./dialog";
9+
import { UploadDialog } from './dialog';
1010

11-
type FileUploadContextType = Omit<FileUploadState, "mutate" | "mutateAsync"> & {
11+
type FileUploadContextType = Omit<FileUploadState, 'mutate' | 'mutateAsync'> & {
1212
fileList: Array<File>;
1313
setFileList: React.Dispatch<React.SetStateAction<Array<File>>>;
1414
uploadFiles: () => Promise<{ status: string }>;
@@ -24,7 +24,11 @@ const FileUploadContext = createContext<FileUploadContextType | null>(null);
2424

2525
// Provider component which allows to
2626
// upload files via drag and drop or file picker
27-
export function FileUploadProvider({ children }: { children: React.ReactNode }) {
27+
export function FileUploadProvider({
28+
children,
29+
}: {
30+
children: React.ReactNode;
31+
}) {
2832
const [fileList, setFileList] = useState<Array<File>>([]);
2933
const [uploadTargetDir, setUploadTargetDir] = useState<string | null>(null);
3034

@@ -41,7 +45,7 @@ export function FileUploadProvider({ children }: { children: React.ReactNode })
4145
setFileList,
4246
uploadFiles: async () => {
4347
if (!uploadTargetDir) {
44-
throw new Error("No target directory set for upload");
48+
throw new Error('No target directory set for upload');
4549
}
4650
return await mutateAsync(fileList, uploadTargetDir);
4751
},
@@ -61,15 +65,15 @@ export function FileUploadProvider({ children }: { children: React.ReactNode })
6165
<Box
6266
// blur the whole background, including navbars
6367
sx={{
64-
position: "fixed",
68+
position: 'fixed',
6569
top: 0,
6670
left: 0,
6771
right: 0,
6872
bottom: 0,
69-
backgroundColor: "rgba(0, 0, 0, 0.3)",
70-
backdropFilter: "blur(4px)",
71-
pointerEvents: "none",
72-
display: isOverWindow ? "flex" : "none",
73+
backgroundColor: 'rgba(0, 0, 0, 0.3)',
74+
backdropFilter: 'blur(4px)',
75+
pointerEvents: 'none',
76+
display: isOverWindow ? 'flex' : 'none',
7377
}}
7478
></Box>,
7579
document.body
@@ -82,7 +86,7 @@ export function useFileUploadContext() {
8286
const context = useContext(FileUploadContext);
8387
if (!context) {
8488
throw new Error(
85-
"useFileUploadContext must be used within a FileUploadProvider"
89+
'useFileUploadContext must be used within a FileUploadProvider'
8690
);
8791
}
8892
return context;

0 commit comments

Comments
 (0)