6458 Browser text-to-CAD should overwrite project and zoom to fit new model (#6626)

change 'Copy To Clipboard' -> 'Replace current file' for textToCAD in browser
This commit is contained in:
Andrew Varga
2025-05-06 20:17:46 +02:00
committed by GitHub
parent e356cd34e3
commit a04f7e9923

View File

@ -2,7 +2,7 @@ import type {
TextToCadIteration_type,
TextToCad_type,
} from '@kittycad/lib/dist/types/src/models'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef } from 'react'
import toast from 'react-hot-toast'
import type { Mesh } from 'three'
import {
@ -165,8 +165,6 @@ export function ToastTextToCadSuccess({
const wrapperRef = useRef<HTMLDivElement | null>(null)
const canvasRef = useRef<HTMLCanvasElement | null>(null)
const animationRequestRef = useRef<number>()
const [hasCopied, setHasCopied] = useState(false)
const [showCopiedUi, setShowCopiedUi] = useState(false)
const modelId = data.id
const projectDirectoryPath = useProjectDirectoryPath()
@ -345,12 +343,10 @@ export function ToastTextToCadSuccess({
iconStart={{
icon: 'close',
}}
data-negative-button={hasCopied ? 'close' : 'reject'}
name={hasCopied ? 'Close' : 'Reject'}
data-negative-button="reject"
name="Reject"
onClick={() => {
if (!hasCopied) {
sendTelemetry(modelId, 'rejected', token).catch(reportRejection)
}
sendTelemetry(modelId, 'rejected', token).catch(reportRejection)
if (isDesktop()) {
// Delete the file from the project
@ -380,7 +376,7 @@ export function ToastTextToCadSuccess({
toast.dismiss(toastId)
}}
>
{hasCopied ? 'Close' : 'Reject'}
Reject
</ActionButton>
{isDesktop() ? (
<ActionButton
@ -404,24 +400,27 @@ export function ToastTextToCadSuccess({
<ActionButton
Element="button"
iconStart={{
icon: showCopiedUi ? 'clipboardCheckmark' : 'clipboardPlus',
icon: 'checkmark',
}}
name="Copy to clipboard"
name="Replace current file"
onClick={() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
sendTelemetry(modelId, 'accepted', token)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
navigator.clipboard.writeText(data.code || '// no code found')
setShowCopiedUi(true)
setHasCopied(true)
const code = data.code || '// no code found'
// Reset the button text after 5 seconds
setTimeout(() => {
setShowCopiedUi(false)
}, 5000)
systemIOActor.send({
type: SystemIOMachineEvents.createKCLFile,
data: {
requestedProjectName: projectName,
requestedCode: code,
requestedFileName: fileName,
},
})
toast.dismiss(toastId)
}}
>
{showCopiedUi ? 'Copied' : 'Copy to clipboard'}
Replace current file
</ActionButton>
)}
</div>