mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-02-14 23:02:07 +00:00
## AI Generated code and Descriptions Improve website performance and efficiency by reducing bundle sizes and implementing caching strategies. * **next.config.ts**: Add `compression` middleware to enable gzip compression for responses. * **Lazy Loading**: Implement lazy loading for images in `app/(platform)/(dashboard)/board/[boardId]/_components/board-update-image.tsx` using the `loading="lazy"` attribute. Add `react-lazyload` library for lazy loading components in `app/(platform)/(dashboard)/board/[boardId]/_components/list-item.tsx` and wrap list items with `LazyLoad` component. * **Database Query Optimization**: Optimize database queries in `actions/copy-card/index.ts`, `actions/copy-list/index.ts`, `actions/create-board/index.ts`, `actions/create-card/index.ts`, `actions/create-list/index.ts`, `actions/delete-board/index.ts`, `actions/delete-card/index.ts`, `actions/delete-list/index.ts`, `actions/stripe-redirect/index.ts`, `actions/update-board/index.ts`, `actions/update-card-order/index.ts`, `actions/update-card/index.ts`, and `actions/update-list/index.ts` by adding appropriate indexes and using `select` to fetch only required fields. * **Dependencies**: Update `package.json` to include `compression` and `react-lazyload` dependencies. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ahmadk953/tasko?shareId=XXXX-XXXX-XXXX-XXXX).
98 lines
2.5 KiB
TypeScript
98 lines
2.5 KiB
TypeScript
import { useState } from 'react';
|
|
import { useRouter } from 'next/navigation';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useForm } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
|
|
import { updateBoard } from '@/actions/update-board';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Form, FormControl, FormField, FormItem, FormLabel } from '@/components/ui/form';
|
|
import { Input } from '@/components/ui/input';
|
|
import { useToast } from '@/components/ui/use-toast';
|
|
import { cn } from '@/lib/utils';
|
|
import { images } from '@/constants/images';
|
|
|
|
const formSchema = z.object({
|
|
image: z.string().min(1, {
|
|
message: 'Image is required',
|
|
}),
|
|
});
|
|
|
|
interface BoardUpdateImageProps {
|
|
boardId: string;
|
|
image: string;
|
|
}
|
|
|
|
export function BoardUpdateImage({ boardId, image }: BoardUpdateImageProps) {
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const { toast } = useToast();
|
|
const router = useRouter();
|
|
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
image,
|
|
},
|
|
});
|
|
|
|
async function onSubmit(values: z.infer<typeof formSchema>) {
|
|
setIsLoading(true);
|
|
|
|
const response = await updateBoard({
|
|
id: boardId,
|
|
image: values.image,
|
|
});
|
|
|
|
setIsLoading(false);
|
|
|
|
if (response?.error) {
|
|
return toast({
|
|
title: 'Something went wrong.',
|
|
description: response.error,
|
|
variant: 'destructive',
|
|
});
|
|
}
|
|
|
|
toast({
|
|
description: 'Board image updated.',
|
|
});
|
|
|
|
router.refresh();
|
|
}
|
|
|
|
return (
|
|
<Form {...form}>
|
|
<form
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className="space-y-8"
|
|
>
|
|
<FormField
|
|
control={form.control}
|
|
name="image"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Image</FormLabel>
|
|
<FormControl>
|
|
<div className="relative">
|
|
<Input {...field} />
|
|
<img
|
|
src={field.value}
|
|
alt="Board Image"
|
|
className="mt-4 w-full h-auto rounded-lg"
|
|
loading="lazy"
|
|
/>
|
|
</div>
|
|
</FormControl>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<Button type="submit" disabled={isLoading}>
|
|
{isLoading && (
|
|
<span className="mr-2 h-4 w-4 animate-spin">🔄</span>
|
|
)}
|
|
Update Image
|
|
</Button>
|
|
</form>
|
|
</Form>
|
|
);
|
|
}
|