summaryrefslogtreecommitdiff
path: root/src/pages/ChooseArt.tsx
blob: fab6d79de8210841287f2d0f249971da3b809967 (plain)
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
import type React from 'react';
import { useEffect, useRef, useState } from 'react';

export interface ChooseArtProps {
    artSubmissionCallback: (art: string) => void;
}

export const ChooseArt: React.FC<ChooseArtProps> = ({
    artSubmissionCallback,
}) => {
    const [art, setArt] = useState('');
    const promptRef = useRef<HTMLTextAreaElement>(null);

    useEffect(() => {
        if (!promptRef.current) {
            return;
        }
        // Automatically focus the textarea when the component mounts
        promptRef.current.focus();
    }, [promptRef]);

    const handleSubmit = () => {
        if (!art.trim()) {
            return;
        }
        artSubmissionCallback(art);
    };

    return (
        <div>
            <textarea
                ref={promptRef}
                value={art}
                onChange={(e) => setArt(e.target.value)}
                placeholder='paste your ascii art here...'
                rows={15}
                cols={80}
            />
            <div className={"maybe-visible " + (art.trim() ? "visible" : "invisible")}>
                <hr />
                <button  onClick={handleSubmit}>color!</button>
            </div>
        </div>
    );
};