diff --git a/.ncurc.json b/.ncurc.json new file mode 100644 index 0000000..da849a4 --- /dev/null +++ b/.ncurc.json @@ -0,0 +1,3 @@ +{ + "reject": ["eslint"] + } \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index f5660f7..0b87a8e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index df14277..35e984f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "start": "next start" }, "dependencies": { - "@auth/drizzle-adapter": "^1.5.2", + "@auth/drizzle-adapter": "^1.5.3", "@headlessui/react": "^2.1.8", "@hookform/resolvers": "^3.9.0", "@radix-ui/react-accordion": "^1.2.0", @@ -88,7 +88,7 @@ "react-dom": "^18.3.1", "react-hook-form": "^7.53.0", "react-icons": "^5.3.0", - "react-resizable-panels": "^2.1.3", + "react-resizable-panels": "^2.1.4", "react-responsive-masonry": "^2.3.0", "recharts": "^2.12.7", "server-only": "^0.0.1", @@ -106,8 +106,8 @@ "@types/bun": "latest", "@types/eslint": "^9.6.1", "@types/jest": "^29.5.13", - "@types/node": "^22.7.3", - "@types/react": "^18.3.9", + "@types/node": "^22.7.4", + "@types/react": "^18.3.10", "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^8.7.0", "@typescript-eslint/parser": "^8.7.0", diff --git a/src/app/(site)/(app)/upload/page.tsx b/src/app/(site)/(app)/upload/page.tsx index 579a556..b1b0325 100644 --- a/src/app/(site)/(app)/upload/page.tsx +++ b/src/app/(site)/(app)/upload/page.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import UploadPage from "@/components/pages/upload-page"; import { ClipboardContext } from "@/lib/clipboard/clipboard-context"; -import { usePathname, useSearchParams } from "next/navigation"; +import { useSearchParams } from "next/navigation"; import GenericError from "@/components/errors/generic-error"; import Loading from "@/components/widgets/loading"; @@ -31,7 +31,7 @@ const Upload = () => { (c === "1" && clipboardContext?.file != null && !loading) || c !== "1" ) { - return ; + return ; } if (c === "1" && loading) { return ; diff --git a/src/components/pages/upload-page.tsx b/src/components/pages/upload-page.tsx index 02ad477..fbe7edb 100644 --- a/src/components/pages/upload-page.tsx +++ b/src/components/pages/upload-page.tsx @@ -1,7 +1,7 @@ "use client"; import React from "react"; import { FormProvider, useForm } from "react-hook-form"; -import { SubmitHandler, Controller } from "react-hook-form"; +import { type SubmitHandler, Controller } from "react-hook-form"; import { useRouter } from "next/navigation"; import ImageUpload from "@/components/widgets/image-upload"; import TaggedInput from "@/components/widgets/tagged-input"; @@ -27,37 +27,25 @@ type FormValues = { }; type UploadPageProps = { - file?: File; + pastedImage?: File; }; -const UploadPage: React.FC = ({ file }) => { +const UploadPage: React.FC = ({ pastedImage }) => { const utils = api.useUtils(); + const router = useRouter(); + const form = useForm({ defaultValues: { title: env.NEXT_PUBLIC_DEBUG_MODE ? "This is my title" : "", description: env.NEXT_PUBLIC_DEBUG_MODE ? "This is my description" : "", tags: [], - image: undefined, }, }); - if (file) { - logger.log("upload-page", "We gotta file", file); + if (pastedImage) { + logger.log("upload-page", "We gotta file", pastedImage); } else { logger.log("upload-page", "No file"); } - // const imageSchema = z.object({ - // image: z - // .any() - // .refine((file) => { - // if (file.size === 0 || file.name === undefined) return false; - // else return true; - // }, "Please update or add new image.") - // .refine( - // (file) => ACCEPTED_IMAGE_TYPES.includes(file?.type), - // ".jpg, .jpeg, .png and .webp files are accepted.", - // ) - // .refine((file) => file.size <= MAX_FILE_SIZE, `Max file size is 5MB.`), - // }); const createImage = api.post.create.useMutation({ onSuccess: async (e) => { console.log("upload-page", "onSuccess", e); @@ -69,7 +57,7 @@ const UploadPage: React.FC = ({ file }) => { method: "POST", body, }); - if (response.status === StatusCodes.CREATED) { + if ((response.status as StatusCodes) === StatusCodes.CREATED) { await utils.post.invalidate(); router.replace("/"); } @@ -89,17 +77,6 @@ const UploadPage: React.FC = ({ file }) => { } catch (error) { logger.error("UploadPage", "error", error); } - // if (data.image) { - // const body = new FormData(); - // body.append("file", data.image); - // const response = await fetch("api/upload", { - // method: "POST", - // body, - // }); - // if (response.status === 201) { - // router.replace("/"); - // } - // } }; return (
@@ -139,7 +116,11 @@ const UploadPage: React.FC = ({ file }) => { control={form.control} name="image" render={({ field: { value, onChange } }) => ( - + )} /> void; } -const ImageUpload: React.FC = ({ onChange }) => { - const [image, setImage] = React.useState(); +const ImageUpload: React.FC = ({ + pastedImage, + onChange, +}) => { + const [image, setImage] = React.useState( + pastedImage && URL.createObjectURL(pastedImage), + ); + const onImageChange = ($event: React.ChangeEvent) => { - console.log("ImageUpload", "onImageChange", $event); if ($event.target.files?.[0]) { - const url = URL.createObjectURL($event.target.files[0]); - setImage(url); - onChange($event.target.files[0]); + handleNewImage($event.target.files[0]); } }; + + const handleNewImage = (imageFile: File) => { + const url = URL.createObjectURL(imageFile); + setImage(url); + onChange(imageFile); + }; + + React.useEffect(() => { + if (pastedImage) { + handleNewImage(pastedImage); + } + }, []); + return (
{image ? ( @@ -41,7 +58,7 @@ const ImageUpload: React.FC = ({ onChange }) => { > Upload a file