mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { useCallback, useState } from 'react'
|
|
import { useStorageBackend } from './use-unified-storage'
|
|
import { useStorageSwitchHandlers } from './useStorageSwitchHandlers'
|
|
import { useStorageDataHandlers } from './useStorageDataHandlers'
|
|
|
|
type StorageSettingsHandlersOptions = {
|
|
defaultFlaskUrl: string
|
|
exportFilename: () => string
|
|
importAccept: string
|
|
}
|
|
|
|
const flaskUrlStorageKey = 'codeforge-flask-url'
|
|
|
|
export const useStorageSettingsHandlers = ({
|
|
defaultFlaskUrl,
|
|
exportFilename,
|
|
importAccept,
|
|
}: StorageSettingsHandlersOptions) => {
|
|
const {
|
|
backend,
|
|
isLoading,
|
|
switchToFlask,
|
|
switchToSQLite,
|
|
switchToIndexedDB,
|
|
exportData,
|
|
importData,
|
|
} = useStorageBackend()
|
|
|
|
const [flaskUrl, setFlaskUrlState] = useState(
|
|
() => localStorage.getItem(flaskUrlStorageKey) || defaultFlaskUrl
|
|
)
|
|
|
|
const setFlaskUrl = useCallback((value: string) => {
|
|
setFlaskUrlState(value)
|
|
localStorage.setItem(flaskUrlStorageKey, value)
|
|
}, [])
|
|
|
|
const { isSwitching, handleSwitchToFlask, handleSwitchToSQLite, handleSwitchToIndexedDB } =
|
|
useStorageSwitchHandlers({
|
|
backend,
|
|
flaskUrl,
|
|
switchToFlask,
|
|
switchToSQLite,
|
|
switchToIndexedDB,
|
|
})
|
|
|
|
const { isExporting, isImporting, handleExport, handleImport } = useStorageDataHandlers({
|
|
exportData,
|
|
importData,
|
|
exportFilename,
|
|
importAccept,
|
|
})
|
|
|
|
return {
|
|
backend,
|
|
isLoading,
|
|
flaskUrl,
|
|
setFlaskUrl,
|
|
isSwitching,
|
|
handleSwitchToFlask,
|
|
handleSwitchToSQLite,
|
|
handleSwitchToIndexedDB,
|
|
isExporting,
|
|
isImporting,
|
|
handleExport,
|
|
handleImport,
|
|
}
|
|
}
|