mirror of
https://github.com/outline/outline.git
synced 2026-01-06 02:59:54 -06:00
36 lines
780 B
TypeScript
36 lines
780 B
TypeScript
import * as React from "react";
|
|
import usePersistedState from "~/hooks/usePersistedState";
|
|
import useStores from "./useStores";
|
|
|
|
export function usePinnedDocuments(
|
|
urlId: "home" | string,
|
|
collectionId?: string
|
|
) {
|
|
const { pins } = useStores();
|
|
const [pinsCacheCount, setPinsCacheCount] = usePersistedState<number>(
|
|
`pins-${urlId}`,
|
|
0
|
|
);
|
|
|
|
function getPins() {
|
|
return urlId === "home"
|
|
? pins.home
|
|
: collectionId
|
|
? pins.inCollection(collectionId)
|
|
: [];
|
|
}
|
|
|
|
React.useEffect(() => {
|
|
void pins
|
|
.fetchPage(urlId === "home" ? undefined : { collectionId })
|
|
.then(() => {
|
|
setPinsCacheCount(getPins().length);
|
|
});
|
|
}, [collectionId, pins]);
|
|
|
|
return {
|
|
count: pinsCacheCount,
|
|
pins: getPins(),
|
|
};
|
|
}
|