mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 22:55:51 -05:00
d8c4399c01
GitOrigin-RevId: 728979b11918c9bc1e535024040d90053536251d
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { Dispatch, SetStateAction, useCallback, useState } from 'react'
|
|
import { LoadedUpdate, Version } from '../services/types/update'
|
|
|
|
type DropdownItem = LoadedUpdate | Version
|
|
type WhichDropDownType = 'moreOptions' | 'compare' | null
|
|
|
|
export type ActiveDropdownValue = {
|
|
item: DropdownItem | null
|
|
isOpened: boolean
|
|
whichDropDown: WhichDropDownType
|
|
}
|
|
|
|
export type ActiveDropdown = {
|
|
activeDropdownItem: ActiveDropdownValue
|
|
setActiveDropdownItem: Dispatch<SetStateAction<ActiveDropdownValue>>
|
|
closeDropdownForItem: (
|
|
item: DropdownItem,
|
|
whichDropDown: WhichDropDownType
|
|
) => void
|
|
}
|
|
|
|
function useDropdownActiveItem(): ActiveDropdown {
|
|
const [activeDropdownItem, setActiveDropdownItem] =
|
|
useState<ActiveDropdownValue>({
|
|
item: null,
|
|
isOpened: false,
|
|
whichDropDown: null,
|
|
})
|
|
|
|
const closeDropdownForItem = useCallback(
|
|
(item: DropdownItem, whichDropDown: WhichDropDownType) =>
|
|
setActiveDropdownItem({ item, isOpened: false, whichDropDown }),
|
|
[setActiveDropdownItem]
|
|
)
|
|
|
|
return {
|
|
activeDropdownItem,
|
|
setActiveDropdownItem,
|
|
closeDropdownForItem,
|
|
}
|
|
}
|
|
|
|
export default useDropdownActiveItem
|