|
@@ -2,7 +2,6 @@ import { h } from 'preact'
|
|
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
|
|
|
|
|
|
import type { Uppy } from '@uppy/core'
|
|
|
-import useStore from '@uppy/core/lib/useStore.js'
|
|
|
import type { AsyncStore } from '@uppy/core/lib/Uppy.js'
|
|
|
|
|
|
import {
|
|
@@ -19,6 +18,31 @@ import {
|
|
|
import AuthView from '../ProviderView/AuthView.js'
|
|
|
import { GoogleDriveIcon, GooglePhotosIcon } from './icons.js'
|
|
|
|
|
|
+function useStore(
|
|
|
+ store: AsyncStore,
|
|
|
+ key: string,
|
|
|
+): [string | undefined | null, (v: string | null) => Promise<void>] {
|
|
|
+ const [value, setValueState] = useState<string | null | undefined>()
|
|
|
+ useEffect(() => {
|
|
|
+ ;(async () => {
|
|
|
+ setValueState(await store.getItem(key))
|
|
|
+ })()
|
|
|
+ }, [key, store])
|
|
|
+
|
|
|
+ const setValue = useCallback(
|
|
|
+ async (v: string | null) => {
|
|
|
+ setValueState(v)
|
|
|
+ if (v == null) {
|
|
|
+ return store.removeItem(key)
|
|
|
+ }
|
|
|
+ return store.setItem(key, v)
|
|
|
+ },
|
|
|
+ [key, store],
|
|
|
+ )
|
|
|
+
|
|
|
+ return [value, setValue]
|
|
|
+}
|
|
|
+
|
|
|
export type GooglePickerViewProps = {
|
|
|
uppy: Uppy<any, any>
|
|
|
clientId: string
|