mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 16:51:33 +10:00
debounce in profile icon
This commit is contained in:
@ -12,11 +12,13 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
Input,
|
Input,
|
||||||
} from "@reactive-resume/ui";
|
} from "@reactive-resume/ui";
|
||||||
import { useForm } from "react-hook-form";
|
import { ControllerRenderProps, useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { SectionDialog } from "../sections/shared/section-dialog";
|
import { SectionDialog } from "../sections/shared/section-dialog";
|
||||||
import { URLInput } from "../sections/shared/url-input";
|
import { URLInput } from "../sections/shared/url-input";
|
||||||
|
import { useDebounceValue } from "usehooks-ts";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
const formSchema = profileSchema;
|
const formSchema = profileSchema;
|
||||||
|
|
||||||
@ -28,6 +30,29 @@ export const ProfilesDialog = () => {
|
|||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [iconSrc, setIconSrc] = useDebounceValue("", 400)
|
||||||
|
|
||||||
|
const handleIconChange = useCallback((event: React.ChangeEvent<HTMLInputElement>, field: ControllerRenderProps<{
|
||||||
|
id: string;
|
||||||
|
visible: boolean;
|
||||||
|
network: string;
|
||||||
|
username: string;
|
||||||
|
icon: string;
|
||||||
|
url: {
|
||||||
|
label: string;
|
||||||
|
href: string;
|
||||||
|
};
|
||||||
|
}, "icon">) => {
|
||||||
|
field.onChange(event);
|
||||||
|
if (event.target.value === "") {
|
||||||
|
setIconSrc("");
|
||||||
|
} else {
|
||||||
|
setIconSrc(`https://cdn.simpleicons.org/${event.target.value}`);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionDialog<FormValues> id="profiles" form={form} defaultValues={defaultProfile}>
|
<SectionDialog<FormValues> id="profiles" form={form} defaultValues={defaultProfile}>
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
@ -83,14 +108,14 @@ export const ProfilesDialog = () => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<div className="flex items-center gap-x-2">
|
<div className="flex items-center gap-x-2">
|
||||||
<Avatar className="size-8 bg-white">
|
<Avatar className="size-8 bg-white">
|
||||||
{field.value && (
|
{iconSrc && (
|
||||||
<AvatarImage
|
<AvatarImage
|
||||||
className="p-1.5"
|
className="p-1.5"
|
||||||
src={`https://cdn.simpleicons.org/${field.value}`}
|
src={iconSrc}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<Input {...field} id="iconSlug" placeholder="linkedin" />
|
<Input {...field} id="iconSlug" placeholder="linkedin" onChange={(e) => handleIconChange(e, field)} />
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
Reference in New Issue
Block a user