-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: split entry history api and accurate count
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
8 changed files
with
118 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/renderer/src/providers/app-grid-layout-container-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { throttle } from "lodash-es" | ||
import type { FC, PropsWithChildren } from "react" | ||
import { createContext, useContext, useLayoutEffect, useRef, useState } from "react" | ||
|
||
|
||
const AppLayoutGridContainerWidthContext = createContext<number>(0) | ||
|
||
export const AppLayoutGridContainerProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const [width, setWidth] = useState(0) | ||
const ref = useRef<HTMLDivElement>(null) | ||
useLayoutEffect(() => { | ||
const $first = ref.current?.firstElementChild | ||
if (!$first) return | ||
const handler = throttle(() => { | ||
if (!$first) return | ||
|
||
const { width } = $first.getBoundingClientRect() | ||
setWidth(width) | ||
}, 100) | ||
|
||
handler() | ||
|
||
const resizeObserver = new ResizeObserver(handler) | ||
resizeObserver.observe($first) | ||
return () => { | ||
resizeObserver.disconnect() | ||
} | ||
}, []) | ||
|
||
return ( | ||
<AppLayoutGridContainerWidthContext.Provider value={width}> | ||
<div ref={ref} className="contents"> | ||
{children} | ||
</div> | ||
</AppLayoutGridContainerWidthContext.Provider> | ||
) | ||
} | ||
|
||
export const useAppLayoutGridContainerWidth = () => { | ||
const width = useContext(AppLayoutGridContainerWidthContext) | ||
return width | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters