Skip to content

Commit

Permalink
Add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
khou22 committed Sep 21, 2023
1 parent 28edccf commit 0088e95
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};
70 changes: 35 additions & 35 deletions app/start/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client";
'use client';

import { NextPage } from "next";
import * as z from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import _ from "lodash";
import { NextPage } from 'next';
import * as z from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import _ from 'lodash';
import {
Form,
FormControl,
Expand All @@ -13,26 +13,26 @@ import {
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Textarea } from "@/components/ui/textarea";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { useCallback, useState } from "react";
import { QrGenerateRequest, QrGenerateResponse } from "@/utils/service";
import { QrCard } from "@/components/QrCard";
import { AlertCircle } from "lucide-react";
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
import LoadingDots from "@/components/ui/loadingdots";
import downloadQrCode from "@/utils/downloadQrCode";
import va from "@vercel/analytics";
import { useRouter } from "next/navigation";
import { PromptSuggestion } from "@/components/PromptSuggestion";
} from '@/components/ui/form';
import { Textarea } from '@/components/ui/textarea';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { useCallback, useState } from 'react';
import { QrGenerateRequest, QrGenerateResponse } from '@/utils/service';
import { QrCard } from '@/components/QrCard';
import { AlertCircle } from 'lucide-react';
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
import LoadingDots from '@/components/ui/loadingdots';
import downloadQrCode from '@/utils/downloadQrCode';
import va from '@vercel/analytics';
import { useRouter } from 'next/navigation';
import { PromptSuggestion } from '@/components/PromptSuggestion';

const promptSuggestions = [
"A city view with clouds",
"A beautiful glacier",
"A forest overlooking a mountain",
"A saharan desert",
'A city view with clouds',
'A beautiful glacier',
'A forest overlooking a mountain',
'A saharan desert',
];

const generateFormSchema = z.object({
Expand All @@ -50,20 +50,20 @@ const GeneratePage: NextPage = () => {

const form = useForm<GenerateFormValues>({
resolver: zodResolver(generateFormSchema),
mode: "onChange",
mode: 'onChange',

// Set default values so that the form inputs are controlled components.
defaultValues: {
url: "",
prompt: "",
url: '',
prompt: '',
},
});

const handleSuggestionClick = useCallback(
(suggestion: string) => {
form.setValue("prompt", suggestion);
form.setValue('prompt', suggestion);
},
[form]
[form],
);

const handleSubmit = useCallback(async (values: GenerateFormValues) => {
Expand All @@ -76,8 +76,8 @@ const GeneratePage: NextPage = () => {
url: values.url,
prompt: values.prompt,
};
const response = await fetch("/api/generate", {
method: "POST",
const response = await fetch('/api/generate', {
method: 'POST',
body: JSON.stringify(request),
});

Expand All @@ -90,13 +90,13 @@ const GeneratePage: NextPage = () => {
const data = await response.json();
setResponse(data);

va.track("Generated QR Code", {
va.track('Generated QR Code', {
prompt: values.prompt,
});

// router.push(`/s/${data.id}`);
} catch (error) {
va.track("Failed to generate", {
va.track('Failed to generate', {
prompt: values.prompt,
});
if (error instanceof Error) {
Expand Down Expand Up @@ -171,7 +171,7 @@ const GeneratePage: NextPage = () => {
className="inline-flex justify-center
max-w-[200px] mx-auto w-full"
>
{isLoading ? <LoadingDots color="white" /> : "Generate"}
{isLoading ? <LoadingDots color="white" /> : 'Generate'}
</Button>

{error && (
Expand Down Expand Up @@ -206,7 +206,7 @@ const GeneratePage: NextPage = () => {
<div className="flex justify-center gap-5 mt-4">
<Button
onClick={() =>
downloadQrCode(response.image_url, "qrCode")
downloadQrCode(response.image_url, 'qrCode')
}
>
Download
Expand Down
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"components": "@/components",
"utils": "@/lib/utils"
}
}
}
2 changes: 1 addition & 1 deletion components/PromptSuggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const PromptSuggestion: React.FC<PromptSuggestionProps> = ({
onClick={() => onClick()}
disabled={isLoading}
className={`border p-2 rounded-2xl ${
!isLoading ? "cursor-pointer" : "cursor-not-allowed"
!isLoading ? 'cursor-pointer' : 'cursor-not-allowed'
} hover:bg-gray-100 transition`}
>
{suggestion}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const alertVariants = cva(
defaultVariants: {
variant: 'default',
},
}
},
);

const Alert = React.forwardRef<
Expand Down
4 changes: 2 additions & 2 deletions components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const buttonVariants = cva(
variant: 'default',
size: 'default',
},
}
},
);

export interface ButtonProps
Expand All @@ -49,7 +49,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
{...props}
/>
);
}
},
);
Button.displayName = 'Button';

Expand Down
8 changes: 4 additions & 4 deletions components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ const Form = FormProvider;

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName;
};

const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
{} as FormFieldContextValue,
);

const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
Expand Down Expand Up @@ -67,7 +67,7 @@ type FormItemContextValue = {
};

const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
{} as FormItemContextValue,
);

const FormItem = React.forwardRef<
Expand Down
4 changes: 2 additions & 2 deletions components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
className
className,
)}
ref={ref}
{...props}
/>
);
}
},
);
Input.displayName = 'Input';

Expand Down
2 changes: 1 addition & 1 deletion components/ui/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '@/utils/utils';

const labelVariants = cva(
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70'
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
);

const Label = React.forwardRef<
Expand Down
4 changes: 2 additions & 2 deletions components/ui/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
<textarea
className={cn(
'flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
className
className,
)}
ref={ref}
{...props}
/>
);
}
},
);
Textarea.displayName = 'Textarea';

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"format": "prettier --write ."
},
"dependencies": {
"@hookform/resolvers": "^3.3.1",
Expand All @@ -29,6 +30,7 @@
"nanoid": "^5.0.1",
"next": "^13.5.2",
"postcss": "8.4.29",
"prettier": "^3.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.46.1",
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
4 changes: 2 additions & 2 deletions utils/ReplicateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ReplicateClient {
* Generate a QR code.
*/
generateQrCode = async (
request: QrCodeControlNetRequest
request: QrCodeControlNetRequest,
): Promise<string> => {
const output = (await this.replicate.run(
'zylim0702/qr_code_controlnet:628e604e13cf63d8ec58bd4d238474e8986b054bc5e1326e50995fdbc851c557',
Expand All @@ -28,7 +28,7 @@ export class ReplicateClient {
guidance_scale: request.guidance_scale,
negative_prompt: request.negative_prompt,
},
}
},
)) as QrCodeControlNetResponse;

if (!output) {
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export function cn(...inputs: ClassValue[]) {

export const nanoid = customAlphabet(
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
7
7,
);

0 comments on commit 0088e95

Please sign in to comment.