MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / TypingFunctions

Function TypingFunctions

apps/web/ui/Thread/UsersTyping.tsx:37–81  ·  view source on GitHub ↗
({
  isUserTyping,
  setUserTyping,
  userTyping,
  currentUser,
}: {
  isUserTyping: boolean;
  setUserTyping: React.Dispatch<React.SetStateAction<boolean>>;
  userTyping: ({
    typing,
    username,
  }: {
    typing: boolean;
    username: string;
  }) => void;
  currentUser: SerializedUser | null;
})

Source from the content-addressed store, hash-verified

35}
36
37export function TypingFunctions({
38 isUserTyping,
39 setUserTyping,
40 userTyping,
41 currentUser,
42}: {
43 isUserTyping: boolean;
44 setUserTyping: React.Dispatch<React.SetStateAction<boolean>>;
45 userTyping: ({
46 typing,
47 username,
48 }: {
49 typing: boolean;
50 username: string;
51 }) => void;
52 currentUser: SerializedUser | null;
53}) {
54 let typingTimer: NodeJS.Timeout;
55
56 const userStartsTyping = function () {
57 if (isUserTyping) {
58 return;
59 }
60 setUserTyping(true);
61 userTyping({ typing: true, username: currentUser?.displayName! });
62 };
63
64 const userStopsTyping = function () {
65 clearTimeout(typingTimer);
66 setUserTyping(false);
67 userTyping({ typing: false, username: currentUser?.displayName! });
68 };
69
70 const onKeyDown = () => {
71 userStartsTyping();
72 clearTimeout(typingTimer);
73 };
74
75 const onKeyUp = () => {
76 clearTimeout(typingTimer);
77 typingTimer = setTimeout(userStopsTyping, typingTimeout);
78 };
79
80 return { onKeyDown, onKeyUp };
81}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected