mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 23:27:09 +00:00
* 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
22 lines
641 B
TypeScript
22 lines
641 B
TypeScript
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]
|
|
}
|