File size: 2,569 Bytes
baa4c21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useStore } from '@nanostores/react';
import { TooltipProvider } from '@radix-ui/react-tooltip';
import WithTooltip from '~/components/ui/Tooltip';
import { useEditChatDescription } from '~/lib/hooks';
import { description as descriptionStore } from '~/lib/persistence';

export function ChatDescription() {
  const initialDescription = useStore(descriptionStore)!;

  const { editing, handleChange, handleBlur, handleSubmit, handleKeyDown, currentDescription, toggleEditMode } =
    useEditChatDescription({
      initialDescription,
      syncWithGlobalStore: true,
    });

  if (!initialDescription) {
    // doing this to prevent showing edit button until chat description is set
    return null;
  }

  return (
    <div className="flex items-center justify-center">

      {editing ? (

        <form onSubmit={handleSubmit} className="flex items-center justify-center">

          <input

            type="text"

            className="bg-bolt-elements-background-depth-1 text-bolt-elements-textPrimary rounded px-2 mr-2 w-fit"

            autoFocus

            value={currentDescription}

            onChange={handleChange}

            onBlur={handleBlur}

            onKeyDown={handleKeyDown}

            style={{ width: `${Math.max(currentDescription.length * 8, 100)}px` }}

          />

          <TooltipProvider>

            <WithTooltip tooltip="Save title">

              <div className="flex justify-between items-center p-2 rounded-md bg-bolt-elements-item-backgroundAccent">

                <button

                  type="submit"

                  className="i-ph:check-bold scale-110 hover:text-bolt-elements-item-contentAccent"

                  onMouseDown={handleSubmit}

                />

              </div>

            </WithTooltip>

          </TooltipProvider>

        </form>

      ) : (

        <>

          {currentDescription}

          <TooltipProvider>

            <WithTooltip tooltip="Rename chat">

              <div className="flex justify-between items-center p-2 rounded-md bg-bolt-elements-item-backgroundAccent ml-2">

                <button

                  type="button"

                  className="i-ph:pencil-fill scale-110 hover:text-bolt-elements-item-contentAccent"

                  onClick={(event) => {

                    event.preventDefault();

                    toggleEditMode();

                  }}

                />

              </div>

            </WithTooltip>

          </TooltipProvider>

        </>
      )}
    </div>
  );
}