2024-06-04 13:56:20 -04:00
|
|
|
import { SettingsLevel } from 'lib/settings/settingsTypes'
|
2024-04-30 14:37:32 -04:00
|
|
|
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
|
2023-08-08 12:39:11 -04:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook'
|
2024-02-11 12:59:00 +11:00
|
|
|
import { paths } from 'lib/paths'
|
2023-09-18 23:55:14 -04:00
|
|
|
import { useDotDotSlash } from 'hooks/useDotDotSlash'
|
2024-04-30 14:37:32 -04:00
|
|
|
import { Fragment, useEffect, useRef } from 'react'
|
|
|
|
|
import { Dialog, Transition } from '@headlessui/react'
|
|
|
|
|
import { CustomIcon } from 'components/CustomIcon'
|
|
|
|
|
import { SettingsSearchBar } from 'components/Settings/SettingsSearchBar'
|
|
|
|
|
import { SettingsTabs } from 'components/Settings/SettingsTabs'
|
2024-06-04 13:56:20 -04:00
|
|
|
import { SettingsSectionsList } from 'components/Settings/SettingsSectionsList'
|
|
|
|
|
import { AllSettingsFields } from 'components/Settings/AllSettingsFields'
|
|
|
|
|
import { AllKeybindingsFields } from 'components/Settings/AllKeybindingsFields'
|
|
|
|
|
import { KeybindingsSectionsList } from 'components/Settings/KeybindingsSectionsList'
|
2024-07-03 15:24:17 -07:00
|
|
|
import { isTauri } from 'lib/isTauri'
|
2023-07-13 07:22:08 -04:00
|
|
|
|
2024-07-03 15:24:17 -07:00
|
|
|
export const APP_VERSION = isTauri()
|
|
|
|
|
? import.meta.env.PACKAGE_VERSION || 'unknown'
|
|
|
|
|
: 'main'
|
2024-04-09 18:05:36 -07:00
|
|
|
|
2023-07-13 07:22:08 -04:00
|
|
|
export const Settings = () => {
|
2023-07-25 10:40:26 -04:00
|
|
|
const navigate = useNavigate()
|
2024-04-30 14:37:32 -04:00
|
|
|
const [searchParams, setSearchParams] = useSearchParams()
|
2024-04-02 10:29:34 -04:00
|
|
|
const close = () => navigate(location.pathname.replace(paths.SETTINGS, ''))
|
2023-08-31 08:27:05 -04:00
|
|
|
const location = useLocation()
|
2023-10-06 10:00:35 -04:00
|
|
|
const isFileSettings = location.pathname.includes(paths.FILE)
|
2024-04-30 14:37:32 -04:00
|
|
|
const searchParamTab =
|
2024-06-04 13:56:20 -04:00
|
|
|
(searchParams.get('tab') as SettingsLevel | 'keybindings') ??
|
2024-04-30 14:37:32 -04:00
|
|
|
(isFileSettings ? 'project' : 'user')
|
|
|
|
|
|
2024-04-02 10:29:34 -04:00
|
|
|
const scrollRef = useRef<HTMLDivElement>(null)
|
2023-09-18 23:55:14 -04:00
|
|
|
const dotDotSlash = useDotDotSlash()
|
|
|
|
|
useHotkeys('esc', () => navigate(dotDotSlash()))
|
2023-10-06 10:00:35 -04:00
|
|
|
|
2024-04-30 14:37:32 -04:00
|
|
|
// Scroll to the hash on load if it exists
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log('hash', location.hash)
|
|
|
|
|
if (location.hash) {
|
|
|
|
|
const element = document.getElementById(location.hash.slice(1))
|
|
|
|
|
if (element) {
|
|
|
|
|
element.scrollIntoView({ block: 'center', behavior: 'smooth' })
|
|
|
|
|
;(
|
|
|
|
|
element.querySelector('input, select, textarea') as HTMLInputElement
|
|
|
|
|
)?.focus()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [location.hash])
|
|
|
|
|
|
2023-07-13 07:22:08 -04:00
|
|
|
return (
|
2024-04-02 10:29:34 -04:00
|
|
|
<Transition appear show={true} as={Fragment}>
|
|
|
|
|
<Dialog
|
|
|
|
|
as="div"
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={close}
|
|
|
|
|
className="fixed inset-0 z-40 overflow-y-auto p-4 grid place-items-center"
|
|
|
|
|
>
|
|
|
|
|
<Transition.Child
|
|
|
|
|
as={Fragment}
|
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
|
enterTo="opacity-100"
|
|
|
|
|
leave="ease-in duration-75"
|
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
|
leaveTo="opacity-0"
|
2023-07-21 12:48:23 -04:00
|
|
|
>
|
2024-04-02 10:29:34 -04:00
|
|
|
<Dialog.Overlay className="fixed inset-0 bg-chalkboard-110/30 dark:bg-chalkboard-110/50" />
|
|
|
|
|
</Transition.Child>
|
|
|
|
|
|
|
|
|
|
<Transition.Child
|
|
|
|
|
as={Fragment}
|
|
|
|
|
enter="ease-out duration-75"
|
|
|
|
|
enterFrom="opacity-0 scale-95"
|
|
|
|
|
enterTo="opacity-100 scale-100"
|
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
|
leaveFrom="opacity-100 scale-100"
|
|
|
|
|
leaveTo="opacity-0 scale-95"
|
2023-10-06 10:00:35 -04:00
|
|
|
>
|
2024-04-15 12:04:17 -04:00
|
|
|
<Dialog.Panel className="rounded relative mx-auto bg-chalkboard-10 dark:bg-chalkboard-100 border dark:border-chalkboard-70 max-w-3xl w-full max-h-[66vh] shadow-lg flex flex-col gap-8">
|
2024-04-02 10:29:34 -04:00
|
|
|
<div className="p-5 pb-0 flex justify-between items-center">
|
|
|
|
|
<h1 className="text-2xl font-bold">Settings</h1>
|
2024-04-30 14:37:32 -04:00
|
|
|
<div className="flex gap-4 items-start">
|
|
|
|
|
<SettingsSearchBar />
|
|
|
|
|
<button
|
|
|
|
|
onClick={close}
|
|
|
|
|
className="p-0 m-0 focus:ring-0 focus:outline-none border-none hover:bg-destroy-10 focus:bg-destroy-10 dark:hover:bg-destroy-80/50 dark:focus:bg-destroy-80/50"
|
|
|
|
|
data-testid="settings-close-button"
|
|
|
|
|
>
|
|
|
|
|
<CustomIcon name="close" className="w-5 h-5" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-04-02 10:29:34 -04:00
|
|
|
</div>
|
2024-04-30 14:37:32 -04:00
|
|
|
<SettingsTabs
|
|
|
|
|
value={searchParamTab}
|
|
|
|
|
onChange={(v) => setSearchParams((p) => ({ ...p, tab: v }))}
|
|
|
|
|
showProjectTab={isFileSettings}
|
|
|
|
|
/>
|
2024-04-15 12:04:17 -04:00
|
|
|
<div
|
2024-04-30 14:37:32 -04:00
|
|
|
className="flex-1 grid items-stretch pl-4 pr-5 pb-5 gap-2 overflow-hidden"
|
2024-05-13 12:43:00 -04:00
|
|
|
style={{
|
|
|
|
|
gridTemplateColumns: 'auto 1fr',
|
|
|
|
|
gridTemplateRows: '1fr',
|
|
|
|
|
}}
|
2024-04-15 12:04:17 -04:00
|
|
|
>
|
2024-06-04 13:56:20 -04:00
|
|
|
{searchParamTab !== 'keybindings' ? (
|
|
|
|
|
<>
|
|
|
|
|
<SettingsSectionsList
|
|
|
|
|
searchParamTab={searchParamTab}
|
|
|
|
|
scrollRef={scrollRef}
|
|
|
|
|
/>
|
|
|
|
|
<AllSettingsFields
|
|
|
|
|
searchParamTab={searchParamTab}
|
|
|
|
|
isFileSettings={isFileSettings}
|
|
|
|
|
ref={scrollRef}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<KeybindingsSectionsList scrollRef={scrollRef} />
|
|
|
|
|
<AllKeybindingsFields ref={scrollRef} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-04-02 10:29:34 -04:00
|
|
|
</div>
|
|
|
|
|
</Dialog.Panel>
|
|
|
|
|
</Transition.Child>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</Transition>
|
2023-07-13 07:22:08 -04:00
|
|
|
)
|
|
|
|
|
}
|