MCPcopy Create free account
hub / github.com/3eif/gitmotion / Component

Function Component

website/src/components/gource-input.tsx:35–378  ·  view source on GitHub ↗
({
  onSubmit,
  onCancel,
  isLoading,
  isGenerating,
  initialUrl = "",
  initialSettings,
}: GourceInputProps)

Source from the content-addressed store, hash-verified

33}
34
35export default function Component({
36 onSubmit,
37 onCancel,
38 isLoading,
39 isGenerating,
40 initialUrl = "",
41 initialSettings,
42}: GourceInputProps) {
43 const [repoUrl, setRepoUrl] = useState(initialUrl);
44 const [isPrivate, setIsPrivate] = useState(false);
45 const [accessKey, setAccessKey] = useState("");
46 const [isValidUrl, setIsValidUrl] = useState(false);
47 const [isSubmitting, setIsSubmitting] = useState(false);
48 const [isFiltersOpen, setIsFiltersOpen] = useState(false);
49 const [settings, setSettings] = useState<GourceSettings>(
50 initialSettings || {
51 show_file_extension_key: false,
52 show_usernames: true,
53 show_dirnames: true,
54 dir_font_size: 11,
55 file_font_size: 10,
56 user_font_size: 12,
57 }
58 );
59
60 const inputRef = useRef<HTMLInputElement>(null);
61
62 useEffect(() => {
63 if (initialSettings) {
64 setSettings(initialSettings);
65 }
66 }, [initialSettings]);
67
68 useEffect(() => {
69 const urlRegex =
70 /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
71 setIsValidUrl(urlRegex.test(repoUrl));
72 }, [repoUrl]);
73
74 useEffect(() => {
75 if (initialUrl) {
76 setRepoUrl(initialUrl);
77 }
78 }, [initialUrl]);
79
80 useEffect(() => {
81 if (inputRef.current) {
82 inputRef.current.focus();
83 }
84 }, []);
85
86 async function handleSubmit(e: FormEvent<HTMLFormElement>) {
87 e.preventDefault();
88 if (isValidUrl && !isSubmitting && !isLoading && !isGenerating) {
89 setIsSubmitting(true);
90 try {
91 await onSubmit(repoUrl, isPrivate ? accessKey : undefined, settings);
92 } catch (error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected