mirror of
https://github.com/Novattz/creamlinux-installer.git
synced 2026-05-02 13:02:04 -04:00
disclaimer hook #87
This commit is contained in:
@@ -5,6 +5,7 @@ export { useGameActions } from './useGameActions'
|
|||||||
export { useToasts } from './useToasts'
|
export { useToasts } from './useToasts'
|
||||||
export { useAppLogic } from './useAppLogic'
|
export { useAppLogic } from './useAppLogic'
|
||||||
export { useConflictDetection } from './useConflictDetection'
|
export { useConflictDetection } from './useConflictDetection'
|
||||||
|
export { useDisclaimer } from './useDisclaimer'
|
||||||
|
|
||||||
// Export types
|
// Export types
|
||||||
export type { ToastType, Toast, ToastOptions } from './useToasts'
|
export type { ToastType, Toast, ToastOptions } from './useToasts'
|
||||||
|
|||||||
58
src/hooks/useDisclaimer.ts
Normal file
58
src/hooks/useDisclaimer.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
import { Config } from '@/types/Config'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook to manage disclaimer dialog state
|
||||||
|
* Loads config on mount and provides methods to update it
|
||||||
|
*/
|
||||||
|
export function useDisclaimer() {
|
||||||
|
const [showDisclaimer, setShowDisclaimer] = useState(false)
|
||||||
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
|
||||||
|
// Load config on mount
|
||||||
|
useEffect(() => {
|
||||||
|
loadConfig()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const loadConfig = async () => {
|
||||||
|
try {
|
||||||
|
const config = await invoke<Config>('load_config')
|
||||||
|
setShowDisclaimer(config.show_disclaimer)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load config:', error)
|
||||||
|
// Default to showing disclaimer if config load fails
|
||||||
|
setShowDisclaimer(true)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDisclaimerClose = async (dontShowAgain: boolean) => {
|
||||||
|
setShowDisclaimer(false)
|
||||||
|
|
||||||
|
if (dontShowAgain) {
|
||||||
|
try {
|
||||||
|
// Load the current config first
|
||||||
|
const currentConfig = await invoke<Config>('load_config')
|
||||||
|
|
||||||
|
// Update the show_disclaimer field
|
||||||
|
const updatedConfig: Config = {
|
||||||
|
...currentConfig,
|
||||||
|
show_disclaimer: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the updated config
|
||||||
|
await invoke('update_config', { configData: updatedConfig })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to update config:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
showDisclaimer,
|
||||||
|
isLoading,
|
||||||
|
handleDisclaimerClose,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user