feat: disable copy button unless all fields are set (#2196)
This commit is contained in:
@@ -7,6 +7,7 @@ import Back from './icons/Back';
|
|||||||
import { Bars } from './icons/Bars';
|
import { Bars } from './icons/Bars';
|
||||||
import { Geese } from './icons/Geese';
|
import { Geese } from './icons/Geese';
|
||||||
import Copy from './icons/Copy';
|
import Copy from './icons/Copy';
|
||||||
|
import Check from './icons/Check';
|
||||||
import { useConfig } from '../components/ConfigContext';
|
import { useConfig } from '../components/ConfigContext';
|
||||||
import { settingsV2Enabled } from '../flags';
|
import { settingsV2Enabled } from '../flags';
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
|||||||
config?.extensions?.map((e) => e.id) || []
|
config?.extensions?.map((e) => e.id) || []
|
||||||
);
|
);
|
||||||
const [newActivity, setNewActivity] = useState('');
|
const [newActivity, setNewActivity] = useState('');
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
// Section visibility state
|
// Section visibility state
|
||||||
const [activeSection, setActiveSection] = useState<
|
const [activeSection, setActiveSection] = useState<
|
||||||
@@ -150,6 +152,20 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
|||||||
|
|
||||||
const deeplink = generateDeepLink(getCurrentConfig());
|
const deeplink = generateDeepLink(getCurrentConfig());
|
||||||
|
|
||||||
|
const handleCopy = () => {
|
||||||
|
// Copy the text to the clipboard
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(deeplink)
|
||||||
|
.then(() => {
|
||||||
|
setCopied(true); // Show the check mark
|
||||||
|
// Reset to normal after 2 seconds (2000 milliseconds)
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Failed to copy the text:', err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Render expanded section content
|
// Render expanded section content
|
||||||
const renderSectionContent = () => {
|
const renderSectionContent = () => {
|
||||||
switch (activeSection) {
|
switch (activeSection) {
|
||||||
@@ -367,8 +383,16 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
|||||||
{/* Deep Link Display */}
|
{/* Deep Link Display */}
|
||||||
<div className="w-full p-4 bg-bgSubtle rounded-lg flex items-center justify-between">
|
<div className="w-full p-4 bg-bgSubtle rounded-lg flex items-center justify-between">
|
||||||
<code className="text-sm text-textSubtle truncate">{deeplink}</code>
|
<code className="text-sm text-textSubtle truncate">{deeplink}</code>
|
||||||
<button onClick={() => navigator.clipboard.writeText(deeplink)} className="ml-2">
|
<button
|
||||||
<Copy className="w-5 h-5 text-iconSubtle" />
|
onClick={handleCopy}
|
||||||
|
className="ml-2 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
disabled={!title.trim() || !description.trim()}
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<Check className="w-5 h-5 text-green-500" />
|
||||||
|
) : (
|
||||||
|
<Copy className="w-5 h-5 text-iconSubtle" />
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user