|
| 1 | +import React, { useCallback, useEffect, useRef, useState } from 'react'; |
| 2 | + |
| 3 | +type AppSettingsViewProps = { |
| 4 | + title: string; |
| 5 | + onUpdateTitle: (next: string, isManual?: boolean) => Promise<void> | void; |
| 6 | + onDownloadHtml: () => void; |
| 7 | +}; |
| 8 | + |
| 9 | +const AppSettingsView: React.FC<AppSettingsViewProps> = ({ |
| 10 | + title, |
| 11 | + onUpdateTitle, |
| 12 | + onDownloadHtml, |
| 13 | +}) => { |
| 14 | + const [isEditingName, setIsEditingName] = useState(false); |
| 15 | + const [editedName, setEditedName] = useState(title); |
| 16 | + const nameInputRef = useRef<HTMLInputElement>(null); |
| 17 | + |
| 18 | + useEffect(() => { |
| 19 | + setEditedName(title); |
| 20 | + }, [title]); |
| 21 | + |
| 22 | + const handleEditNameStart = useCallback(() => { |
| 23 | + setIsEditingName(true); |
| 24 | + setTimeout(() => { |
| 25 | + nameInputRef.current?.focus(); |
| 26 | + nameInputRef.current?.select(); |
| 27 | + }, 0); |
| 28 | + }, []); |
| 29 | + |
| 30 | + const handleNameSave = useCallback(async () => { |
| 31 | + const trimmedName = editedName.trim(); |
| 32 | + if (trimmedName && trimmedName !== title) { |
| 33 | + await onUpdateTitle(trimmedName, true); // Mark as manually set |
| 34 | + } |
| 35 | + setIsEditingName(false); |
| 36 | + }, [editedName, title, onUpdateTitle]); |
| 37 | + |
| 38 | + const handleNameCancel = useCallback(() => { |
| 39 | + setEditedName(title); |
| 40 | + setIsEditingName(false); |
| 41 | + }, [title]); |
| 42 | + |
| 43 | + const handleNameKeyDown = useCallback( |
| 44 | + (e: React.KeyboardEvent<HTMLInputElement>) => { |
| 45 | + if (e.key === 'Enter') { |
| 46 | + handleNameSave(); |
| 47 | + } else if (e.key === 'Escape') { |
| 48 | + handleNameCancel(); |
| 49 | + } |
| 50 | + }, |
| 51 | + [handleNameSave, handleNameCancel] |
| 52 | + ); |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="flex h-full justify-center p-8 pt-16"> |
| 56 | + <div className="w-full max-w-2xl"> |
| 57 | + <h2 className="text-light-primary dark:text-dark-primary mb-6 text-center text-2xl font-semibold"> |
| 58 | + App Settings |
| 59 | + </h2> |
| 60 | + |
| 61 | + <div className="space-y-6"> |
| 62 | + <div className="bg-light-background-01 dark:bg-dark-background-01 border-light-decorative-01 dark:border-dark-decorative-01 rounded-lg border p-6"> |
| 63 | + <h3 className="text-light-primary dark:text-dark-primary mb-4 text-lg font-medium"> |
| 64 | + General Settings |
| 65 | + </h3> |
| 66 | + <div className="space-y-4"> |
| 67 | + <div className="space-y-1"> |
| 68 | + <label className="text-light-primary dark:text-dark-primary block text-sm font-semibold"> |
| 69 | + App Name |
| 70 | + </label> |
| 71 | + {isEditingName ? ( |
| 72 | + <div className="flex items-center gap-2"> |
| 73 | + <input |
| 74 | + ref={nameInputRef} |
| 75 | + type="text" |
| 76 | + value={editedName} |
| 77 | + onChange={(e) => setEditedName(e.target.value)} |
| 78 | + onKeyDown={handleNameKeyDown} |
| 79 | + onBlur={handleNameSave} |
| 80 | + className="dark:bg-dark-background-00 text-light-primary dark:text-dark-primary flex-1 rounded border-2 border-blue-500 bg-white px-3 py-2 text-sm shadow-sm transition-colors focus:border-blue-600 focus:ring-2 focus:ring-blue-500/30 focus:outline-none dark:border-blue-400 dark:focus:border-blue-300 dark:focus:ring-blue-400/30" |
| 81 | + placeholder="Enter app name" |
| 82 | + /> |
| 83 | + <button |
| 84 | + onClick={handleNameSave} |
| 85 | + className="hover:bg-light-decorative-01 dark:hover:bg-dark-decorative-01 rounded p-1 text-green-600 dark:text-green-400" |
| 86 | + title="Save" |
| 87 | + > |
| 88 | + <svg |
| 89 | + className="h-4 w-4" |
| 90 | + fill="none" |
| 91 | + stroke="currentColor" |
| 92 | + viewBox="0 0 24 24" |
| 93 | + > |
| 94 | + <path |
| 95 | + strokeLinecap="round" |
| 96 | + strokeLinejoin="round" |
| 97 | + strokeWidth={2} |
| 98 | + d="M5 13l4 4L19 7" |
| 99 | + /> |
| 100 | + </svg> |
| 101 | + </button> |
| 102 | + <button |
| 103 | + onClick={handleNameCancel} |
| 104 | + className="hover:bg-light-decorative-01 dark:hover:bg-dark-decorative-01 rounded p-1 text-red-600 dark:text-red-400" |
| 105 | + title="Cancel" |
| 106 | + > |
| 107 | + <svg |
| 108 | + className="h-4 w-4" |
| 109 | + fill="none" |
| 110 | + stroke="currentColor" |
| 111 | + viewBox="0 0 24 24" |
| 112 | + > |
| 113 | + <path |
| 114 | + strokeLinecap="round" |
| 115 | + strokeLinejoin="round" |
| 116 | + strokeWidth={2} |
| 117 | + d="M6 18L18 6M6 6l12 12" |
| 118 | + /> |
| 119 | + </svg> |
| 120 | + </button> |
| 121 | + </div> |
| 122 | + ) : ( |
| 123 | + <div className="flex items-center gap-2"> |
| 124 | + <div className="dark:bg-dark-background-01 dark:border-dark-decorative-01 text-light-primary dark:text-dark-primary flex-1 cursor-default rounded border border-gray-200 bg-gray-50 px-3 py-2 font-medium"> |
| 125 | + {title} |
| 126 | + </div> |
| 127 | + <button |
| 128 | + onClick={handleEditNameStart} |
| 129 | + className="bg-light-background-01 dark:bg-dark-decorative-01 text-light-secondary dark:text-dark-secondary hover:bg-light-background-02 dark:hover:bg-dark-decorative-00 focus:ring-light-border-01 dark:focus:ring-dark-border-01 rounded-md px-4 py-2 text-sm font-semibold shadow transition-colors focus:ring-1 focus:outline-none" |
| 130 | + > |
| 131 | + Edit |
| 132 | + </button> |
| 133 | + </div> |
| 134 | + )} |
| 135 | + </div> |
| 136 | + |
| 137 | + <div className="opacity-60"> |
| 138 | + <div className="text-light-primary dark:text-dark-primary mb-1 flex items-center gap-2 font-medium"> |
| 139 | + Custom Domain |
| 140 | + <span className="inline-flex items-center rounded-full bg-gradient-to-r from-purple-500 to-pink-500 px-2 py-0.5 text-xs font-medium text-white"> |
| 141 | + ✨ Pro |
| 142 | + </span> |
| 143 | + <span className="inline-flex items-center rounded-full bg-orange-500 px-2 py-0.5 text-xs font-medium text-white"> |
| 144 | + 🚀 Soon |
| 145 | + </span> |
| 146 | + </div> |
| 147 | + <div className="text-light-primary/70 dark:text-dark-primary/70 text-sm"> |
| 148 | + {title !== 'Untitled App' |
| 149 | + ? `${title.toLowerCase().replace(/\s+/g, '-')}.vibesdiy.app` |
| 150 | + : 'app-name.vibesdiy.app'} |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + |
| 156 | + <div className="bg-light-background-01 dark:bg-dark-background-01 border-light-decorative-01 dark:border-dark-decorative-01 rounded-lg border p-6"> |
| 157 | + <h3 className="text-light-primary dark:text-dark-primary mb-4 text-lg font-medium"> |
| 158 | + Export Options |
| 159 | + </h3> |
| 160 | + <div className="space-y-3"> |
| 161 | + <div |
| 162 | + className="bg-light-background-00 dark:bg-dark-background-00 border-light-decorative-01 dark:border-dark-decorative-01 hover:bg-light-decorative-01 dark:hover:bg-dark-decorative-01 flex cursor-pointer items-center rounded-lg border p-4 transition-colors" |
| 163 | + onClick={onDownloadHtml} |
| 164 | + > |
| 165 | + <div className="flex-1"> |
| 166 | + <div className="text-light-primary dark:text-dark-primary font-medium"> |
| 167 | + Download html |
| 168 | + </div> |
| 169 | + <div className="text-light-primary/70 dark:text-dark-primary/70 text-sm"> |
| 170 | + Just open it in your browser. |
| 171 | + </div> |
| 172 | + </div> |
| 173 | + </div> |
| 174 | + </div> |
| 175 | + </div> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + </div> |
| 179 | + ); |
| 180 | +}; |
| 181 | + |
| 182 | +export default AppSettingsView; |
0 commit comments