refactor: usePreference + update TS tooling (#2333)

This commit is contained in:
Aman Harwara
2023-05-11 20:04:14 +05:30
committed by GitHub
parent bcd962f150
commit 3b5bf1e509
188 changed files with 544 additions and 2028 deletions

View File

@@ -81,7 +81,7 @@ const ClipperView = ({
})
}, [application])
const defaultTagId = usePreference<string>(PrefKey.ClipperDefaultTagUuid)
const defaultTagId = usePreference(PrefKey.ClipperDefaultTagUuid)
const [defaultTag, setDefaultTag] = useState<SNTag | undefined>()
const defaultTagRef = useStateRef(defaultTag)

View File

@@ -1,8 +1,8 @@
import { ApplicationEvent, PrefKey, PrefValue } from '@standardnotes/snjs'
import { useEffect, useState } from 'react'
import { PrefKey, PrefValue } from '@standardnotes/snjs'
import { useApplication } from '../ApplicationProvider'
import Dropdown from '../Dropdown/Dropdown'
import Modal from '../Modal/Modal'
import usePreference from '@/Hooks/usePreference'
type Props = {
exportNotes: () => void
@@ -11,14 +11,7 @@ type Props = {
const SuperExportModal = ({ exportNotes, close }: Props) => {
const application = useApplication()
const [superNoteExportFormat, setSuperNoteExportFormat] = useState<PrefValue[PrefKey.SuperNoteExportFormat]>(
() => application.getPreference(PrefKey.SuperNoteExportFormat) || 'json',
)
useEffect(() => {
return application.addSingleEventObserver(ApplicationEvent.PreferencesChanged, async () => {
setSuperNoteExportFormat(application.getPreference(PrefKey.SuperNoteExportFormat) || 'json')
})
}, [application, superNoteExportFormat])
const superNoteExportFormat = usePreference(PrefKey.SuperNoteExportFormat)
return (
<Modal

View File

@@ -21,7 +21,7 @@ const Moments: FunctionComponent<Props> = ({ application }: Props) => {
const momentsEnabled = application.momentsService.isEnabled
const premiumModal = usePremiumModal()
const defaultTagId = usePreference<string>(PrefKey.MomentsDefaultTagUuid)
const defaultTagId = usePreference(PrefKey.MomentsDefaultTagUuid)
const [defaultTag, setDefaultTag] = useState<SNTag | undefined>()
useEffect(() => {