Make "Replay Onboarding" button available on home settings page (#804)
* Fix unrelated bug, settings button in the home sidebar doesn't go to the home settings after my previous fixes to routes * Turn on "Replay Onboarding" button in home settings * Use ONBOARDING_PROJECT_NAME in both places * Fix formatting
This commit is contained in:
@ -7,7 +7,7 @@ import {
|
|||||||
faSignOutAlt,
|
faSignOutAlt,
|
||||||
} from '@fortawesome/free-solid-svg-icons'
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faGithub } from '@fortawesome/free-brands-svg-icons'
|
import { faGithub } from '@fortawesome/free-brands-svg-icons'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useLocation, useNavigate } from 'react-router-dom'
|
||||||
import { Fragment, useState } from 'react'
|
import { Fragment, useState } from 'react'
|
||||||
import { paths } from '../Router'
|
import { paths } from '../Router'
|
||||||
import { Models } from '@kittycad/lib'
|
import { Models } from '@kittycad/lib'
|
||||||
@ -17,6 +17,7 @@ import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
|
|||||||
type User = Models['User_type']
|
type User = Models['User_type']
|
||||||
|
|
||||||
const UserSidebarMenu = ({ user }: { user?: User }) => {
|
const UserSidebarMenu = ({ user }: { user?: User }) => {
|
||||||
|
const location = useLocation()
|
||||||
const filePath = useAbsoluteFilePath()
|
const filePath = useAbsoluteFilePath()
|
||||||
const displayedName = getDisplayName(user)
|
const displayedName = getDisplayName(user)
|
||||||
const [imageLoadFailed, setImageLoadFailed] = useState(false)
|
const [imageLoadFailed, setImageLoadFailed] = useState(false)
|
||||||
@ -132,7 +133,10 @@ const UserSidebarMenu = ({ user }: { user?: User }) => {
|
|||||||
// since /settings is a nested route the sidebar doesn't close
|
// since /settings is a nested route the sidebar doesn't close
|
||||||
// automatically when navigating to it
|
// automatically when navigating to it
|
||||||
close()
|
close()
|
||||||
navigate(filePath + paths.SETTINGS)
|
const targetPath = location.pathname.includes(paths.FILE)
|
||||||
|
? filePath + paths.SETTINGS
|
||||||
|
: paths.HOME + paths.SETTINGS
|
||||||
|
navigate(targetPath)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Settings
|
Settings
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
import { faArrowRight, faXmark } from '@fortawesome/free-solid-svg-icons'
|
import { faArrowRight, faXmark } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { ActionButton } from '../../components/ActionButton'
|
import { ActionButton } from '../../components/ActionButton'
|
||||||
import { onboardingPaths, useDismiss, useNextClick } from '.'
|
import {
|
||||||
|
ONBOARDING_PROJECT_NAME,
|
||||||
|
onboardingPaths,
|
||||||
|
useDismiss,
|
||||||
|
useNextClick,
|
||||||
|
} from '.'
|
||||||
import { useGlobalStateContext } from 'hooks/useGlobalStateContext'
|
import { useGlobalStateContext } from 'hooks/useGlobalStateContext'
|
||||||
import { Themes, getSystemTheme } from 'lib/theme'
|
import { Themes, getSystemTheme } from 'lib/theme'
|
||||||
import { bracket } from 'lib/exampleKcl'
|
import { bracket } from 'lib/exampleKcl'
|
||||||
@ -25,14 +30,20 @@ function OnboardingWithNewFile() {
|
|||||||
}))
|
}))
|
||||||
const {
|
const {
|
||||||
settings: {
|
settings: {
|
||||||
context: { defaultDirectory, defaultProjectName },
|
context: { defaultDirectory },
|
||||||
},
|
},
|
||||||
} = useGlobalStateContext()
|
} = useGlobalStateContext()
|
||||||
|
|
||||||
async function createAndOpenNewProject() {
|
async function createAndOpenNewProject() {
|
||||||
const projects = await getProjectsInDir(defaultDirectory)
|
const projects = await getProjectsInDir(defaultDirectory)
|
||||||
const nextIndex = await getNextProjectIndex(defaultProjectName, projects)
|
const nextIndex = await getNextProjectIndex(
|
||||||
const name = interpolateProjectNameWithIndex(defaultProjectName, nextIndex)
|
ONBOARDING_PROJECT_NAME,
|
||||||
|
projects
|
||||||
|
)
|
||||||
|
const name = interpolateProjectNameWithIndex(
|
||||||
|
ONBOARDING_PROJECT_NAME,
|
||||||
|
nextIndex
|
||||||
|
)
|
||||||
const newFile = await createNewProject(defaultDirectory + '/' + name)
|
const newFile = await createNewProject(defaultDirectory + '/' + name)
|
||||||
navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`)
|
navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ import FutureWork from './FutureWork'
|
|||||||
import { paths } from 'Router'
|
import { paths } from 'Router'
|
||||||
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
|
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
|
||||||
|
|
||||||
|
export const ONBOARDING_PROJECT_NAME = 'Tutorial Project $nn'
|
||||||
|
|
||||||
export const onboardingPaths = {
|
export const onboardingPaths = {
|
||||||
INDEX: '/',
|
INDEX: '/',
|
||||||
CAMERA: '/camera',
|
CAMERA: '/camera',
|
||||||
|
@ -24,11 +24,19 @@ import {
|
|||||||
} from 'lib/cameraControls'
|
} from 'lib/cameraControls'
|
||||||
import { UnitSystem } from 'machines/settingsMachine'
|
import { UnitSystem } from 'machines/settingsMachine'
|
||||||
import { useDotDotSlash } from 'hooks/useDotDotSlash'
|
import { useDotDotSlash } from 'hooks/useDotDotSlash'
|
||||||
|
import {
|
||||||
|
createNewProject,
|
||||||
|
getNextProjectIndex,
|
||||||
|
getProjectsInDir,
|
||||||
|
interpolateProjectNameWithIndex,
|
||||||
|
} from 'lib/tauriFS'
|
||||||
|
import { ONBOARDING_PROJECT_NAME } from './Onboarding'
|
||||||
|
|
||||||
export const Settings = () => {
|
export const Settings = () => {
|
||||||
const loaderData = useRouteLoaderData(paths.FILE) as IndexLoaderData
|
const loaderData = useRouteLoaderData(paths.FILE) as IndexLoaderData
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
const isFileSettings = location.pathname.includes(paths.FILE)
|
||||||
const dotDotSlash = useDotDotSlash()
|
const dotDotSlash = useDotDotSlash()
|
||||||
useHotkeys('esc', () => navigate(dotDotSlash()))
|
useHotkeys('esc', () => navigate(dotDotSlash()))
|
||||||
const {
|
const {
|
||||||
@ -63,6 +71,33 @@ export const Settings = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function restartOnboarding() {
|
||||||
|
send({
|
||||||
|
type: 'Set Onboarding Status',
|
||||||
|
data: { onboardingStatus: '' },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isFileSettings) {
|
||||||
|
navigate(dotDotSlash(1) + paths.ONBOARDING.INDEX)
|
||||||
|
} else {
|
||||||
|
createAndOpenNewProject()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createAndOpenNewProject() {
|
||||||
|
const projects = await getProjectsInDir(defaultDirectory)
|
||||||
|
const nextIndex = await getNextProjectIndex(
|
||||||
|
ONBOARDING_PROJECT_NAME,
|
||||||
|
projects
|
||||||
|
)
|
||||||
|
const name = interpolateProjectNameWithIndex(
|
||||||
|
ONBOARDING_PROJECT_NAME,
|
||||||
|
nextIndex
|
||||||
|
)
|
||||||
|
const newFile = await createNewProject(defaultDirectory + '/' + name)
|
||||||
|
navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-40 overflow-auto body-bg">
|
<div className="fixed inset-0 z-40 overflow-auto body-bg">
|
||||||
<AppHeader showToolbar={false} project={loaderData?.project}>
|
<AppHeader showToolbar={false} project={loaderData?.project}>
|
||||||
@ -257,26 +292,18 @@ export const Settings = () => {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
{location.pathname.includes(paths.FILE) && (
|
|
||||||
<SettingsSection
|
<SettingsSection
|
||||||
title="Onboarding"
|
title="Onboarding"
|
||||||
description="Replay the onboarding process"
|
description="Replay the onboarding process"
|
||||||
>
|
>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
Element="button"
|
Element="button"
|
||||||
onClick={() => {
|
onClick={restartOnboarding}
|
||||||
send({
|
|
||||||
type: 'Set Onboarding Status',
|
|
||||||
data: { onboardingStatus: '' },
|
|
||||||
})
|
|
||||||
navigate(dotDotSlash(1) + paths.ONBOARDING.INDEX)
|
|
||||||
}}
|
|
||||||
icon={{ icon: faArrowRotateBack }}
|
icon={{ icon: faArrowRotateBack }}
|
||||||
>
|
>
|
||||||
Replay Onboarding
|
Replay Onboarding
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user