Files
outline/app/hooks/usePinnedDocuments.ts
T
Tom MoorandGitHub 08a3b64295 chore: Exhaustive deps warning -> error (#13124)
* chore: Exhaustive deps turned to error

* Refactor useDragResize

* Refactor Lightbox to explicit state machine

* feedback

* ci
2026-07-25 10:43:49 -04:00

39 lines
957 B
TypeScript

import { useCallback, useEffect } from "react";
import usePersistedState from "~/hooks/usePersistedState";
import useStores from "./useStores";
type UrlId = string;
export const pinsCacheKey = (urlId: UrlId) => `pins-${urlId}`;
export function usePinnedDocuments(urlId: UrlId, collectionId?: string) {
const { pins } = useStores();
const [pinsCacheCount, setPinsCacheCount] = usePersistedState<number>(
pinsCacheKey(urlId),
0
);
const getPins = useCallback(
() =>
urlId === "home"
? pins.home
: collectionId
? pins.inCollection(collectionId)
: [],
[urlId, collectionId, pins]
);
useEffect(() => {
void pins
.fetchPage(urlId === "home" ? undefined : { collectionId })
.then(() => {
setPinsCacheCount(getPins().length);
});
}, [urlId, collectionId, pins, getPins, setPinsCacheCount]);
return {
count: pinsCacheCount,
pins: getPins(),
};
}