Skip to content

Commit

Permalink
chore: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mateopresacastro committed Nov 6, 2024
1 parent 17ca914 commit 89862d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
40 changes: 15 additions & 25 deletions app/_header/upload-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const uploadFormSchema = z.object({
),
});

export type UploadFormSchema = z.infer<typeof uploadFormSchema>;
type UploadFormSchema = z.infer<typeof uploadFormSchema>;

function UploadForm() {
const form = useForm<UploadFormSchema>({
Expand All @@ -77,13 +77,9 @@ function UploadForm() {
const {
mutate: createPreSignedUrls,
data: preSignedUrls,
isError: isPresignedUrlsError,
isPending: isCreatingPresignedUrls,
} = useMutation({
mutationFn: () =>
handleCreatePreSignedUrl({
numOfSamples: form.getValues().samples.length,
}),
mutationFn: () => handleCreatePreSignedUrl(form.getValues().samples.length),
onSuccess: (preSignedUrls) => {
return uploadToS3({
zipFileSignedUrl: preSignedUrls.zipFileSignedUrl.url,
Expand All @@ -106,18 +102,6 @@ function UploadForm() {
onSuccess: () => persistData(),
});

function createPublicUrl({
key,
visibility,
}: {
key: string;
visibility: "private" | "public";
}) {
const bucketName =
visibility === "private" ? "noos-private-assets" : "noos-public-assets";
return `https://localhost.localstack.cloud:4566/${bucketName}/${key}`;
}

const { mutate: persistData, isPending: isPersistingData } = useMutation({
mutationFn: async () => {
if (!preSignedUrls) throw new Error("Pre-signed urls not found");
Expand Down Expand Up @@ -161,12 +145,6 @@ function UploadForm() {
createPreSignedUrls();
}

console.log({
preSignedUrls,
isCreatingPresignedUrls,
isPresignedUrlsError,
});

return (
<Form {...form}>
<form
Expand Down Expand Up @@ -257,12 +235,24 @@ function UploadForm() {
: isUploadingToS3
? "Uploading..."
: isPersistingData
? "Persisting Data"
? "Persisting Data..."
: "Submit"}
</Button>
</form>
</Form>
);
}

function createPublicUrl({
key,
visibility,
}: {
key: string;
visibility: "private" | "public";
}) {
const bucketName =
visibility === "private" ? "noos-private-assets" : "noos-public-assets";
return `https://localhost.localstack.cloud:4566/${bucketName}/${key}`;
}

export default UploadForm;
6 changes: 1 addition & 5 deletions lib/aws/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { AWS_PRIVATE_BUCKET_NAME, AWS_PUBLIC_BUCKET_NAME } from "@/cfg";
import { addSampleToSamplePack, createSamplePack } from "@/lib/db/mod";
import "server-only";

export async function handleCreatePreSignedUrl({
numOfSamples,
}: {
numOfSamples: number;
}) {
export async function handleCreatePreSignedUrl(numOfSamples: number) {
try {
const user = await currentUser();
if (!user) throw new Error();
Expand Down
1 change: 0 additions & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
images: {
remotePatterns: [
{
Expand Down

0 comments on commit 89862d6

Please sign in to comment.