Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Nov 4, 2024
1 parent 89ab272 commit 88c8ef7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/desktop-client/src/components/ScrollProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ type ScrollListenerArgs = {
hasScrolledToEnd: (direction: ScrollDirection, tolerance?: number) => boolean;
};

type ScrollListener = (values: ScrollListenerArgs) => void;
type ScrollListener = (args: ScrollListenerArgs) => void;
type UnregisterScrollListener = () => void;
type RegisterScrollListener = (listener: ScrollListener) => UnregisterScrollListener;

Check warning on line 24 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `listener:·ScrollListener` with `⏎··listener:·ScrollListener,⏎`

type IScrollContext = {
registerListener: (listener: ScrollListener) => void;
unregisterListener: (listener: ScrollListener) => void;
registerScrollListener: RegisterScrollListener;
};

const ScrollContext = createContext<IScrollContext | undefined>(undefined);

type ScrollProviderProps<T extends Element> = {
scrollableRef: RefObject<T>;
isDisabled: boolean;
isDisabled?: boolean;
children?: ReactNode;
};

Expand Down Expand Up @@ -175,16 +176,16 @@ export function ScrollProvider<T extends Element>({
});
}, [hasScrolledToEnd, isDisabled, isScrolling, scrollableRef]);

const registerListener = useCallback((listener: ScrollListener) => {
const registerScrollListener: RegisterScrollListener = useCallback(listener => {

Check warning on line 179 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎····`
listeners.current.push(listener);

Check warning on line 180 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `······`
}, []);

const unregisterListener = useCallback((listener: ScrollListener) => {
listeners.current = listeners.current.filter(l => l !== listener);
return () => {

Check warning on line 182 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
listeners.current = listeners.current.filter(l => l !== listener);

Check warning on line 183 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
};

Check warning on line 184 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `······`
}, []);

Check warning on line 185 in packages/desktop-client/src/components/ScrollProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `··},·[]` with `····},⏎····[],⏎··`

return (
<ScrollContext.Provider value={{ registerListener, unregisterListener }}>
<ScrollContext.Provider value={{ registerScrollListener }}>
{children}
</ScrollContext.Provider>
);
Expand All @@ -196,11 +197,9 @@ export function useScrollListener(listener: ScrollListener) {
throw new Error('useScrollListener must be used within a ScrollProvider');
}

const { registerListener, unregisterListener } = context;
const { registerScrollListener } = context;

useEffect(() => {
const _listener = listener;
registerListener(_listener);
return () => unregisterListener(_listener);
}, [listener, registerListener, unregisterListener]);
return registerScrollListener(listener);
}, [listener, registerScrollListener]);
}

0 comments on commit 88c8ef7

Please sign in to comment.