2025-04-01 15:31:19 -07:00
|
|
|
import { useEffect, useState } from 'react'
|
2025-04-01 23:54:26 -07:00
|
|
|
import { useNavigate, useRouteLoaderData } from 'react-router-dom'
|
|
|
|
|
|
|
|
import { useLspContext } from '@src/components/LspProvider'
|
|
|
|
import { useFileContext } from '@src/hooks/useFileContext'
|
|
|
|
import { isKclEmptyOrOnlySettings } from '@src/lang/wasm'
|
|
|
|
import { APP_NAME } from '@src/lib/constants'
|
|
|
|
import { createAndOpenNewTutorialProject } from '@src/lib/desktopFS'
|
|
|
|
import { bracket } from '@src/lib/exampleKcl'
|
|
|
|
import { isDesktop } from '@src/lib/isDesktop'
|
|
|
|
import { PATHS } from '@src/lib/paths'
|
|
|
|
import { codeManager, kclManager } from '@src/lib/singletons'
|
|
|
|
import { Themes, getSystemTheme } from '@src/lib/theme'
|
|
|
|
import { reportRejection } from '@src/lib/trap'
|
|
|
|
import type { IndexLoaderData } from '@src/lib/types'
|
|
|
|
import { useSettings } from '@src/machines/appMachine'
|
|
|
|
import { onboardingPaths } from '@src/routes/Onboarding/paths'
|
|
|
|
|
|
|
|
import { OnboardingButtons, useDemoCode } from '@src/routes/Onboarding/utils'
|
2023-07-25 10:40:26 -04:00
|
|
|
|
2024-07-28 21:59:06 -04:00
|
|
|
/**
|
|
|
|
* Show either a welcome screen or a warning screen
|
|
|
|
* depending on if the user has code in the editor.
|
|
|
|
*/
|
|
|
|
export default function OnboardingIntroduction() {
|
|
|
|
const [shouldShowWarning, setShouldShowWarning] = useState(
|
2025-03-31 10:56:03 -04:00
|
|
|
!isKclEmptyOrOnlySettings(codeManager.code) && codeManager.code !== bracket
|
2024-07-28 21:59:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return shouldShowWarning ? (
|
|
|
|
<OnboardingResetWarning setShouldShowWarning={setShouldShowWarning} />
|
|
|
|
) : (
|
|
|
|
<OnboardingIntroductionInner />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
interface OnboardingResetWarningProps {
|
|
|
|
setShouldShowWarning: (arg: boolean) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnboardingResetWarning(props: OnboardingResetWarningProps) {
|
|
|
|
return (
|
|
|
|
<div className="fixed inset-0 z-50 grid place-content-center bg-chalkboard-110/50">
|
2025-02-07 11:30:36 -05:00
|
|
|
<div className="relative max-w-3xl p-8 rounded bg-chalkboard-10 dark:bg-chalkboard-90">
|
2024-08-16 07:15:42 -04:00
|
|
|
{!isDesktop() ? (
|
2024-07-28 21:59:06 -04:00
|
|
|
<OnboardingWarningWeb {...props} />
|
|
|
|
) : (
|
2024-08-02 15:38:39 -04:00
|
|
|
<OnboardingWarningDesktop {...props} />
|
2024-07-28 21:59:06 -04:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-08-02 15:38:39 -04:00
|
|
|
function OnboardingWarningDesktop(props: OnboardingResetWarningProps) {
|
2023-09-15 22:37:40 -04:00
|
|
|
const navigate = useNavigate()
|
2024-08-09 02:47:25 -04:00
|
|
|
const loaderData = useRouteLoaderData(PATHS.FILE) as IndexLoaderData
|
2024-08-02 15:38:39 -04:00
|
|
|
const { context: fileContext } = useFileContext()
|
|
|
|
const { onProjectClose, onProjectOpen } = useLspContext()
|
2023-07-25 10:40:26 -04:00
|
|
|
|
2024-08-02 15:38:39 -04:00
|
|
|
async function onAccept() {
|
|
|
|
onProjectClose(
|
|
|
|
loaderData.file || null,
|
|
|
|
fileContext.project.path || null,
|
|
|
|
false
|
2023-10-17 12:31:14 -04:00
|
|
|
)
|
2024-10-28 14:29:47 -04:00
|
|
|
await createAndOpenNewTutorialProject({ onProjectOpen, navigate })
|
2024-08-02 15:38:39 -04:00
|
|
|
props.setShouldShowWarning(false)
|
2023-09-15 22:37:40 -04:00
|
|
|
}
|
2024-07-28 21:59:06 -04:00
|
|
|
|
2023-07-25 10:40:26 -04:00
|
|
|
return (
|
2024-07-28 21:59:06 -04:00
|
|
|
<>
|
|
|
|
<h1 className="flex flex-wrap items-center gap-4 text-3xl font-bold">
|
|
|
|
Would you like to create a new project?
|
|
|
|
</h1>
|
|
|
|
<section className="my-12">
|
|
|
|
<p className="my-4">
|
|
|
|
You have some content in this project that we don't want to overwrite.
|
|
|
|
If you would like to create a new project, please click the button
|
|
|
|
below.
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
<OnboardingButtons
|
|
|
|
className="mt-6"
|
2025-02-07 11:30:36 -05:00
|
|
|
onNextOverride={() => {
|
|
|
|
onAccept().catch(reportRejection)
|
|
|
|
}}
|
2024-07-28 21:59:06 -04:00
|
|
|
/>
|
|
|
|
</>
|
2023-09-15 22:37:40 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:59:06 -04:00
|
|
|
function OnboardingWarningWeb(props: OnboardingResetWarningProps) {
|
2025-02-07 11:30:36 -05:00
|
|
|
useEffect(() => {
|
|
|
|
async function beforeNavigate() {
|
|
|
|
// We do want to update both the state and editor here.
|
|
|
|
codeManager.updateCodeStateEditor(bracket)
|
|
|
|
await codeManager.writeToFile()
|
2024-07-28 21:59:06 -04:00
|
|
|
|
2025-02-07 11:30:36 -05:00
|
|
|
await kclManager.executeCode(true)
|
|
|
|
props.setShouldShowWarning(false)
|
|
|
|
}
|
|
|
|
return () => {
|
|
|
|
beforeNavigate().catch(reportRejection)
|
|
|
|
}
|
|
|
|
}, [])
|
2024-07-28 21:59:06 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1 className="text-3xl font-bold text-warn-80 dark:text-warn-10">
|
|
|
|
Replaying onboarding resets your code
|
|
|
|
</h1>
|
|
|
|
<p className="my-4">
|
|
|
|
We see you have some of your own code written in this project. Please
|
|
|
|
save it somewhere else before continuing the onboarding.
|
|
|
|
</p>
|
2025-02-07 11:30:36 -05:00
|
|
|
<OnboardingButtons className="mt-6" />
|
2024-07-28 21:59:06 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnboardingIntroductionInner() {
|
|
|
|
// Reset the code to the bracket code
|
|
|
|
useDemoCode()
|
|
|
|
|
2023-09-15 22:37:40 -04:00
|
|
|
const {
|
2025-02-21 13:47:36 -05:00
|
|
|
app: { theme },
|
|
|
|
} = useSettings()
|
2023-09-18 16:13:04 -04:00
|
|
|
const getLogoTheme = () =>
|
2024-04-02 10:29:34 -04:00
|
|
|
theme.current === Themes.Light ||
|
|
|
|
(theme.current === Themes.System && getSystemTheme() === Themes.Light)
|
2023-09-18 16:13:04 -04:00
|
|
|
? '-dark'
|
|
|
|
: ''
|
2023-09-15 22:37:40 -04:00
|
|
|
|
2024-07-28 21:59:06 -04:00
|
|
|
return (
|
2023-10-17 12:31:14 -04:00
|
|
|
<div className="fixed inset-0 z-50 grid place-content-center bg-chalkboard-110/50">
|
2025-02-07 11:30:36 -05:00
|
|
|
<div className="relative max-w-3xl p-8 rounded bg-chalkboard-10 dark:bg-chalkboard-90">
|
2024-03-08 17:59:14 -05:00
|
|
|
<h1 className="flex flex-wrap items-center gap-4 text-3xl font-bold">
|
2023-09-15 22:37:40 -04:00
|
|
|
<img
|
2024-08-20 22:16:44 -04:00
|
|
|
src={`${isDesktop() ? '.' : ''}/zma-logomark${getLogoTheme()}.svg`}
|
2023-12-18 06:15:26 -05:00
|
|
|
alt={APP_NAME}
|
2023-10-17 12:31:14 -04:00
|
|
|
className="h-20 max-w-full"
|
2023-09-15 22:37:40 -04:00
|
|
|
/>
|
2024-04-05 00:59:02 -04:00
|
|
|
<span className="px-3 py-1 text-base rounded-full bg-primary/10 text-primary">
|
2023-09-15 22:37:40 -04:00
|
|
|
Alpha
|
|
|
|
</span>
|
2023-07-25 10:40:26 -04:00
|
|
|
</h1>
|
2023-09-15 22:37:40 -04:00
|
|
|
<section className="my-12">
|
|
|
|
<p className="my-4">
|
2023-12-18 06:15:26 -05:00
|
|
|
Welcome to {APP_NAME}! This is a hardware design tool that lets you
|
2024-03-29 12:56:32 -04:00
|
|
|
edit visually, with code, or both. It's powered by the KittyCAD
|
|
|
|
Design API, the first API created for anyone to build hardware
|
|
|
|
design tools. The 3D view is not running on your computer, but is
|
|
|
|
instead being streamed to you from an instance of our Geometry
|
|
|
|
Engine on a remote GPU as video.
|
2023-09-15 22:37:40 -04:00
|
|
|
</p>
|
|
|
|
<p className="my-4">
|
|
|
|
This is an alpha release, so you will encounter bugs and missing
|
|
|
|
features. You can read our{' '}
|
|
|
|
<a
|
|
|
|
href="https://gist.github.com/jgomez720/5cd53fb7e8e54079f6dc0d2625de5393"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
|
|
|
>
|
|
|
|
expectations for alpha users here
|
|
|
|
</a>
|
2024-03-08 17:59:14 -05:00
|
|
|
, and please give us feedback on your experience{' '}
|
|
|
|
<a
|
|
|
|
href="https://discord.com/invite/JQEpHR7Nt2"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
|
|
|
>
|
|
|
|
our Discord
|
|
|
|
</a>
|
|
|
|
! We are trying to release as early as possible to get feedback from
|
|
|
|
users like you.
|
2023-09-15 22:37:40 -04:00
|
|
|
</p>
|
2024-06-20 21:39:01 -04:00
|
|
|
<p>
|
|
|
|
As you go through the onboarding, we'll be changing and resetting
|
|
|
|
your code occasionally, so that we can reference specific code
|
|
|
|
features. So hold off on writing production KCL code until you're
|
|
|
|
done with the onboarding 😉
|
|
|
|
</p>
|
2023-09-15 22:37:40 -04:00
|
|
|
</section>
|
2023-12-06 14:44:13 -05:00
|
|
|
<OnboardingButtons
|
2024-03-08 17:59:14 -05:00
|
|
|
currentSlug={onboardingPaths.INDEX}
|
2023-12-06 14:44:13 -05:00
|
|
|
className="mt-6"
|
|
|
|
/>
|
2023-07-25 10:40:26 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|