Spaces:
Sleeping
Sleeping
Tina Tarighian
commited on
Commit
·
b4dece4
1
Parent(s):
103fcd2
save button on mobile
Browse files- components/PromptEditor.js +43 -24
components/PromptEditor.js
CHANGED
|
@@ -10,24 +10,41 @@ const PromptEditor = ({ customPrompt, setCustomPrompt, isMac, isMobile }) => {
|
|
| 10 |
setIsCollapsed(isMobile);
|
| 11 |
}, [isMobile]);
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return (
|
| 14 |
<div className={`w-full max-w-4xl ${isMobile ? 'mt-4' : 'mb-4'}`}>
|
| 15 |
<div
|
| 16 |
-
className="flex justify-between items-center mb-1
|
| 17 |
-
onClick={() => setIsCollapsed(!isCollapsed)}
|
| 18 |
>
|
| 19 |
-
<label
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
System Prompt
|
| 21 |
</label>
|
| 22 |
<div className="flex items-center">
|
| 23 |
{!isEditingPrompt && !isCollapsed && (
|
| 24 |
<button
|
| 25 |
onClick={(e) => {
|
| 26 |
-
e.
|
|
|
|
| 27 |
setTempPrompt(customPrompt);
|
| 28 |
setIsEditingPrompt(true);
|
| 29 |
}}
|
| 30 |
-
className="text-sm text-blue-600 hover:text-blue-800 flex items-center mr-2"
|
| 31 |
>
|
| 32 |
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 33 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
|
|
@@ -35,23 +52,29 @@ const PromptEditor = ({ customPrompt, setCustomPrompt, isMac, isMobile }) => {
|
|
| 35 |
Edit
|
| 36 |
</button>
|
| 37 |
)}
|
| 38 |
-
{/* Down/Up caret icon */}
|
| 39 |
-
<
|
| 40 |
-
|
| 41 |
-
className=
|
| 42 |
-
|
| 43 |
-
viewBox="0 0 24 24"
|
| 44 |
-
stroke="currentColor"
|
| 45 |
>
|
| 46 |
-
<
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
</div>
|
| 49 |
</div>
|
| 50 |
|
| 51 |
{!isCollapsed && (
|
| 52 |
<>
|
| 53 |
{isEditingPrompt ? (
|
| 54 |
-
<div>
|
| 55 |
<textarea
|
| 56 |
id="system-prompt"
|
| 57 |
value={tempPrompt}
|
|
@@ -60,8 +83,7 @@ const PromptEditor = ({ customPrompt, setCustomPrompt, isMac, isMobile }) => {
|
|
| 60 |
// Save on Ctrl+Enter or Cmd+Enter
|
| 61 |
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
| 62 |
e.preventDefault();
|
| 63 |
-
|
| 64 |
-
setIsEditingPrompt(false);
|
| 65 |
}
|
| 66 |
}}
|
| 67 |
className="w-full p-3 border border-gray-300 rounded-lg shadow-sm focus:ring-blue-500 focus:border-blue-500 text-sm"
|
|
@@ -73,17 +95,14 @@ const PromptEditor = ({ customPrompt, setCustomPrompt, isMac, isMobile }) => {
|
|
| 73 |
Tip: Press {isMac ? '⌘' : 'Ctrl'}+Enter to save
|
| 74 |
</span>
|
| 75 |
<button
|
| 76 |
-
onClick={
|
| 77 |
-
className="px-
|
| 78 |
>
|
| 79 |
Cancel
|
| 80 |
</button>
|
| 81 |
<button
|
| 82 |
-
onClick={
|
| 83 |
-
|
| 84 |
-
setIsEditingPrompt(false);
|
| 85 |
-
}}
|
| 86 |
-
className="px-3 py-1 text-sm text-white bg-blue-600 rounded-md hover:bg-blue-700"
|
| 87 |
>
|
| 88 |
Save
|
| 89 |
</button>
|
|
|
|
| 10 |
setIsCollapsed(isMobile);
|
| 11 |
}, [isMobile]);
|
| 12 |
|
| 13 |
+
const handleSave = (e) => {
|
| 14 |
+
e.preventDefault();
|
| 15 |
+
e.stopPropagation();
|
| 16 |
+
setCustomPrompt(tempPrompt);
|
| 17 |
+
setIsEditingPrompt(false);
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
const handleCancel = (e) => {
|
| 21 |
+
e.preventDefault();
|
| 22 |
+
e.stopPropagation();
|
| 23 |
+
setIsEditingPrompt(false);
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
return (
|
| 27 |
<div className={`w-full max-w-4xl ${isMobile ? 'mt-4' : 'mb-4'}`}>
|
| 28 |
<div
|
| 29 |
+
className="flex justify-between items-center mb-1"
|
|
|
|
| 30 |
>
|
| 31 |
+
<label
|
| 32 |
+
htmlFor="system-prompt"
|
| 33 |
+
className="block text-sm font-medium text-gray-700 cursor-pointer flex-grow"
|
| 34 |
+
onClick={() => setIsCollapsed(!isCollapsed)}
|
| 35 |
+
>
|
| 36 |
System Prompt
|
| 37 |
</label>
|
| 38 |
<div className="flex items-center">
|
| 39 |
{!isEditingPrompt && !isCollapsed && (
|
| 40 |
<button
|
| 41 |
onClick={(e) => {
|
| 42 |
+
e.preventDefault();
|
| 43 |
+
e.stopPropagation();
|
| 44 |
setTempPrompt(customPrompt);
|
| 45 |
setIsEditingPrompt(true);
|
| 46 |
}}
|
| 47 |
+
className="text-sm text-blue-600 hover:text-blue-800 flex items-center mr-2 p-2"
|
| 48 |
>
|
| 49 |
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 50 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
|
|
|
|
| 52 |
Edit
|
| 53 |
</button>
|
| 54 |
)}
|
| 55 |
+
{/* Down/Up caret icon with increased touch target */}
|
| 56 |
+
<button
|
| 57 |
+
onClick={() => setIsCollapsed(!isCollapsed)}
|
| 58 |
+
className="p-2"
|
| 59 |
+
aria-label={isCollapsed ? 'Expand prompt' : 'Collapse prompt'}
|
|
|
|
|
|
|
| 60 |
>
|
| 61 |
+
<svg
|
| 62 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 63 |
+
className={`h-5 w-5 text-gray-500 transition-transform duration-200 ${isCollapsed ? '' : 'transform rotate-180'}`}
|
| 64 |
+
fill="none"
|
| 65 |
+
viewBox="0 0 24 24"
|
| 66 |
+
stroke="currentColor"
|
| 67 |
+
>
|
| 68 |
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
| 69 |
+
</svg>
|
| 70 |
+
</button>
|
| 71 |
</div>
|
| 72 |
</div>
|
| 73 |
|
| 74 |
{!isCollapsed && (
|
| 75 |
<>
|
| 76 |
{isEditingPrompt ? (
|
| 77 |
+
<div onClick={(e) => e.stopPropagation()}>
|
| 78 |
<textarea
|
| 79 |
id="system-prompt"
|
| 80 |
value={tempPrompt}
|
|
|
|
| 83 |
// Save on Ctrl+Enter or Cmd+Enter
|
| 84 |
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
| 85 |
e.preventDefault();
|
| 86 |
+
handleSave(e);
|
|
|
|
| 87 |
}
|
| 88 |
}}
|
| 89 |
className="w-full p-3 border border-gray-300 rounded-lg shadow-sm focus:ring-blue-500 focus:border-blue-500 text-sm"
|
|
|
|
| 95 |
Tip: Press {isMac ? '⌘' : 'Ctrl'}+Enter to save
|
| 96 |
</span>
|
| 97 |
<button
|
| 98 |
+
onClick={handleCancel}
|
| 99 |
+
className="px-4 py-2 text-sm text-gray-600 border border-gray-300 rounded-md hover:bg-gray-100 min-w-[60px]"
|
| 100 |
>
|
| 101 |
Cancel
|
| 102 |
</button>
|
| 103 |
<button
|
| 104 |
+
onClick={handleSave}
|
| 105 |
+
className="px-4 py-2 text-sm text-white bg-blue-600 rounded-md hover:bg-blue-700 min-w-[60px]"
|
|
|
|
|
|
|
|
|
|
| 106 |
>
|
| 107 |
Save
|
| 108 |
</button>
|