mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 15:47:08 +00:00
Projects (#192)
* Add file save UI and drafts project * Fix build * Create SearchList component as abstraction * Add project page and file tree view * Create Locale context * Create Theme context * Create Version context * Create Title context * Create Project context * Store current file in project context * Fix issues when renaming file and implement deleting * Style improvements * Make all project strings translatable * Fix z-index
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './useActiveTimout'
|
||||
export * from './useCanvas'
|
||||
export * from './useFocus'
|
||||
export * from './useModel'
|
||||
|
||||
21
src/app/hooks/useActiveTimout.ts
Normal file
21
src/app/hooks/useActiveTimout.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useRef, useState } from 'preact/hooks'
|
||||
|
||||
interface ActiveTimeoutOptions {
|
||||
cooldown?: number,
|
||||
invert?: boolean,
|
||||
initial?: boolean,
|
||||
}
|
||||
export function useActiveTimeout({ cooldown, invert, initial }: ActiveTimeoutOptions = {}): [boolean | undefined, () => unknown] {
|
||||
const [active, setActive] = useState(initial)
|
||||
const timeout = useRef<number | undefined>(undefined)
|
||||
|
||||
const trigger = () => {
|
||||
setActive(invert ? false : true)
|
||||
if (timeout.current !== undefined) clearTimeout(timeout.current)
|
||||
timeout.current = setTimeout(() => {
|
||||
setActive(invert ? true : false)
|
||||
}, cooldown ?? 2000) as any
|
||||
}
|
||||
|
||||
return [active, trigger]
|
||||
}
|
||||
Reference in New Issue
Block a user