Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions src/components/ToastTextToCad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -380,7 +376,7 @@ export function ToastTextToCadSuccess({
toast.dismiss(toastId)
}}
>
{hasCopied ? 'Close' : 'Reject'}
Reject
</ActionButton>
{isDesktop() ? (
<ActionButton
Expand All @@ -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)

// Reset the button text after 5 seconds
setTimeout(() => {
setShowCopiedUi(false)
}, 5000)
const code = data.code || '// no code found'

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>
Expand Down
Loading