Skip to content

Commit

Permalink
feat: debounce onChangeConversationName
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry authored Feb 15, 2024
2 parents 7db6c78 + e37a31c commit 40a07a1
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions webapp/components/common/EditableItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,41 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { useState } from 'react';
import { Input } from '@/components/ui/input';
import useDebounceFunc from '@/hooks/useDebounceFunc';

export type EditableItemProps = {
id: string;
title: string;
className?: string;
editable?: boolean;
onChange?: (value: string, id: string) => void;
};

export default function EditableItem({
id,
title,
className,
editable = false,
onChange,
}: {
id: string;
title: string;
className?: string;
editable?: boolean;
onChange?: (value: string, id: string) => void;
}) {
}: EditableItemProps) {
const [changedValue, setChangedValue] = useState<string | undefined>(undefined);

const onDebouncedChange = (value: string) => {
onChange?.(value, id);
};

useDebounceFunc<string>(onDebouncedChange, changedValue, 500);
if (editable) {
return (
<Input
type="text"
className="line-clamp-1 h-auto w-full text-ellipsis border-none bg-transparent outline-none"
value={title}
value={changedValue || title}
onChange={(e) => {
e.preventDefault();
onChange?.(e.target.value, id);
setChangedValue(e.target.value);
}}
/>
);
Expand Down

0 comments on commit 40a07a1

Please sign in to comment.