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