Skip to content

Commit

Permalink
feat: multiple uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Sep 29, 2024
1 parent f5c505a commit 39c1632
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
36 changes: 25 additions & 11 deletions frontend/src/lib/actions/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,32 @@ export async function uploadNewsFileAction(
id: number,
type: NewsUploadTypeEnum,
formData: FormData,
): Promise<ApiResult<NewsUpload200Response>> {
): Promise<ApiResult<NewsUpload200Response|null>> {
try {
const file = deserializeFileData(formData)
const data = await newsApi.newsUpload({
id,
type,
// TODO: Multiple
file: Array.isArray(file) ? file[0] : file,
})
return {
data,
error: null,
const fileData = deserializeFileData(formData)

if (Array.isArray(fileData)) {
for await (const file of fileData) {
await newsApi.newsUpload({
id,
type,
file,
})
}
return {
data: null,
error: null,
}
} else {
const data = await newsApi.newsUpload({
id,
type,
file: fileData,
})
return {
data,
error: null,
}
}
} catch (error) {
if (error instanceof ResponseError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ const Editor = React.forwardRef((props: EditorProps, ref: React.Ref<any>) => {
?.chain()
.focus()
.setImage({
src: data?.url,
// TODO: Better types
src: data!.url,
})
.run()
}}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiErrors } from '@/types'
import { ApiErrors, AppSessionData } from '@/types'
import { clsx, type ClassValue } from 'clsx'
import { FieldValues, UseFormReturn } from 'react-hook-form'
import { twMerge } from 'tailwind-merge'
Expand Down

0 comments on commit 39c1632

Please sign in to comment.