TwitchClone / src / utils / helpers / handleTitle / index.tsx
index.tsx
Raw
import { UseMutationResult } from "@tanstack/react-query";
import { api } from "../../api";
import { SetStateAction } from "react";

// const handleTitleChange = (e: any ) => {
export const handleTitleChange = (
  e: React.ChangeEvent<HTMLInputElement>,
  setStreamTitle: React.Dispatch<SetStateAction<string>>
) => {
  setStreamTitle(e.target.value);
};

export const handleTitleBlur = (
  creatorId: string,
  setIsEditingTitle: React.Dispatch<SetStateAction<boolean>>,
  title: string,
  playbackId: string,
  id: string,
  updateTitleMutation: ReturnType<typeof api.lambda.updateVideo.useMutation>
) => {
  setIsEditingTitle(false);

  void updateTitleMutation.mutateAsync({ id, playbackId, title, creatorId });
};

// const handleTitleKeyPress = (e: any) => {
export const handleTitleKeyPress = (
  e: React.KeyboardEvent<HTMLInputElement>,
  setIsEditingTitle: React.Dispatch<SetStateAction<boolean>>
) => {
  if (e.key === "Enter") {
    setIsEditingTitle(false);
  }
};