mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
23 lines
817 B
TypeScript
23 lines
817 B
TypeScript
|
import { useCallback } from 'react'
|
||
|
import { DocId } from '../../../../../types/project-settings'
|
||
|
import { useProjectContext } from '../../../shared/context/project-context'
|
||
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
||
|
|
||
|
export default function useOverviewFileCollapsed(docId: DocId) {
|
||
|
const { _id: projectId } = useProjectContext()
|
||
|
const [collapsedDocs, setCollapsedDocs] = usePersistedState<
|
||
|
Record<DocId, boolean>
|
||
|
>(`docs_collapsed_state:${projectId}`, {}, false, true)
|
||
|
|
||
|
const toggleCollapsed = useCallback(() => {
|
||
|
setCollapsedDocs((collapsedDocs: Record<DocId, boolean>) => {
|
||
|
return {
|
||
|
...collapsedDocs,
|
||
|
[docId]: !collapsedDocs[docId],
|
||
|
}
|
||
|
})
|
||
|
}, [docId, setCollapsedDocs])
|
||
|
|
||
|
return { collapsed: collapsedDocs[docId], toggleCollapsed }
|
||
|
}
|